Links on button's payload

Hello,

I use Rasa on a website, with React as front-end,

I am looking to use buttons with payload as a link to open on a new tab, so bot responds with a message and add a button after response “Click here to open the website”, I want the user to be able to click on this and get his default browser opened with the link

I can display the button but can’t put a link on it sadly

I tried to use webbrowser python library on my action file like :

import webbrowser

and

def run(self, dispatcher, tracker, domain):
    url = "https://link.com"
    webbrowser.open(url)
    return []

But it’s not working, is there a way to do this ?

Thanks

Gilles

2 Likes

Hi Gilles,

In fact to do so you have to call the link in the front-end not in rasa. For the generated button you can add this to domain.yml:

utter_link:

  • text: “Click here to open the website” buttons:

Replace the payload with your link, then configure your stories to use it.

When you get the response in the front-end it will be like this:

{“text”: “Click here to open the website”, “buttons”: [ “title”: “Click me”, “payload”: “http://website.com”]}

Display text

Display any button if exist

=> If payload first element is “/” parse it back to your bot

=> If payload contains “http://” or “https://” add to the button a function to navigate to a parameter url and pass the payload as a parameter.

Jobs done :slight_smile:

Florian

2 Likes

Perfect, thanks :slight_smile:

Could you please explain this part. Ex i want to run linkedin on button click. How to get this

In your frontend you have to access to button.payload, this will give you the content of payload variable, so you can test if payload contains http or https or not

If button.payload contains http or https
   you generate a real link <a href="yourpayloadlink">.....
else
   you default button with a rasa payload

Hi, i have a question. You said “If payload first element is “/” parse it back to your bot”. Do i need to only send the payload or the title too? And like normal text message or in some other structure ?

@gillesf @Kenz Could you please tell me that how to call the frontend? Frontend means in actions.py file?I have understood about domain.yml payload button but didn’t get the fact about the frontend.

Hi,

I have added as given below , but it is not working.

buttons:

- title: About Products

  payload: ‘http://abcd.com’

Getting response “Sorry, I didn’t understand! Questions you can ask me”.

hey, when i am attaching links ,links open in the form of google docs and then i have to redirect to main site manually ,could you please help me out in this