> ## Documentation Index
> Fetch the complete documentation index at: https://docs.poly.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# SMS templates

> Define reusable SMS messages that the agent can send during a conversation.

SMS templates define reusable text messages that the agent can send during a conversation, such as confirmations, links, or verification codes.

> [!NOTE]
>
> **Enterprise feature**
>
> SMS templates require an enterprise Agent Studio account.

Templates support dynamic content through variables stored in conversation state.

## Location

SMS templates are defined in:

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
config/sms_templates.yaml
```

Templates are listed under the `sms_templates` key.

## What an SMS template contains

Each template can include the following fields:

| Field | Description |
| - | - |
| `name` | Identifier for the template. Referenced in prompts as `{{twilio_sms:template_name}}`. |
| `text` | Message body. Supports [`{{vrbl:variable_name}}`](https://docs.poly.ai/adk/reference/resources/variables) placeholders from `conv.state` and [`{{tn:translation_name}}`](https://docs.poly.ai/adk/reference/resources/translations) references. No other reference type (e.g. `{{fn:...}}`, `{{ho:...}}`) is valid here. |
| `env_phone_numbers` | Optional sender phone numbers for different environments. |

## Environment-specific sender numbers

If needed, you can define different sender numbers for different environments:

| Environment | Description |
| - | - |
| `sandbox` | Sender number for sandbox use |
| `pre_release` | Sender number for pre-release use |
| `live` | Sender number for production use |

## Example

```yaml theme={"theme":{"light":"github-light","dark":"github-dark"}}
sms_templates:
  - name: booking_confirmation
    text: "Hi {{vrbl:customer_name}}, your booking for {{vrbl:booking_date}} is confirmed. Reference: {{vrbl:booking_ref}}"
    env_phone_numbers:
      sandbox: "+15551234567"
      live: "+15559876543"

  - name: verification_code
    text: "Your verification code is {{vrbl:verification_code}}. It expires in 10 minutes."
```

## How SMS templates are used

> [card] In rules, topics, and flows
>
> Use `{{twilio_sms:template_name}}` to tell the agent which SMS should be sent.

> [card] In code
>
> Call a function that triggers the SMS through `conv` or the platform API.

> [card] With variables
>
> Use `{{vrbl:...}}` placeholders to insert values from conversation state.

## In prompts and instructions

SMS templates can be referenced in rules, topics, and related instructions using:

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
{{twilio_sms:template_name}}
```

This lets you reference the correct template by name without embedding the full message body in prompt text.

## Using variables and translations

Template text can include placeholders drawn from `conv.state`, for example:

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
{{vrbl:customer_name}}
```

It can also reference a [translation](https://docs.poly.ai/adk/reference/resources/translations.md) key, for example:

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
{{tn:booking_confirmed}}
```

Before the SMS is sent, the corresponding state variables should already be set in code.

For example:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
conv.state.customer_name = "Alice"
conv.state.booking_date = "12 March"
conv.state.booking_ref = "ABC123"
```

## Validation

* Only `{{vrbl:...}}` and `{{tn:...}}` references are valid inside `text` — using any other reference type fails validation.
* Each template `name` must be unique.

## Best practices

* set required state variables before the SMS is triggered
* use separate templates for different purposes such as confirmation, verification, and follow-up
* keep templates short and clear
* configure `env_phone_numbers` when sender numbers differ between environments
* prefer template references over hard-coded SMS text in prompts

> [!TIP]
>
> **Treat templates as reusable resources**
>
> SMS templates are easier to manage when each template has one clear purpose and a stable name.

## Related pages

> [card] [Variables](https://docs.poly.ai/adk/reference/resources/variables.md)
>
> Learn how values are stored in `conv.state` and referenced with `{{vrbl:...}}`.

> [card] [Functions](https://docs.poly.ai/adk/reference/resources/functions.md)
>
> See how deterministic code can set variables and trigger SMS sending.

> [card] [Translations](https://docs.poly.ai/adk/reference/resources/translations.md)
>
> Reference a localized string from template text with `{{tn:...}}`.

> [card] [SMS setup (platform)](https://docs.poly.ai/sms/introduction.md)
>
> Configuring SMS channels, sender numbers, opt-out handling, and full template options.

> [card] [Conversation object reference (platform)](https://docs.poly.ai/tools/classes/conv-object.md)
>
> Full reference for `conv.send_sms_template`, `conv.send_sms`, and all other `conv` methods.
