> This page is for Server SDKs.

> 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.

# Messages

> Task pack that takes a message for someone, reads it back, and passes it on once the caller agrees.

[operations]: /docs/server-sdks/reference/python/agents/operations/operations

[service-agent]: /docs/server-sdks/reference/python/agents/operations/service-agent

[write]: /docs/server-sdks/reference/python/agents/operations/write

[wording]: /docs/server-sdks/reference/python/agents/operations/wording

[front-desk]: /docs/server-sdks/reference/python/agents/prefabs/front-desk-agent

[personal-assistant]: /docs/server-sdks/reference/python/agents/prefabs/personal-assistant-agent

`Messages` is a task pack that takes a message for someone, reads it back, and passes
it on once the caller agrees. Add it to an [`Operations`][operations] or a
[`ServiceAgent`][service-agent] with `add_to()`.

When the caller gives no number, the pack offers the number they're calling from,
read back for them to agree to. A second message for the same recipient while the
first waits for a yes takes its place.

```python
from signalwire.operations import Message, Messages
```

## Parameters

All parameters are keyword-only.

**`save`** `Callable[[CallContext, Message], Any]` — required

`save(call, message)` passes the `Message` on once the caller says yes. Raise
[`WriteFailed`][write] when it can't. May be `async`.

---

**`recipients`** `Mapping[str, str] | None` — default: None

Who a message can be for, by name, each with a few words on who they are. `None` when
there's only one place messages go.

---

**`ask_for`** `Sequence[str]` — default: ("name", "number")

What's asked for when the caller hasn't said it: `"name"`, `"number"`, or both. Any
other value raises `ValueError`. The message itself is always asked for, and who it's
for whenever there are `recipients`.

---

**`caller_id`** `bool` — default: True

`True` to offer the number the caller is calling from when they haven't given one.

---

**`tool`** `str` — default: take_message

The tool's name.

---

**`wording`** `Mapping[str, str] | None` — default: None

Replacements keyed like `MESSAGES_WORDING`. See [wording][wording].

---

**`before_identity`** `bool` — default: True

`False` to take messages only from identified callers.

---

## Methods

`add_to(target)` registers the pack's operation on an `Operations` or a
`ServiceAgent`, and returns `target`.

## Message

A frozen dataclass that `save` receives.

**`Message.text`** `str`

The message, in the caller's words.

---

**`Message.name`** `str`

Who it's from, as they said it, or `""`.

---

**`Message.number`** `str`

A number to reach them on, as they gave it or agreed to, or `""`.

---

**`Message.to`** `str`

Who it's for (one of `recipients`), or `""`.

---

**`Message.call_id`** `str`

The platform's id for the call.

---

**`Message.account_id`** `str`

The account identified, or `""`.

---

## Example

```python
from signalwire.operations import Messages, ServiceAgent

agent = ServiceAgent("office", role="You answer the phone for a dental practice.")
Messages(
    save=lambda call, message: print(message.to, message.text, message.number),
    recipients={"Dr. Lee": "the dentist"},
).add_to(agent)
```

[`FrontDeskAgent`][front-desk] and [`PersonalAssistantAgent`][personal-assistant] take
a `Messages` pack as `messages=` and offer it when a call can't be put through.