send_sms

View as MarkdownOpen in Claude

Send an SMS or MMS message to a phone number. At least one of body or media must be provided. Generates a SWML send_sms verb under the hood.

Raises ValueError if neither body nor media is provided.

Parameters

to_number
strRequired

Destination phone number in E.164 format (e.g., "+15551234567").

from_number
strRequired

Sender phone number in E.164 format. Must be a number in your SignalWire project.

body
str | NoneDefaults to None

Text body of the message.

media
list[str] | NoneDefaults to None

List of media URLs to include as MMS attachments.

tags
list[str] | NoneDefaults to None

Tags to associate with the message for searching and filtering in the SignalWire dashboard.

region
str | NoneDefaults to None

Region to originate the message from.

Returns

FunctionResult — self, for chaining.

Examples

Text Message

from signalwire import AgentBase
from signalwire import FunctionResult
agent = AgentBase(name="my-agent", route="/agent")
agent.set_prompt_text("You are a helpful assistant.")
@agent.tool(name="send_confirmation", description="Send an order confirmation SMS")
def send_confirmation(args, raw_data):
phone = args.get("phone_number")
order_id = args.get("order_id")
return (
FunctionResult("I've sent you a confirmation text.")
.send_sms(
to_number=phone,
from_number="+15559876543",
body=f"Your order {order_id} has been confirmed!"
)
)
agent.serve()

MMS with Media

from signalwire import AgentBase
from signalwire import FunctionResult
agent = AgentBase(name="my-agent", route="/agent")
agent.set_prompt_text("You are a helpful assistant.")
@agent.tool(name="send_receipt", description="Send a receipt with media attachment")
def send_receipt(args, raw_data):
phone = args.get("phone_number")
receipt_url = args.get("receipt_url")
return (
FunctionResult("I've sent your receipt.")
.send_sms(
to_number=phone,
from_number="+15559876543",
body="Here's your receipt:",
media=[receipt_url]
)
)
agent.serve()