> This page is for SWML.

> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes.

# reply

> Create and send an outbound message in response to an inbound message.

Create and send an outbound message in response to the inbound message. `reply` accepts three
shapes: a string shorthand, an object with body/media/routing fields, or an inline `switch` that
branches the reply body on a variable's value.

`reply` does **not** end execution — subsequent steps in the section continue to run after the reply
is queued.

## **Properties**

`reply` accepts one of three shapes — use whichever fits the document shape:

#### String shorthand

A single string used as the reply body. The reply is sent to the inbound
message's `from` number, using the inbound `to` as the sender.

**`reply`** `string` — required

The body of the reply message. After variable expansion it must contain at least one
non-whitespace character. Body length is checked before the reply is queued. The limit depends on
the route SignalWire uses to send the reply, and length is counted according to the message
encoding. A body over the limit fails the reply with a `swml_reply_character_limit_exceeded`
[error](/docs/swml/reference/errors) whose message states the limit.

---

#### Object

Full control over the reply — set the body, attach media, override the routing fields, or configure
a delivery status callback. The reply needs content: either a `body` with at least one
non-whitespace character after variable expansion, or a `media` array with at least one URL.
`{ "reply": { "media": [] } }` has neither.

**`reply`** `object` — required

An object containing the properties below.

---

**`reply.body`** `string`

Text body of the outbound message. Required when `media` is not set. When no media is
attached, the body must contain at least one non-whitespace character after variable
expansion.

Body length is checked before the reply is queued. The limit depends on whether the reply is SMS
or MMS and on the route SignalWire uses to send it, and length is counted according to the
message encoding. A body over the limit fails the reply with a
`swml_reply_character_limit_exceeded` [error](/docs/swml/reference/errors) whose message states
the limit.

---

**`reply.media`** `string[]`

Array of HTTP or HTTPS media URLs to attach. Converts the message to MMS. Maximum 8 attachments.
Required if `body` is not present, and must then contain at least one URL. Media is fetched after
the reply is queued, so a `queued` result does not confirm that the media could be retrieved.

---

**`reply.to`** `string` — default: message.from

Destination phone number in E.164 format.

---

**`reply.from`** `string` — default: message.to

Sending phone number or short code. Must be owned by your project and have messaging capability.

---

**`reply.status_url`** `string`

HTTP or HTTPS URL to receive delivery status callbacks for the outbound reply message.
Callbacks are delivered after the reply is queued, so a `queued` result does not confirm that a
callback reached this URL. See [Status callbacks](#status-callbacks) below.

---

#### Inline switch

Branch the reply body on a variable's value — for keyword-driven replies.
The matched `case` (or `default`) provides the reply body.

**`reply`** `object` — required

An object with a single `switch` property.

---

**`reply.switch`** `object` — required

An object that accepts the properties below.

---

**`reply.switch.variable`** `string` — required

Variable path to match. Specified without the `%{}` wrapper (e.g. `message.body`).

---

**`reply.switch.transform`** `string`

Transform to apply to the value before matching. One of `lowercase`, `uppercase`, `trim`,
`lowercase_trim`, or `uppercase_trim`.

---

**`reply.switch.case`** `object` — required

Map of values to reply outcomes. Each entry's value is either:

* a **string** — used as the reply body, sent back to the original sender as SMS, or
* a **full reply object** with `body`, `media`, `to`, `from`, `status_url` — for cases that
  need media, a different destination, or a per-branch `status_url`.

`%{…}` placeholders inside the matched value are expanded before the reply is sent. A string
outcome follows the same rules as the string shorthand: it must contain at least one
non-whitespace character after expansion, and its length is checked against the reply body
limit.

---

**`reply.switch.default`** `string | object`

Fallback used when no `case` value matches. Accepts the same string-or-reply-object shape as a
`case` value. If omitted and no case matches, the `reply` step fails and execution stops.

---

When using an inline `switch`, do not set `body`, `media`, `to`, `from`, or `status_url` directly
on the same `reply` — put them inside each `case` value (or `default`) instead.

## **Variables**

`reply` writes these variables into the script context after it runs. Read them with the
`%{variable}` syntax in subsequent steps. When `reply` is called multiple times in a single
document, both variables reflect the most recent successful reply. If a reply can't be queued,
execution stops, so no later step runs.

**`reply_result`** `string`

Outcome of queuing the reply. `queued` when the outbound message was accepted and queued for
sending; `failed` when it couldn't be queued (invalid `from`/`to`, missing body and media,
character limit exceeded, missing messaging capability, inactive campaign, etc.). This value
doesn't report what happens to the message after it is queued — use
[status callbacks](#status-callbacks) or the
[message logs](/docs/apis/rest/message-logs/list-message-logs) to track delivery.

---

**`reply_message_id`** `string`

ID of the outbound message created by the most recent successful reply. It matches the `id` in
that reply's status callbacks. A failed reply doesn't set or clear it.

---

## **Status callbacks**

> **Status callbacks are advisory**
>
> Status callbacks are asynchronous, best-effort HTTP notifications: delivery can be delayed or fail silently — if your server is unreachable, the callback simply never arrives. Don't gate time-critical or business-critical actions solely on receiving one. Confirm state via the REST API before acting, or use a transport with visible failure modes — see [Status callback reliability](/docs/platform/webhooks#status-callback-reliability).

The `status_url` on `reply` registers a delivery status callback for the **outbound reply message** —
not for the inbound message that triggered the SWML document. It behaves the same way as the status
callback on any other outbound message sent through SignalWire.

* Fires as the outbound reply moves through delivery states, starting with a `queued` callback
  when the reply is queued.
* Callback delivery is independent of SWML execution: `reply` queues the outbound message and
  execution continues with the next step. Callbacks have no guaranteed order relative to the
  document's remaining steps.
* If `reply` is called multiple times in a single document, each reply's `status_url` is registered
  independently for its own outbound message.

When `status_url` is set, SignalWire sends an HTTP `POST` to that URL each time the outbound reply
transitions to a new state. The callback uses the same payload as other outbound messages sent
through SignalWire.

See the [Message status callback](/docs/apis/rest/webhooks/message-status-callback)
webhook page for the full field reference and the list of possible `status` values.

## **Examples**

### Reply with body

#### YAML

```yaml
version: 1.0.0
sections:
  main:
    - reply:
        body: "Thanks for your message!"
```

#### JSON

```json
{
  "version": "1.0.0",
  "sections": {
    "main": [
      {
        "reply": {
          "body": "Thanks for your message!"
        }
      }
    ]
  }
}
```

### Reply with media (MMS)

#### YAML

```yaml
version: 1.0.0
sections:
  main:
    - reply:
        body: "Here's the document you requested"
        media:
          - "https://example.com/document.pdf"
```

#### JSON

```json
{
  "version": "1.0.0",
  "sections": {
    "main": [
      {
        "reply": {
          "body": "Here's the document you requested",
          "media": [
            "https://example.com/document.pdf"
          ]
        }
      }
    ]
  }
}
```

### Reply with a status callback URL

#### YAML

```yaml
version: 1.0.0
sections:
  main:
    - reply:
        body: "Your order is confirmed"
        status_url: "https://example.com/status"
```

#### JSON

```json
{
  "version": "1.0.0",
  "sections": {
    "main": [
      {
        "reply": {
          "body": "Your order is confirmed",
          "status_url": "https://example.com/status"
        }
      }
    ]
  }
}
```

### Keyword-driven reply with inline switch

The inline `switch` form branches the reply body on a variable's value — typically the
inbound `message.body`.

#### YAML

```yaml
version: 1.0.0
sections:
  main:
    - reply:
        switch:
          variable: message.body
          transform: lowercase_trim
          case:
            help: "Reply STOP to unsubscribe, or visit https://example.com/help."
            stop: "You've been unsubscribed."
            start: "Welcome back!"
          default: "Thanks for your message!"
```

#### JSON

```json
{
  "version": "1.0.0",
  "sections": {
    "main": [
      {
        "reply": {
          "switch": {
            "variable": "message.body",
            "transform": "lowercase_trim",
            "case": {
              "help": "Reply STOP to unsubscribe, or visit https://example.com/help.",
              "stop": "You've been unsubscribed.",
              "start": "Welcome back!"
            },
            "default": "Thanks for your message!"
          }
        }
      }
    ]
  }
}
```

### Per-case media and routing with inline switch

When a case needs more than a body string — different media, a different destination, or a
per-branch `status_url` — supply a full reply object for that case instead of a bare string.

#### YAML

```yaml
version: 1.0.0
sections:
  main:
    - reply:
        switch:
          variable: message.body
          transform: lowercase_trim
          case:
            menu:
              body: "Here's our menu."
              media:
                - "https://example.com/menu.pdf"
            directions:
              body: "Tap below for directions."
              media:
                - "https://example.com/map.jpg"
            agent:
              body: "Connecting you with a human — they'll text from a different number."
              from: "+15559876543"
          default: "Reply MENU, DIRECTIONS, or AGENT."
```

#### JSON

```json
{
  "version": "1.0.0",
  "sections": {
    "main": [
      {
        "reply": {
          "switch": {
            "variable": "message.body",
            "transform": "lowercase_trim",
            "case": {
              "menu": {
                "body": "Here's our menu.",
                "media": ["https://example.com/menu.pdf"]
              },
              "directions": {
                "body": "Tap below for directions.",
                "media": ["https://example.com/map.jpg"]
              },
              "agent": {
                "body": "Connecting you with a human — they'll text from a different number.",
                "from": "+15559876543"
              }
            },
            "default": "Reply MENU, DIRECTIONS, or AGENT."
          }
        }
      }
    ]
  }
}
```

### Forward an inbound message to another number

#### YAML

```yaml
version: 1.0.0
sections:
  main:
    - reply:
        to: "+12223334444"
        from: "+15559876543"
        body: "Your number %{message.to} got a message from %{message.from}! The body was: %{message.body}"
```

#### JSON

```json
{
  "version": "1.0.0",
  "sections": {
    "main": [
      {
        "reply": {
          "to": "+12223334444",
          "from": "+15559876543",
          "body": "Your number %{message.to} got a message from %{message.from}! The body was: %{message.body}"
        }
      }
    ]
  }
}
```