Variable in utterance

Hello guys,

I have a greet action that returns an username, can I use that variable in a goodbye utterance without having to call another action?

Something like that:

Action:

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
 
        utterances = ["Hello ##username##",
"Hi ##username##"]

        utterance = random.choice(utterances)
        dispatcher.utter_message(text=utterance, buttons=buttons)

Bye Utterance:

utter_bye:
- text: It was good chatting with you ##username##.

You can stored this value in slot

domain.yml

slots:
  slot_username:
    type: text
    initial_value: null
    influence_conversation: false

in action

from rasa_sdk.events import UserUtteranceReverted, SlotSet

#get value
username = tracker.get_slot('slot_username')

#set variable in slot
SlotSet('slot_username', 'some_username')
2 Likes

Thanks João (Valeu João, salvou rs)!

Can I ask you something else? In Rasa 2 I should use that syntax in utterance?

utter_bye:

  • text: It was good chatting with you ##username##.

Another thing is need to build a new action for that or I can set the slot inside the greet action?

:blush: :blush:

I think the correct is

utter_bye:
- text: Nice to meet you, {slot_username}.

reference: Reaching Out to the User

You can set the slot inside your greet action

1 Like