Fill slot with button raise KeyError with Rasa 2

-------- Solution --------

I found the correct format from this test case

Here is how you can do it

  - buttons:
    - payload: '/continue{{"chat_user_mood":"unhappy"}}'
      title: unhappy
    - payload: '/continue{{"chat_user_mood":"just_ok"}}'
      title: just_ok
    - payload: '/continue{{"chat_user_mood":"happy"}}'
      title: happy

-------- Original question --------

I want to fill the slot directly from the button. But I failed to do so.

System Ubuntu 20.04 & Mac OS 11 (Big Sur) + Python 3.8.

❯ pip list | grep rasa                                                                              
rasa                    2.0.6
rasa-sdk                2.0.0

I have defined both intent & slot like this

intents:
- affirm
- deny
- continue
...
slots:
  user_name:
    type: text
    influence_conversation: true
  chat_user_mood:
    type: categorical
    values:
      - happy
      - just_ok
      - unhappy

And reply is

  utter_chat_ask_user_mood:
  - buttons:
    # Trided several fotmat
    - payload: /continue{chat_user_mood:happy}
      title: happy
    - payload: '/continue{"chat_user_mood":"just_ok"}'
      title: just_ok
    - payload: '/continue{"chat_user_mood": "unhappy"}'
      title: unhappy

Then I get an error

2020-11-16 01:09:45 ERROR    rasa.core.nlg.interpolator  - Failed to fill utterance template '/continue{chat_user_mood:happy}'. Tried to replace 'chat_user_mood:happy' but could not find a value for it. There is no slot with this name nor did you pass the value explicitly when calling the template. Return template without filling the template. 
Traceback (most recent call last):
  File "/home/brikerman/.miniconda3/envs/chatty/lib/python3.8/site-packages/rasa/core/nlg/interpolator.py", line 28, in interpolate_text
    text = text.format(values)
KeyError: 'chat_user_mood:happy'
2020-11-16 01:09:45 ERROR    rasa.core.nlg.interpolator  - Failed to fill utterance template '/continue{"chat_user_mood":"just_ok"}'. Tried to replace '"chat_user_mood":"just_ok"' but could not find a value for it. There is no slot with this name nor did you pass the value explicitly when calling the template. Return template without filling the template. 
Traceback (most recent call last):
  File "/home/brikerman/.miniconda3/envs/chatty/lib/python3.8/site-packages/rasa/core/nlg/interpolator.py", line 28, in interpolate_text
    text = text.format(values)
KeyError: '"chat_user_mood":"just_ok"'
2020-11-16 01:09:45 ERROR    rasa.core.nlg.interpolator  - Failed to fill utterance template '/continue{"chat_user_mood": "unhappy"}'. Tried to replace '"chat_user_mood": "unhappy"' but could not find a value for it. There is no slot with this name nor did you pass the value explicitly when calling the template. Return template without filling the template. 
Traceback (most recent call last):
  File "/home/brikerman/.miniconda3/envs/chatty/lib/python3.8/site-packages/rasa/core/nlg/interpolator.py", line 28, in interpolate_text
    text = text.format(values)
KeyError: '"chat_user_mood": "unhappy"'
4 Likes

I am having the same problem. Did you find a solution to this?

Yep. I have updated the question. I like the new config format, just need to update the document

Updated

I don’t think you need the double braces {{ / }} do you? Is that a new 2.x requirement?

In 1.x it was a single set to set a slot with a button

But double braces solved my issue, when I use single brace in my yml with 2.x, I got KeyError exception.

4 Likes

Interesting, thanks, I’ll keep that in mind

Thank you for sharing this solution with the community @BrikerMan :slight_smile: