Skip to navigation

Messages

View as MarkdownOpen in Claude

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 or a ServiceAgent 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.

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 when it can’t. May be async.

recipients
Mapping[str, str] | NoneDefaults to 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]Defaults to ("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
boolDefaults to True

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

tool
strDefaults to take_message

The tool’s name.

wording
Mapping[str, str] | NoneDefaults to None

Replacements keyed like MESSAGES_WORDING. See wording.

before_identity
boolDefaults to 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

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 and PersonalAssistantAgent take a Messages pack as messages= and offer it when a call can’t be put through.