How to implement dispatcher.utter_button_template in actions.py?

How to implement dispatcher.utter_button_template() in actions.py? within domain.yml templates: utter_login_cinfirm:

  • text: “It seems that you are facing login issue.Am I correct?” buttons:
    • title: “Yes” payload: “/intent_affirm”
    • title: “No” payload: “/intent_deny”

For the above utter I want to use dispatcher.utter_button_template() . How to implement that?

use dispatcher.utter_button_template("utter_login_confirm")

1 Like

Yes I did that one. But the button is not created, only “It seems that you are facing login issue.Am I correct?” that message is displaying. I have also used dispatcher.utter_button_message(“utter_login_confirm”) that one. But using this also button is not created. Actually I want a create two buttons after displaying that message.

domain.yml utter_login_confirm: - text: “It seems that you are facing some login related issue am I correct ?” buttons: - title: “yes” payload: “/intent_affirm” - title: “No” payload: “/intent_deny”

actions.py def run(self, dispatcher, tracker, domain): dispatcher.utter_button_message(“utter_login_confirm”,buttons(“title”)) return [SlotSet(“appName”, None)]

after running that one I got this type of error : DEBUG:rasa_core.policies.memoization:Current tracker state [None, {}, {‘entity_issueType’: 1.0, ‘intent_intent_login_issue’: 1.0, ‘prev_action_listen’: 1.0}] DEBUG:rasa_core.policies.memoization:There is a memorised next action ‘33’ DEBUG:rasa_core.policies.ensemble:Predicted next action using policy_0_MemoizationPolicy DEBUG:rasa_core.policies.ensemble:Predicted next action ‘utter_login_confirm’ with prob 1.00. DEBUG:rasa_core.processor:Bot utterance ‘BotUttered(text: It seems that you are facing some login related issue am I correct ?, data: { “buttons”: [ { “title”: “yes”, “payload”: “/intent_affirm” }, { “title”: “No”, “payload”: “/intent_deny” } ] })’ DEBUG:rasa_core.processor:Action ‘utter_login_confirm’ ended with events ‘[]’ DEBUG:rasa_core.policies.memoization:Current tracker state [{}, {‘entity_issueType’: 1.0, ‘intent_intent_login_issue’: 1.0, ‘prev_action_listen’: 1.0}, {‘entity_issueType’: 1.0, ‘intent_intent_login_issue’: 1.0, ‘prev_utter_login_confirm’: 1.0}] DEBUG:rasa_core.policies.memoization:There is a memorised next action ‘4’ DEBUG:rasa_core.policies.ensemble:Predicted next action using policy_0_MemoizationPolicy DEBUG:rasa_core.policies.ensemble:Predicted next action ‘action_on_button’ with prob 1.00. ERROR:rasa_core.processor:Encountered an exception while running action ‘action_on_button’. Bot will continue, but the actions events are lost. Make sure to fix the excepti on in your custom code. ERROR:rasa_core.processor:name ‘buttons’ is not defined

Please help. I am unable to create buttons within chatbox.

you should use utter_button_template, if you want to specify the buttons in your custom action, then you can use utter_button_message

Hi akelad,

While using utter_button_message() i am getting below error. Could you please tell me how to define buttons inside custom action.

utter_button_message() missing 1 required positional argument: ‘buttons’

My mistake. ! I got the answer

what was the mistake. I am getting stuck at the same place. i am getting: TypeError: utter_button_template() missing 2 required positional arguments: ‘buttons’ and ‘tracker’

You have to define button and then call at utter_button_template. Ex below

buttons = [{ “title”: “Yes”, “payload”: “/Write_to_us” }]

Hi neerajb1. Thanks for the response. I am still not clear. I have defined buttons in the templates in the domain.yml as : utter_ask_loan:

  • text: “what kind of loan you have??” buttons:
    • title: “low” payload: “low”
    • title: “medium” payload: “medium”
    • title: “high” payload: “high”

Now I am calling it in my actions.py as: dispatcher.utter_button_template(“utter_ask_loan”) and have tried many other variations of this. Please let me know as in where to define the button and how to call in the actions.py. I get the error as two arguments missing: buttons and tracker

Hi,

buttons = [{‘title’: ‘low’, ‘payload’: ‘low’}, {‘title’: ‘med’, ‘payload’: ‘med’}, {‘title’: ‘high’, ‘payload’: ‘high’}] (Define it in your custom actions, define this)

Try using utter_button_message(“MESSAGE”, buttons, tracker)

Ideally, even your utter_button_template should work.

I want to have buttons as part of my bot, below is my domain file configuration:

intents:

  • orderStatus
  • affirm
  • sad

actions:

  • utter_ orderStatus

templates: utter_orderStatus:

  • text: “Confirm the order status” buttons:
    • title: “Passed” payload: “/intent_affirm”
    • title: “Failed” payload: “/intent_sad”

Buttons are not coming in the UI ? Plz guide me, where I’m doing wrong and what extra I need to configure

Which chat platform are you using?

If it is your custom platform, are you getting these buttons in the JSON response?

yes we are getting the response in JSON. But in this case i am not getting the buttons in my response.

Which version of RASA are you using? Also, if you run the bot on terminal are the buttons being displayed?

@Biswa did you solved the problem of not getting the buttons in the response, i am facing the similar problem, can you help me? Thanks

Important message for people who are following the above examples. Please use utter_message for everything. read the warning below.

"Use of utter_button_message is deprecated. " “Use utter_message(text=<text> , buttons=<list of buttons>) instead.”,