How to define utter_template, can show quick reply on facebook

I create template on domain:

templates:
  utter_answer: 
  - buttons:
    - title: test1
      payload: test1
    - title: test2
      payload: test2
    - title: test3
      payload: test3
    text: The answer is:

=> The result on facebook: image

(maximum 3 buttons)

So, How can I define template to show more than 3 buttons on facebook messenger?

Thanks

Facebook does not allow you to show more than three buttons on a message. Quick replies are included in the "quick_replies":[] array

Thanks Brian,

I know that. I mean how to included “quick_replies”:[] in file domain.yml?

hey @tuyendh check this thread

Getting user data in Facebook Messenger

@tuyendh. Feel your pain. Frankly I’m getting a little tired of the vague answers on this forum, and the ambiguous / unclear / outdated documentation online, including the zillions of broken links to existing documentation which 301 redirects back to the rasa homepage …

To the moderators / admins, one line answers with no material direction or valid solution just drive me up the wall, I am sure that I am not the only one.

As far as I can tell, there is a bug (See Here) with including ‘quick_replies’ array in the domain.yml file, however, the following worked for me:

class ActionYesNo(Action):
    def name(self):
        return "action_yes_no"

    def run(self, dispatcher, tracker, domain):
        if tracker.get_latest_input_channel() == 'facebook':
            message = {
                "text": "Is this correct (Yes/No)?",
                "quick_replies": [
                    {
                        "content_type": "text",
                        "title": "Yes",
                        "payload": "/affirm",
                    }, {
                        "content_type": "text",
                        "title": "No",
                        "payload": "/deny",
                    }
                ]
            }
            dispatcher.utter_custom_json(message)
        else:
            dispatcher.utter_template("utter_yes_no", tracker)
        return []

Basically it is an action that utters custom JSON (including quick replies) if the latest input channel is facebook, else, it utters a simple template which you can define in the domain.yml file.

Not sure if the quick replies work on other channels, for me its binary, either on facebook or console. The quick replies are undesired if the channel is the console (ie rest channel).

Facebook messenger screenshot below…

Console screenshot below

6 Likes

I feel your pain, I love rasa but there are a lot vague answers.

I have used your example and it worked like a charm for me. However on a bigger application, I cant see this logic working quite well. I mean I would have to perpetually use:

if tracker.get_latest_input_channel() == 'channel_name':. all time in all the functions ? I dont see it as a good pratice :confused:

Or do you know a way I could filter the channel in the beginning and redirect it to a specific part of the code that is just related to that one Channel ? Thanks

Thank you so much sir. This helped me to solve the issue. But is there any means by which we can change the replies to vertical format

Hi @amina_anvar

Facebook quick replies always go horizontal. Like the original question shows, only buttons(max. 3) go vertical.

Here you can find all buttons and menus facebook supports currently:

https://developers.facebook.com/docs/messenger-platform/send-messages/quick-replies

I have checked it. And changed to quick replies, as it goes only horizontal

I was able to get facebook messenger with quick replies, but while I tried to update it on website, I wasn’t able to get all the quick replies,but other than quick replies option, it was possible. why is that so? is it because quick replies only comes on messenger?

if tracker.get_latest_input_channel() == ‘facebook’:

Here, we have been mentioning only facebook? Is that so? CAn you please help? Is there any solution where i can catch up with the quick replies in my chatbot on website?

ANy body ever tried to use buttons and quick replies simultaneously ? ( Like 3 buttons in one meesage and 5 quick replies in the next one ). Is that possible :thinking:

Hey , yes quick replies are only for FB messenger. But no worries, you can specify channels in domain file. For eg an entry in domain file could be

 utter_tools_coronasafe:
- text: Here are few of CoronaSafe Network tools  #Making replies telegram specific for button_vertical
  channel: "telegram"
  custom:
  button_type: vertical
  buttons:
    - title: Care Platform for Hospitals
      payload: '/ask_about_care'
    - title: Logistics/Delivery Networks
      payload: '/ask_about_delivery_networks'
    - title: Contact us
      payload: 'ask_contact_us'
    - title: <- Back to main Menu
      payload: '/ask_return_main_menu'
- text: Few of CoronaSafe Network tools(Swipe Left/Right)  #Making General replies for other channels
  channel: "facebook"
  custom:
  quick_replies:
    - content_type: text
      title: Care Platform
      payload: '/ask_about_care'
    - content_type: text
      title: Logistics Networks
      payload: '/ask_about_delivery_networks'
    - content_type: text
      title: Contact us
      payload: 'ask_contact_us'
    - content_type: text
      title: <- Back to main Menu
      payload: '/ask_return_main_menu'

It is best practice to have a response without the channel : as default. This will be rendered in your website.

2 Likes

oh Thank you so much for reaching out.