# How to get values from payload in button after choosing an option?

**URL:** <https://forum.rasa.com/t/how-to-get-values-from-payload-in-button-after-choosing-an-option/11979>\
**Category:** Rasa Open Source\
**Created:** [June 24, 2019, 4:10pm UTC](https://forum.rasa.com/t/how-to-get-values-from-payload-in-button-after-choosing-an-option/11979 "2019-06-24T16:10:16Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramonrod](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/ramonrod/32/6885_2.png) [@ramonrod](https://forum.rasa.com/u/ramonrod)\
**Post date:** [June 24, 2019, 4:10pm UTC](https://forum.rasa.com/t/how-to-get-values-from-payload-in-button-after-choosing-an-option/11979/1 "2019-06-24T16:10:16Z")

</div>

Hi there, I want to get access to the payload values from my custom buttons. The main idea is to choose one option from the buttons, and then collect the payload values in a variable, in order to pass these to the next action.

The custom buttons are in a loop where from each items I collect the needed values for the “titles” and for the “payloads”. I want to achieve this in a dynamic way, since I have a lot of different variables with different length.

Here is my code until now:

```
    def run(self, dispatcher: CollectingDispatcher,
             tracker: Tracker, domain: Dict[Text, Any],
         ) -> Text:
       for element in request.question.items:
       for l in element['choices']:
       buttons.append({"title": "{}".format(l['label']), "payload": "{}{}".format(element['id'],l['id'])})

       return []

```

`dispatcher.utter_button_message(message, buttons)`

Again, my question is how to access the selected payload values. In rasa x I can see that the payload is being selected properly, for example: `"11,true"`.

But I find no way to get these values into another variable.

Any help will be appreciated.

Thanks

---

<div class="post-metadata">

**Author:** ![naag](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/naag/32/6857_2.png) [@naag](https://forum.rasa.com/u/naag)\
**Post date:** [June 24, 2019, 6:13pm UTC](https://forum.rasa.com/t/how-to-get-values-from-payload-in-button-after-choosing-an-option/11979/2 "2019-06-24T18:13:15Z")

</div>

Have you tried tracker.latest\_message.get(‘text’)? This gets the latest message passed as input. Since when a button is pressed, the payload is sent to the NLU as input, I guess this could fetch the payload.

---

<div class="post-metadata">

**Author:** ![ramonrod](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/ramonrod/32/6885_2.png) [@ramonrod](https://forum.rasa.com/u/ramonrod)\
**Post date:** [June 24, 2019, 6:46pm UTC](https://forum.rasa.com/t/how-to-get-values-from-payload-in-button-after-choosing-an-option/11979/3 "2019-06-24T18:46:02Z")

</div>

Hi naag, Thank you for your answer. I did try that indeed, but I am only getting the last user input, as you said, the title of the buttons if you want. But I need the information behind that. If you see my code above again, I need an id which correspond to that element in the title.

I can see it is being called right in the payload, I just don’t know how to store this information in a variable in order to reuse it.

---

<div class="post-metadata">

**Author:** ![ramonrod](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/ramonrod/32/6885_2.png) [@ramonrod](https://forum.rasa.com/u/ramonrod)\
**Post date:** [June 25, 2019, 8:33am UTC](https://forum.rasa.com/t/how-to-get-values-from-payload-in-button-after-choosing-an-option/11979/4 "2019-06-25T08:33:10Z")

</div>

Any help please?

---

<div class="post-metadata">

**Author:** ![imabhinav-am](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/imabhinav-am/32/3370_2.png) [@imabhinav-am](https://forum.rasa.com/u/imabhinav-am)\
**Post date:** [June 25, 2019, 9:06am UTC](https://forum.rasa.com/t/how-to-get-values-from-payload-in-button-after-choosing-an-option/11979/5 "2019-06-25T09:06:31Z")

</div>

Use slots for storing the payload and mention the same in stories

---

<div class="post-metadata">

**Author:** ![ramonrod](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/ramonrod/32/6885_2.png) [@ramonrod](https://forum.rasa.com/u/ramonrod)\
**Post date:** [June 25, 2019, 9:31am UTC](https://forum.rasa.com/t/how-to-get-values-from-payload-in-button-after-choosing-an-option/11979/6 "2019-06-25T09:31:33Z")

</div>

Could you give an example, how I can store the payload information in a slot based on my example above? That would be very helpful.

---

<div class="post-metadata">

**Author:** ![imabhinav-am](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/imabhinav-am/32/3370_2.png) [@imabhinav-am](https://forum.rasa.com/u/imabhinav-am)\
**Post date:** [July 3, 2019, 5:33pm UTC](https://forum.rasa.com/t/how-to-get-values-from-payload-in-button-after-choosing-an-option/11979/7 "2019-07-03T17:33:21Z")

</div>

make a slot for example TEMP in domain file then in your first custom action use function SlotSet to set the slot value to desired value [https://rasa.com/docs/rasa/api/events/](https://rasa.com/docs/rasa/api/events/) and then use that value in next actions using getSlots method [https://rasa.com/docs/rasa/api/tracker/](https://rasa.com/docs/rasa/api/tracker/)

---

<div class="post-metadata">

**Author:** ![naag](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/naag/32/6857_2.png) [@naag](https://forum.rasa.com/u/naag)\
**Post date:** [July 4, 2019, 10:50am UTC](https://forum.rasa.com/t/how-to-get-values-from-payload-in-button-after-choosing-an-option/11979/8 "2019-07-04T10:50:39Z")

</div>

@ramonrod If you want to obtain the payload values after the user presses the button, you’ll have to configure slots in your domain.yml file and set slot values in the buttons accordingly. When the user presses the button, the values mentioned in the payload are extracted and assigned to the respective slots. You can configure stories to act accordingly when a certain slot is set.

To get the value of a certain slot in your custom action, use tracker.get\_slot(“slot\_name”), where slot\_name is the slot that you wish to extract.

Ensure that whichever entity value you intend to extract has a slot with the same name as the entity name. Check out [RASA Slots](https://rasa.com/docs/rasa/core/slots/)

Follow this format to set slots in the button payload:

To set a single slot - “payload”:"/intent\_name{/“slot1/”:/“value1/”}

To set multiple slots - “payload”:"/intent\_name{/“slot1/”:/“value1/”,/“slot2/”:/“value2/”}

Note that you need to escape the double quotes with the backslash as this is parsed as a json and it is necessary for the double quote characters to be present for this to work.

---

<div class="post-metadata">

**Author:** ![ramonrod](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/ramonrod/32/6885_2.png) [@ramonrod](https://forum.rasa.com/u/ramonrod)\
**Post date:** [July 4, 2019, 1:22pm UTC](https://forum.rasa.com/t/how-to-get-values-from-payload-in-button-after-choosing-an-option/11979/9 "2019-07-04T13:22:54Z")

</div>

Hi naag, This sounds reasonable. I will give it a try.

Thanks for the advise.

---

<div class="post-metadata">

**Author:** ![Shweta\_Mohite](https://avatars.discourse-cdn.com/v4/letter/s/ecccb3/32.png) [@Shweta\_Mohite](https://forum.rasa.com/u/Shweta_Mohite)\
**Post date:** [March 16, 2020, 6:43am UTC](https://forum.rasa.com/t/how-to-get-values-from-payload-in-button-after-choosing-an-option/11979/10 "2020-03-16T06:43:50Z")

</div>

Hey @ramonrod can you guide me how you have achieved saving button value in variable

---

<div class="post-metadata">

**Author:** ![rodrigo\_deoliveira](https://avatars.discourse-cdn.com/v4/letter/r/3ab097/32.png) [@rodrigo\_deoliveira](https://forum.rasa.com/u/rodrigo_deoliveira)\
**Post date:** [June 11, 2020, 5:27pm UTC](https://forum.rasa.com/t/how-to-get-values-from-payload-in-button-after-choosing-an-option/11979/11 "2020-06-11T17:27:56Z")

</div>

Tried @naag’s solution but wasn’t lucky =/

In `actions.py` I have:

```
my_slot = tracker.get_slot("my_slot")

```

```auto
intents:
    - start
    - greet
    - goodbye

entities:
  - my_slot

slots: 
  my_slot:
    type: categorical
    values:
    - a
    - b
    - c
    - d

responses:  
  utter_start:
    - text: What would you like to do?
      buttons:
      - title: A
        payload: '/greet{"my_slot": "a"}'
      - title: B
        payload: '/greet{"my_slot": "b"}'
      - title: C
        payload: '/greet{"my_slot": "c"}'
      - title: D
        payload: '/greet{"my_slot": "d"}'

```

But `my_slot` is `None` always. What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![samscudder](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/samscudder/32/4466_2.png) [@samscudder](https://forum.rasa.com/u/samscudder)\
**Post date:** [July 17, 2020, 12:43pm UTC](https://forum.rasa.com/t/how-to-get-values-from-payload-in-button-after-choosing-an-option/11979/12 "2020-07-17T12:43:00Z")

</div>

Did you manage to solve this? Can you post the output of `rasa shell --debug` for this?

---

<div class="post-metadata">

**Author:** ![Sharada201](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/sharada201/32/15272_2.png) [@Sharada201](https://forum.rasa.com/u/Sharada201)\
**Post date:** [June 5, 2021, 4:41am UTC](https://forum.rasa.com/t/how-to-get-values-from-payload-in-button-after-choosing-an-option/11979/13 "2021-06-05T04:41:47Z")

</div>

Hi,

Create intent for slot and train with some example.
