Failing to set slot with buttons

Hi, I am trying to set a slot when the user presses a button. I tried a couple of methods but didn’t work. Not sure what I am missing. To clarify, I am not using any forms, as I have just one single slot to fill. Here are the files:

domain.yml:

config:
  store_entities_as_slots: true
intents:
- ss_ask_fitness_regime:
    use_entities: true
- yoga:
    use_entities: true
- cardio:
    use_entities: true
- sports:
    use_entities: true
- stregth_training:
    use_entities: true
- cross_fit:
    use_entities: true
entities:
- attrib_fitness_regime
slots:
  attrib_fitness_regime:
    type: text
    auto_fill: true
    influence_conversation: false
responses:
  utter_regime_buttons:
  - buttons:
    - payload: /yoga{{"attrib_fitness_regime":"yoga"}}
      title: Yoga
    - payload: /cardio{{"attrib_fitness_regime":"cardio"}}
      title: Cardio
    - payload: /sports{{"attrib_fitness_regime":"sports"}}
      title: Sports
    - payload: /strength_training{{"attrib_fitness_regime":"strength_training"}}
      title: Strength Training
    - payload: /crossfit{{"attrib_fitness_regime":"cross_fit"}}
      title: Cross Fit
    text: What fitness regime do you follow?
actions:
- action_fitness_regime_affirmation

stories.yml:

- story: ask fitness regime
  steps:
  - intent: ss_ask_fitness_regime
  - action: utter_regime_buttons
  - action: action_fitness_regime_affirmation

I first trigger the intent “ss_ask_fitness_regime” to start the story. I get the buttons back from rasa and when the user presses a button, I send the payload back to rasa and check the slot value “attrib_fitness_regime” from the tracker in the action. In my case, it is always None which is wrong.

I tried two ways to send the payload back and both cases failed to set the slot. One is to send the payload as simple text “/yoga{{“attrib_fitness_regime”:“yoga”}}”. Another way I tried is to trigger the intent “/yoga” and supply {“attrib_fitness_regime”:“yoga”} in “entities” as shown in this link: here:Reaching Out to the User

I tried to make the slot categorical instead of text, didn’t work. Not very sure what I am missing here. Any help is appreciated.

Thanks, Kris

Hello!

Does using single brackets instead of double brackets work? E.g.:

/yoga{"attrib_fitness_regime": "yoga"}

Other than that it all looks good. You have store_entities_as_slots: true and auto_fill: true.

Hi, Using single brackets gives me an error as shown below in Rasa server and the slot is still None. To fix the error someone suggested using double brackets and the error was gone. In one of the github issues, they said this was fixed but I still get that error. I didn’t look into this issue in detail as I just wanted to get this working, so used double brackets. I use rasa docker with image “rasa/rasa:2.8.0-spacy-en”. Even with single brackets, the slot is still None.

Error:

2021-08-28 12:53:50 ERROR    rasa.core.nlg.interpolator  - Failed to replace placeholders in response '/yoga{"attrib_fitness_regime":"yoga"}'. Tried to replace '"attrib_fitness_regime":"yoga"' 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 response. Return response without filling the response. 
Traceback (most recent call last):
  File "/opt/venv/lib/python3.8/site-packages/rasa/core/nlg/interpolator.py", line 27, in interpolate_text
    text = text.format(values)
KeyError: '"attrib_fitness_regime":"yoga"'

My action function looks like this:

class ActionGetFitnessRegime(Action):
    def name(self) -> Text:
        return "action_fitness_regime_affirmation"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        # Slot is None always :-(
        fitness_regime = tracker.get_slot('attrib_fitness_regime')
        dispatcher.utter_message("Fitness Regime: %s" %fitness_regime)
        return []
1 Like

I fixed it. I had to change the story to the following. I was under the impression that if we send buttons, Rasa will wait for a response which is not the case. We have to make it wait by listing all the intents possible in the reponse.


- story: ask fitness regime
  steps:
  - intent: ss_ask_fitness_regime
  - action: utter_regime_buttons
  - or:
      - intent: yoga
      - intent: cardio
      - intent: sports
      - intent: cross_fit
      - intent: strength_training
  - action: action_fitness_regime_affirmation
1 Like

You’re right!!

And sorry for the late reply! :slight_smile:

Please mark your answer as solution :slight_smile: