assistant-api with a new telephony provider. Read the telephony overview first to understand how providers integrate into the call pipeline.
Architecture
Every telephony provider consists of two layers:telephony/telephony.go resolves which implementation to use at runtime based on the provider string constant.
Step-by-Step Guide
Add the provider constant
Open This string becomes the provider identifier in all webhook URLs:
api/assistant-api/internal/channel/telephony/telephony.go and add a new constant:/v1/talk/my-provider/call/{assistantId}Implement the Telephony interface
telephony.go must implement the internal_type.Telephony interface:- Extract
assistantIdfromc.Param("assistantId") - Return appropriate response format for your provider (TwiML XML, NCCO JSON, etc.)
- Use
cc.GetContext()to access conversation state
Implement the Streamer interface
websocket.go bridges the provider’s audio stream to the AI pipeline:- Twilio and Exotel send base64-encoded μ-law 8kHz in JSON envelopes
- Vonage sends raw Linear PCM 16kHz binary frames
- Rapida’s STT pipeline expects 16kHz PCM — resample if needed
Register in the factory
Open
api/assistant-api/internal/channel/telephony/telephony.go and add your provider to both factory functions:Interface Reference
internal_type.Telephony
| Method | Called When |
|---|---|
ReceiveCall(c *gin.Context) | Provider POSTs to /v1/talk/{provider}/call/{assistantId} |
OutboundCall(auth, to, from, cc, vault, opts) | SDK/API initiates an outbound call |
InboundCall(c *gin.Context, cc) | Provider WebSocket connection arrives at /v1/talk/{provider}/ctx/{contextId} |
StatusCallback(c *gin.Context, cc) | Provider POSTs a status event to /v1/talk/{provider}/ctx/{contextId}/event |
CatchAllStatusCallback(c *gin.Context) | Catch-all for unmatched status events |
internal_type.Streamer
| Method | Purpose |
|---|---|
Stream(ctx context.Context) error | Start bidirectional audio loop (blocks until call ends) |
Close() error | Clean up connections |
Existing Implementations as Reference
Study these for real-world examples:| Provider | Directory | Notable Pattern |
|---|---|---|
| Twilio | internal/channel/telephony/internal/twilio/ | JSON envelope, base64 μ-law, TwiML response |
| Vonage | internal/channel/telephony/internal/vonage/ | NCCO JSON response, binary PCM frames |
| Asterisk | internal/channel/telephony/internal/asterisk/ | Two-phase: HTTP webhook + ARI outbound |
| SIP | internal/channel/telephony/internal/sip/ | Direct UDP, RTP media, no provider account |