How it works
Twilio routes to PolyAI
Twilio forwards the message to PolyAI via a pre-configured webhook. This webhook is set up automatically when you provision a number through PolyAI.
Session handling
If there’s an active conversation session with that user’s number, the message is added to the existing session. Otherwise, a new session is created and the agent greets the user (or processes the message directly, depending on your agent configuration).
Session behavior
| Scenario | Behavior |
|---|---|
| New user | A new conversation session is created. The agent’s start function runs with conv.channel_type = "sms". |
| Active session exists | The message is added to the existing conversation. The agent continues where it left off. |
| Previous session timed out | A new session is created. |
| Reply to an outbound SMS | The message is added to the session created by the Send SMS endpoint. The outbound message is part of the conversation context. |
Inactivity timeout
Once a conversation is engaged (at least one user reply), an inactivity timer starts:- After 24 hours of no messages, a warning message is sent to the user.
- If the user replies within 10 minutes, the session stays open and the timer resets.
- If no reply, the session terminates.
Channel detection
In your agent’s start function, detect inbound SMS usingconv.channel_type:
Setup
Inbound SMS requires:- A provisioned Twilio number — the number must be SMS-capable and provisioned for your project in Agent Studio.
- Webhook configuration — handled automatically when you provision the number through PolyAI. No manual Twilio webhook setup is needed.
- Agent configuration — your agent should handle the
smschannel type appropriately (greeting, conversation flow, formatting for text-based interaction).
Not every country supports inbound SMS. Check Number availability & compliance for 2-way SMS support by country, number types, and regulatory requirements.

