How to extract value of button from custom action

I am trying get the value from button which user selects from custom action.

def run(self, dispatcher, tracker, domain):
        user_vendor_name = tracker.latest_message.get('text')
        vs = VendorSimilarity()
        output = vs.get_vendor(name = user_vendor_name)
        print(output)
        buttons=[]
        for key in output["matched_vendor_name"]:
            buttons.append({"payload": "/user_vendor_name", "title": key})
        buttons.append({"payload": "/deny", "title": "I would like to add a new vendor"})
        dispatcher.utter_message(text="Please select a vendor:\n",buttons=buttons)
        user_vendor_name = tracker.get_slot('user_vendor_name')
        print(user_vendor_name)
        return []

Above is the custom action code. User will make a selection using buttons and I want to save that value in a slot to use it again in future.

You can set an entity in the payload along with the intent, that will save it to a slot.

For example:

buttons.append({'title': key,  'payload': '/user_vendor_name{"vendor": "' + key + '"}'})
1 Like

Let me try this. Would it work if my title and slot values are dynamic?

Oops sorry, didn’t pay attention to the dynamic values! I edited my code above :slight_smile:

key = 'test'
button = {'title': key,  'payload': '/user_vendor_name{"vendor": "' + key + '"}'}

print(button)
# -> {'title': 'test', 'payload': '/user_vendor_name{"vendor": "test"}'}

1 Like

This worked thanks a lot.

Although i had empty list as buttons and appended the title and payload like you showed above.

1 Like