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
Optional[str]Defaults to None

Text body of the message.

media
Optional[list[str]]Defaults to None

List of media URLs to include as MMS attachments.

tags
Optional[list[str]]Defaults to None

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

region
Optional[str]Defaults to None

Region to originate the message from.

Returns

FunctionResult — self, for chaining.

Examples

Text Message

1from signalwire import AgentBase
2from signalwire import FunctionResult
3
4agent = AgentBase(name="my-agent", route="/agent")
5agent.set_prompt_text("You are a helpful assistant.")
6
7@agent.tool(name="send_confirmation", description="Send an order confirmation SMS")
8def send_confirmation(args, raw_data):
9 phone = args.get("phone_number")
10 order_id = args.get("order_id")
11 return (
12 FunctionResult("I've sent you a confirmation text.")
13 .send_sms(
14 to_number=phone,
15 from_number="+15559876543",
16 body=f"Your order {order_id} has been confirmed!"
17 )
18 )
19
20agent.serve()

MMS with Media

1from signalwire import AgentBase
2from signalwire import FunctionResult
3
4agent = AgentBase(name="my-agent", route="/agent")
5agent.set_prompt_text("You are a helpful assistant.")
6
7@agent.tool(name="send_receipt", description="Send a receipt with media attachment")
8def send_receipt(args, raw_data):
9 phone = args.get("phone_number")
10 receipt_url = args.get("receipt_url")
11 return (
12 FunctionResult("I've sent your receipt.")
13 .send_sms(
14 to_number=phone,
15 from_number="+15559876543",
16 body="Here's your receipt:",
17 media=[receipt_url]
18 )
19 )
20
21agent.serve()