# Saved reply and chat action variables

> Look up every placeholder you can put in a saved reply or a chat action, what it's replaced with, and what happens when it has no value.

Source: https://docs.soosh.io/reference/variables/

A variable is a name in double curly braces, like `{{contact_name}}`. Saved replies and chat actions replace it with a real value when they run. The two use different names.

Template variables like `{{1}}` are a different thing. See [Use variables in a template](https://docs.soosh.io/guides/templates/use-variables-in-a-template/).

## Saved reply variables

Use these in [**Inbox > Saved replies**](https://app.soosh.io/saved-replies), in **Content** and in the text of each button (its title, link and phone number). Soosh fills them in when an agent picks the reply in a chat.

| Variable | Replaced with | Example |
|---|---|---|
| `{{contact_name}}` | The customer's WhatsApp profile name. `there` if the chat has no name. | `Priya Sharma` |
| `{{phone_number}}` | The customer's number in international format, without `+`. | `919812345678` |
| `{{agent_name}}` | The full name of the member sending the reply. | `Ravi` |
| `{{user_name}}` | Same as `{{agent_name}}`. The editor has no button for it. | `Ravi` |

In the editor, **Customer name**, **Phone number** and **Your name** insert `{{contact_name}}`, `{{phone_number}}` and `{{agent_name}}`.

Example content, sent by Ravi in Priya's chat:

```text
Hi {{contact_name}}, this is {{agent_name}} from Blue Lotus Fashion.
```

```text
Hi Priya Sharma, this is Ravi from Blue Lotus Fashion.
```

### Blanks

Any other name is a blank. **Blank to fill** inserts `{{variable}}` with the name selected so you can type over it.

| Rule | Detail |
|---|---|
| Characters allowed in a name | Letters A to Z, digits, `_`, `.` and `-`. A name with a space or any other character isn't a variable and is sent as typed. |
| Spaces inside the braces | Ignored. `{{ order_id }}` is the same as `{{order_id}}`. |
| Capital letters | Names are case-sensitive. `{{Contact_Name}}` is a blank, not the customer's name. |
| What the agent sees | A gap in the message, labelled with the name with `_`, `.` and `-` shown as spaces. `{{order_id}}` reads as *order id*. |
| Same name twice | One gap. The agent's entry fills every place the name appears. |
| Empty blank | The agent can't send until every gap has text. The footer shows **1 blank to fill**, or **2 blanks to fill** and so on, then **Ready to send**. |
| Length | Up to 4,096 characters per gap. |

Example content with a blank:

```text
Hi {{contact_name}}, your order {{order_id}} is on its way.
```

Ravi types `BLF-20418` into the gap. Priya gets:

```text
Hi Priya Sharma, your order BLF-20418 is on its way.
```

### Older replies

Replies written with single braces, like `{contact_name}`, are read as `{{contact_name}}`. This works for `contact_name`, `phone_number`, `agent_name` and `user_name` only.

### With Mask phone numbers on

The chat gives the reply the masked number, so `{{phone_number}}` is sent as the masked number, like `********5678`, and the customer sees it.

## Chat action variables

Chat actions use paths with a dot, like `{{contact.phone_number}}`. They're replaced in these fields:

| Action type | Fields |
|---|---|
| **Webhook (Call external API)** | **Webhook URL**, the value of each header under **Headers (optional)**, and **Request body (JSON)** |
| **Open URL (Open in browser)** | **URL** |

They aren't replaced in **HTTP method**, in header names, or in **JavaScript (Run custom code)** actions. A JavaScript action gets the same data as objects named `contact`, `user` and `organization` instead.

| Variable | Replaced with | Example |
|---|---|---|
| `{{contact.id}}` | The contact's ID. | `3f2a1c9e-0000-0000-0000-000000000001` |
| `{{contact.name}}` | The customer's WhatsApp profile name. Empty if none. | `Priya Sharma` |
| `{{contact.profile_name}}` | Same as `{{contact.name}}`. | `Priya Sharma` |
| `{{contact.phone_number}}` | The customer's number in international format, without `+`. | `919812345678` |
| `{{contact.tags}}` | The contact's tags as a JSON list. | `["VIP"]` |
| `{{contact.metadata}}` | The contact's extra details as a JSON object. | `{"city":"Pune"}` |
| `{{user.id}}` | The ID of the member who clicked the action. | `7c1d4b2a-0000-0000-0000-000000000002` |
| `{{user.name}}` | That member's full name. | `Ravi` |
| `{{user.email}}` | That member's email. | `ravi@example.com` |
| `{{organization.id}}` | The workspace's ID. | `b5e0a8d3-0000-0000-0000-000000000003` |
| `{{organization.name}}` | The workspace's name. | `Blue Lotus Fashion` |

The action form lists `{{contact.name}}`, `{{contact.phone_number}}`, `{{user.name}}` and `{{user.email}}`.

Example **Open URL** link:

```text
https://crm.example.com/contact?phone={{contact.phone_number}}
```

```text
https://crm.example.com/contact?phone=919812345678
```

Example **Request body (JSON)**, run by Ravi on Priya's chat:

```json
{
  "subject": "WhatsApp: {{contact.name}}",
  "phone": "{{contact.phone_number}}",
  "agent": "{{user.name}}"
}
```

```json
{
  "subject": "WhatsApp: Priya Sharma",
  "phone": "919812345678",
  "agent": "Ravi"
}
```

With **Request body (JSON)** left empty, a webhook action sends the whole `contact`, `user` and `organization` data as JSON.

### Empty and unknown variables

| You write | Soosh sends |
|---|---|
| A known variable with no value, like `{{contact.name}}` for a contact with no name | Nothing: an empty string. |
| A name that doesn't exist, like `{{contact.nickname}}` or `{{nickname}}` | Nothing: an empty string. |
| A path that goes through something that isn't an object, like `{{nickname.first}}` or `{{contact.name.first}}` | The text as you typed it, braces included. |
| `{{contact.metadata.city}}` | The text as you typed it. Fields inside `contact.metadata` can't be picked out; use `{{contact.metadata}}` for the whole object. |
| `{{contact}}`, `{{user}}` or `{{organization}}` | The whole object as JSON. |
| Text with only one brace, or no name, like `{contact.name}` or `{{}}` | The text as you typed it. |

Names are case-sensitive, and spaces around the name are ignored.

### How values are inserted

Soosh escapes each value for the field it goes into, so a value can't break what it lands in:

- In a **URL** (**Webhook URL**, or **URL** for **Open URL**), values are encoded for a link: a space becomes `%20`, and `&`, `/`, `?` and `.` are encoded too. `Priya & Co` goes in as `Priya%20%26%20Co`. Use them in the path or the query, like `?name={{contact.name}}`.
- In **Request body (JSON)**, text is escaped as inside a JSON string, so put the variable inside quote marks: `"name": "{{contact.name}}"`. A name with a quote mark stays valid JSON. Lists and objects, like `{{contact.tags}}` and `{{contact.metadata}}`, go in as JSON, so leave those without quote marks.
- In a header value, a line break becomes a space, so a value stays on its header's line.

A **Webhook URL** must write out its host, like `https://crm.example.com/...`. A variable before the path, like `https://{{contact.name}}.example.com`, makes the action fail, because the headers can carry your keys.

Chat actions send the customer's real number even when **Mask phone numbers** is on.

## Related

- [Create a saved reply](https://docs.soosh.io/guides/inbox/create-a-saved-reply/)
- [Use saved replies](https://docs.soosh.io/guides/inbox/use-saved-replies/)
- [Create a chat action](https://docs.soosh.io/guides/integrations/create-a-chat-action/)
- [Run a chat action](https://docs.soosh.io/guides/inbox/run-a-chat-action/)
- [Hide customers' phone numbers](https://docs.soosh.io/guides/workspace/hide-customers-phone-numbers/)
