Twilio
Telephony — Twilio Media Streams transport and voice webhook.
The Twilio plugin turns an inbound phone call into a session: it frames Twilio Media Streams (μ-law audio over a WebSocket) as a transport, and provides the voice webhook that answers a call with TwiML opening that stream.
Capabilities
Transport (media stream) · ingress (voice webhook)
Install & import
import "github.com/webdeveloperben/agents-go/plugins/twilio"No build tag. The media stream rides the generic WebSocket transport; Twilio supplies the framing.
Serve the webhook
http.Handle("/twilio/voice", twilio.WebhookHandler(twilio.WebhookConfig{
// StreamURL: absolute wss:// URL; empty derives wss://<host>/twilio/media
// StreamPath: media path when StreamURL is empty (default "/twilio/media")
// Parameters: custom <Parameter> pairs passed to the stream
}))twilio.BuildTwiML(streamURL, params) builds the response directly if you'd
rather not use the handler. twilio.New() returns the plugin identity (registers
as a transport/ingress provider).
Bind media to a session
Each media socket becomes one session over the WebSocket transport — see the
end-to-end wiring (worker + websocket.NewSessionHandoff) in
Telephony with Twilio.
Caveats
Twilio's wire is 8 kHz μ-law; match your TTS output rate accordingly. The runnable
examples/twiliovoice wires both endpoints with fakes (no cloud accounts).
Related
- Telephony with Twilio — the full how-to.
- Transports