# How to extract value of button from custom action

**URL:** <https://forum.rasa.com/t/how-to-extract-value-of-button-from-custom-action/49085>\
**Category:** Rasa Open Source\
**Created:** [November 8, 2021, 1:35pm UTC](https://forum.rasa.com/t/how-to-extract-value-of-button-from-custom-action/49085 "2021-11-08T13:35:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajas.black](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/rajas.black/32/15711_2.png) [@rajas.black](https://forum.rasa.com/u/rajas.black)\
**Post date:** [November 8, 2021, 1:35pm UTC](https://forum.rasa.com/t/how-to-extract-value-of-button-from-custom-action/49085/1 "2021-11-08T13:35:21Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)\
**Post date:** [November 9, 2021, 7:54am UTC](https://forum.rasa.com/t/how-to-extract-value-of-button-from-custom-action/49085/2 "2021-11-09T07:54:11Z")

</div>

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

For example:

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

```

---

<div class="post-metadata">

**Author:** ![rajas.black](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/rajas.black/32/15711_2.png) [@rajas.black](https://forum.rasa.com/u/rajas.black)\
**Post date:** [November 9, 2021, 8:03am UTC](https://forum.rasa.com/t/how-to-extract-value-of-button-from-custom-action/49085/3 "2021-11-09T08:03:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)\
**Post date:** [November 9, 2021, 8:05am UTC](https://forum.rasa.com/t/how-to-extract-value-of-button-from-custom-action/49085/4 "2021-11-09T08:05:41Z")

</div>

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

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

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

```

---

<div class="post-metadata">

**Author:** ![rajas.black](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/rajas.black/32/15711_2.png) [@rajas.black](https://forum.rasa.com/u/rajas.black)\
**Post date:** [November 9, 2021, 8:48am UTC](https://forum.rasa.com/t/how-to-extract-value-of-button-from-custom-action/49085/5 "2021-11-09T08:48:13Z")

</div>

This worked thanks a lot.

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