# Save Payload Value to List Slot

**URL:** <https://forum.rasa.com/t/save-payload-value-to-list-slot/42092>\
**Category:** Tutorials, Resources & Videos\
**Created:** [April 5, 2021, 11:53am UTC](https://forum.rasa.com/t/save-payload-value-to-list-slot/42092 "2021-04-05T11:53:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![IsraaMohamedHamid](https://avatars.discourse-cdn.com/v4/letter/i/a9a28c/32.png) [@IsraaMohamedHamid](https://forum.rasa.com/u/IsraaMohamedHamid)\
**Post date:** [April 5, 2021, 11:53am UTC](https://forum.rasa.com/t/save-payload-value-to-list-slot/42092/1 "2021-04-05T11:53:09Z")

</div>

I am creating a restaurant bot in which the user is asked to pay or order more, when the user picks order more it repeats part of the story that displays the restaurant menu category and then chooses the dish he/she wants. My problem is that the button should set two slots; a list and a normal slot. This is my code:

######ACTION######

> ```
> i=1
> buttons = []
> for restaurant_menu_category_en in all_restaurant_menu_categories_en:
> title = str(i) + "- "+ restaurant_menu_category_en[1] +"\n"
> payload = "/ask_chosen_restaurant_menu_category_en{\"chosen_restaurant_menu_category_en\":\"" + restaurant_menu_category_en[1] + "\",\"chosen_restaurant_menu_category_list_en\":\"" + tracker.get_slot('chosen_restaurant_menu_category_list_en').append(restaurant_menu_category_en[1]) + "\"}"
> i+=1
> buttons.append({"title": title,"payload": payload})
>                  	
> dispatcher.utter_message(buttons=buttons)
> 
> ```

######DOMAIN######

###slots###

> ```
> chosen_restaurant_menu_category_en:
> type: text
> influence_conversation: false
> chosen_restaurant_menu_category_list_en:
> type: list
> initial_value: []
> influence_conversation: true
> 
> ```

#####STORY#####

> - intent: ask\_chosen\_restaurant\_menu\_category\_en entities:
> - chosen\_restaurant\_menu\_category\_en: sandwich
> 
> - slot\_was\_set:
> - chosen\_restaurant\_menu\_category\_en: sandwich
> 
> - slot\_was\_set:
> - chosen\_restaurant\_menu\_category\_list\_en:

My problem is that when I run the code I get the following

> error: TypeError: can only concatenate str (not “NoneType”) to str

for this line: payload =

> “/ask\_chosen\_restaurant\_menu\_category\_en{"chosen\_restaurant\_menu\_category\_en":"” + restaurant\_menu\_category\_en[1] + “","chosen\_restaurant\_menu\_category\_list\_en":"” + tracker.get\_slot(‘chosen\_restaurant\_menu\_category\_list\_en’).append(restaurant\_menu\_category\_en[1]) + “"}”

How can I append the payload value to a list?

---

<div class="post-metadata">

**Author:** ![m.vielkind](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/m.vielkind/32/12693_2.png) [@m.vielkind](https://forum.rasa.com/u/m.vielkind)\
**Post date:** [April 5, 2021, 8:41pm UTC](https://forum.rasa.com/t/save-payload-value-to-list-slot/42092/2 "2021-04-05T20:41:18Z")

</div>

Hi @IsraaMohamedHamid instead of handling this all at once could you do this with a custom action? In your payload you can set the value for `chosen_restaurant_menu_category_en` and then have a custom action to process the input to append to a list. This is probably the cleanest way.

I think the reason you’re getting your error is this segment is evaluating to `None` `tracker.get_slot('chosen_restaurant_menu_category_list_en').append(restaurant_menu_category_en[1])`.

A workaround would be to construct your payload first and then use `json.dumps` to attach it to your button. Something like this, but the custom action to process to the user response is probably cleaner.

```auto
new_list = tracker.get_slot('chosen_restaurant_menu_category_list_en').copy()
new_list.append(restaurant_menu_category_en[1])
d = {
"chosen_restaurant_menu_category_en": restaurant_menu_category_en[1],
"chosen_restaurant_menu_category_list_en": new_list
}
payload = f"/ask_chosen_restaurant_menu_category_en{json.dumps(d)}"

```

---

<div class="post-metadata">

**Author:** ![IsraaMohamedHamid](https://avatars.discourse-cdn.com/v4/letter/i/a9a28c/32.png) [@IsraaMohamedHamid](https://forum.rasa.com/u/IsraaMohamedHamid)\
**Post date:** [April 7, 2021, 6:05pm UTC](https://forum.rasa.com/t/save-payload-value-to-list-slot/42092/3 "2021-04-07T18:05:33Z")

</div>

@m.vielkind thank you so much. I have managed to solve the problem by adding a new custom action: class ActionSaveCategoryToList\_en(Action):

```
def name(self):
	return 'action_save_category_to_list_en'
	
def run(self, dispatcher, tracker, domain):
	chosen_category_list_en = tracker.get_slot('chosen_restaurant_menu_category_list_en')
	##print(chosen_category_list_en) ####### Check to see if code prints correctly ####### 
	
	current_chosen_category_en = tracker.get_slot('chosen_restaurant_menu_category_en')
	##print(current_chosen_category_en) ####### Check to see if code prints correctly ####### 
	
	chosen_category_list_en.append(current_chosen_category_en)
	##print(chosen_category_list_en) ####### Check to see if code prints correctly ####### 
	
	return [SlotSet("chosen_restaurant_menu_category_list_en", chosen_category_list_en)]

```

I just call it in my story after setting the slots and it works perfectly. I just wanted to make sure that there isn’t another way to write less code but since it’s not broken and all. Again thank you very much you’ve helped a lot. Sorry tI just have one last question and it happened more than once, when it comes to adding a number like quantity or phone number and I use the shell debugger to check it does not fill the slot, have you ever come accross a problem like this?
