Utter_button_template in custom action of actions.py

I need to display a set of buttons in custom action using utter_button_template(). These buttons will be used to fill a slot. I am facing problem in how to define the parameters for utter_button_template(), as for now my code flow doesn’t show any error but doesn’t even show the buttons in front end. Below is the code I am using : class action_CustomAction(Action): def name(self): return ‘action_’

    buttons = [{'title': 'title1', 'payload': '/intent{\"Entity_name\": "payload1"}'},{'title': 'title2', 'payload': 
                     '/intent{\"Entity_name\": "payload2"}'}]
    def run(self, dispatcher, tracker, domain):
          if tracker.get_slot('Slot_name') == 'yes':
              dispatcher.utter_button_template('utter_message', 'buttons', tracker)
          else:
              dispatcher.utter_button_template('utter_message_1', 'buttons', tracker)
          return [SlotSet("Other_slot","buttons")]

Looks like you are passing the string 'buttons' instead of your button list. Try this:

buttons = [{'title': 'title1', 'payload': '/intent{\"Entity_name\": "payload1"}'},{'title': 'title2', 'payload': 
                     '/intent{\"Entity_name\": "payload2"}'}]
    def run(self, dispatcher, tracker, domain):
          if tracker.get_slot('Slot_name') == 'yes':
              dispatcher.utter_button_template('utter_message', buttons, tracker)
          else:
              dispatcher.utter_button_template('utter_message_1', buttons, tracker)
          return [SlotSet("Other_slot","buttons")]

What are you trying to do with your slotset event? right now you’re setting a slot to the value “buttons”. It seems like you want to rather put the list there (return [SlotSet("Other_slot", buttons)]), but i’m not quite sure why you would want to do that.

1 Like