# Variable in utterance

**URL:** <https://forum.rasa.com/t/variable-in-utterance/52521>\
**Category:** Rasa Open Source\
**Created:** [April 11, 2022, 2:41pm UTC](https://forum.rasa.com/t/variable-in-utterance/52521 "2022-04-11T14:41:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![peixeprata](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/peixeprata/32/20551_2.png) [@peixeprata](https://forum.rasa.com/u/peixeprata)\
**Post date:** [April 11, 2022, 2:41pm UTC](https://forum.rasa.com/t/variable-in-utterance/52521/1 "2022-04-11T14:41:37Z")

</div>

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:

```auto
    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:

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

```

---

<div class="post-metadata">

**Author:** ![itsjhonny](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/itsjhonny/32/20201_2.png) [@itsjhonny](https://forum.rasa.com/u/itsjhonny)\
**Post date:** [April 11, 2022, 2:49pm UTC](https://forum.rasa.com/t/variable-in-utterance/52521/2 "2022-04-11T14:49:33Z")

</div>

You can stored this value in slot

domain.yml

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

```

in action

```auto
from rasa_sdk.events import UserUtteranceReverted, SlotSet

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

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

```

---

<div class="post-metadata">

**Author:** ![peixeprata](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/peixeprata/32/20551_2.png) [@peixeprata](https://forum.rasa.com/u/peixeprata)\
**Post date:** [April 11, 2022, 3:11pm UTC](https://forum.rasa.com/t/variable-in-utterance/52521/3 "2022-04-11T15:11:07Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![itsjhonny](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/itsjhonny/32/20201_2.png) [@itsjhonny](https://forum.rasa.com/u/itsjhonny)\
**Post date:** [April 11, 2022, 3:22pm UTC](https://forum.rasa.com/t/variable-in-utterance/52521/4 "2022-04-11T15:22:58Z")

</div>

😊 😊

I think the correct is

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

```

reference: [Reaching Out to the User](https://rasa.com/docs/rasa/next/reaching-out-to-user/)

You can set the slot inside your greet action
