# Defining Responses

Responses go under the `responses` key in your domain file or in a separate "responses.yml" file. Each response name should start with `utter_`. For example, you could add responses for greeting and saying goodbye under the response names `utter_greet` and `utter_bye`:

```yaml
intents:
  - greet

responses:
  utter_greet:
  - text: "Hi there!"
  utter_bye:
  - text: "See you!"
```

If you are using [retrieval intents](https://legacy-docs-oss.rasa.com/docs/rasa/glossary#retrieval-intent) in your assistant, you also need to add responses for your assistant's replies to these intents:

```yaml
intents:
  - chitchat

responses:
  utter_chitchat/ask_name:
  - text: Oh yeah, I am called the retrieval bot.

utter_chitchat/ask_weather:
  - text: Oh, it does look sunny right now in Berlin.
```

### Using Variables in Responses

You can use variables to insert information into responses. Within a response, a variable is enclosed in curly brackets. For example, see the variable `name` below:

```yaml
responses:
  utter_greet:
  - text: "Hey, {name}. How are you?"
```

When the `utter_greet` response is used, Rasa automatically fills in the variable with the value found in the slot called `name`. If such a slot doesn't exist or is empty, the variable gets filled with `None`.

Another way to fill in a variable is within a [custom action](/content/docs/reference/primitives/custom-actions/index.html). In your custom action code, you can supply values to a response to fill in specific variables. If you're using the Rasa SDK for your action server, you can pass a value for the variable as a keyword argument to [`dispatcher.utter_message`](/content/docs/reference/integrations/action-server/sdk-dispatcher/index.html):

```python
dispatcher.utter_message(
    template="utter_greet",
    name="Sara"
)
```

### Response Variations

You can make your assistant's replies more interesting if you provide multiple response variations to choose from for a given response name:

```yaml
responses:
  utter_greet:
  - text: "Hey, {name}. How are you?"
  - text: "Hey, {name}. How is your day going?"
```

In this example, when `utter_greet` gets predicted as the next action, Rasa will randomly pick one of the two response variations to use.

#### IDs for Responses

New in Rasa 3.6

You can now set an ID for any response. This is useful when you want to use the [NLG server](/content/docs/reference/integrations/nlg/index.html) to generate the response.

Type for ID is string.

Example of response variations with ID:

```yaml
responses:
  utter_greet:
  - id: "greet_1"
    text: "Hey, {name}. How are you?"
  - id: "greet_2"
    text: "Hey, {name}. How is your day going?"
```

### Channel-Specific Response Variations

To specify different response variations depending on which channel the user is connected to, use channel-specific response variations.

In the following example, the `channel` key makes the first response variation channel-specific for the `slack` channel while the second variation is not channel-specific:

```yaml
responses:
  utter_ask_game:
  - text: "Which game would you like to play on Slack?"
    channel: "slack"
  - text: "Which game would you like to play?"
```

### Conditional Response Variations

Specific response variations can also be selected based on one or more slot values using a conditional response variation. A conditional response variation is defined in the domain or responses YAML files similarly to a standard response variation but with an additional `condition` key.

```yaml
responses:
  utter_greet:
    - condition: slots.prior_visits > 1
      text: "Hey, {name}. Nice to see you again! How are you?"

- condition: not slots.prior_visits
      text: "Welcome. How is your day going?"
```

### Rich Responses

You can make responses rich by adding visual and interactive elements. There are several types of elements that are supported across many channels:

#### Buttons

You can add buttons to a response to allow the user to select from a list of options.

```yaml
responses:
  utter_greet:
  - text: "Hey! How are you?"
    buttons:
    - title: "great"
      payload: "/mood_great"
    - title: "super sad"
      payload: "/mood_sad"
```

#### Images

You can add images to a response by providing a URL to the image under the `image` key:

```yaml
  utter_cheer_up:
  - text: "Here is something to cheer you up:"
    image: "https://i.imgur.com/nGF1K8f.jpg"
```

### Using Responses in Conversations

If the name of the response starts with `utter_`, the response can directly be used as an action, without being listed in the `actions` section of your domain. You would add the response to the domain:

```yaml
responses:
  utter_greet:
  - text: "Hey! How are you?"
```

You can use that same response as an action in your Flows:

```yaml
flows:
  Greet:
    name: Greet
    description: This flow is called to greet customers at the start of the conversation.
    steps:
      - action: utter_Greet
```

If you want to change the text, or any other part of the response, you need to retrain the assistant before these changes will be picked up.
