- A Twilio account (Account SID + Auth Token from the Console home page)
- A phone number in that account
- An AssemblyAI API key
- An HTTPS endpoint that accepts POST (use webhook.site for testing)
1. Install the Twilio CLI and log in
Install
2. Fill in your details
Save these in a.env file in your working directory:
.env
TRUNK_DOMAIN is a name you invent. It must end in .pstn.twilio.com and be unique across Twilio, so include your company name.
3. Create the SIP trunk
A SIP trunk is the connection Twilio uses to hand calls off to AssemblyAI. You will create an empty trunk here, then configure it in the next two steps. Create the trunk using the$TRUNK_DOMAIN you set in step 2:
sid from the response and save it in your shell:
$TRUNK_SID in steps 4 and 5.
4. Send incoming calls to AssemblyAI
5. Put your number on the trunk
Look up your number’s SID:6. Create your agent
Your agent has three parts:- A system prompt telling it how to behave on the call.
- A
process_paymenttool that charges the card. Card number, expiry, and authorization are collected from the keypad usingdtmf_collected_arguments, so the model never hears or sees them. - A
send_receipttool that emails the receipt after payment.
agent.json:
agent.json
Create agent
Keypad settings reference
Each entry indtmf_collected_arguments controls one keypad prompt:
7. Register the number and attach the agent
Register and attach
201 then 200, and the last call should show your agent_id with "type": "imported".
8. Call it
Ring the number. Say yes when it offers to take payment, then: type a card number and press# → press 1 to confirm → type the four digit expiry → press 1 to authorize → say your email.
Refresh webhook.site and you will see the payment request arrive, then the receipt request.
If it does not work
- Nothing happens when you call. Check the number is on the trunk (5), the origination URL is exactly
sip:sip.assemblyai.comand enabled (4), and an agent is attached (7). A number with a Voice webhook still set in the Console is not going through the trunk. - The agent asks out loud instead of using the keypad.
parameter_namedoes not match a parameter name in the tool. 409number already registered ·404 agent_not_foundwrong agent ID ·422 phone_number_has_no_agentdo step 7 ·502Twilio rejected it, retry.- Twilio command not recognised. Names change between CLI versions. Run
twilio api:trunking:v1 --help, or use the Console.