User choice from bot response


I have following situation. If a users asks for paid special leave the bot is answering the following: Choose from the list:

[1] – Baby is born

[2] – Fatality

after that I made a custom action which tracks the latest user message, here is the snippet:

def name(self):
return 'action_extra_vacation'

def run(self, dispatcher, tracker, domain):

user_msg = tracker.latest_message.get('text')

if user_msg == 1:


If I type 1 the bot falls into default fallback I add and says “Sorry, I can´t help you”. Is there any option I can use to allow user inputs which only affects the message which is generated in the custom action script?

Here is a story example to make things clear:

* ask_extra_vacation
    - utter_ask_extra_vacation_topic
    - action_extra_vacation
* say_thank_you
    - utter_you_are_welcome
* goodbye
    - utter_goodbye

Try using buttons. In this example “inform” is an intent and “opc” is a slot. You also need to replace your utter with a custom action.

buttons = []
buttons.append({ "title": "Baby is born", "payload": "/inform{\'opc\':  \'1\' }"  })
buttons.append({ "title": "Fatality", "payload": "/inform{\'opc\':  \'2\' }"  })
dispatcher.utter_button_message("Choose from the list:", buttons)

Your story will look like:

* ask_extra_vacation
    - action_ask_extra_vacation_topic
*inform{"opt": "1"}
   - slot{"opt": "1"}
    - action_extra_vacation

Hi @Gehova thank you for your suggestion. Unfortunately my messenger does not support buttons, so I think your solution won´t work. Do you have another idea?

One problem is definitely that you’re checking whether the user input is integer 1. But it should be a string.

if user_msg == '1':

@tabularasa yeah, that was exactly the problem. Thank you so much for you help.

Hi Max, i want user can choose a option by number like you but my knowledge in python is very bad

My issue is: user can chat 1 or 2 or 3 to choose the food like:
Bot: please choose you food
1: order pizza
2: order noodle
3: order pasta
User: 1
Bot: ok you choose the pizza

This is my python code. But it is not run

class chooseOption(Action): def name(self): return “action_choose_option”

def run(self, dispatcher, tracker, domain):

    user_msg = tracker.latest_message.get('text')

if user_msg == '1':
    response = "ok you choose pizza"

if user_msg == '2':
    response = "ok you choose noddle"
if user_msg == '3':
    response = "ok you choose pasta"

    dispatcher.utter_template("response", tracker)
    return []

Can you help me

@vunt39 sorry for my late reply. I think for your output specification you don´t need the dispatcher.utter_template("response", tracker)

did you already tried to replace the dispatcher to dispatcher.utter_message(response) ?

Do you get any error message while running your bot?

1 Like

Thank you for reply. I did it. Replace utter_template to utter_message. But i have a different issue. That’s when i want to call a formAction by an action like that ( in this case: response is a formAction). And it’s impossible. Do you have any ideas for that: choose an option by number

It´s pretty hard to help you if you provide such small information to us.

First of all, if you post your code snippets it´s much easier to follow your problem. It would also be very helpful if you describe your desired output and the actual output you get.

Error messages also helps us to understand the problem.

Did you read this article how to build a FormAction within RASA?

Since your problem is far away from mine, you can think about to post a new question in the rasa community forum because this way you can reach more developers.