AgentStream
Programmable Voice APIs with AgentStream
10 min
when you build bot driven voice experiences, reducing perceived latency is critical with exotel legs apis, you can control call legs and media actions in real time this guide explains two recommended approaches approach 1 create a customer leg and immediately start a stream approach 2 create a leg, start a stream, and optionally play a short greeting (say/play) in parallel while the bot connects both flows are supported with existing exotel legs apis prerequisites an exotel account and valid account sid, key and token an exophone configured for outbound calls a grpc endpoint to receive leg events a websocket bot server that supports exotel streaming and events approach 1 create leg + start stream (bot first) this is the simplest flow connect the customer leg, then hand it directly to your bot step 1 create the leg post /v2/accounts/{account sid}/legs content type application/json { "contact uri" "074xxxxx773", "exophone" "0204xxxxx38", "leg event endpoint" "grpc //\<your example endpoint>", "timeout" 30 } you will receive events such as leg connecting, leg ringing, and finally leg answered step 2 start the stream on leg answered, start the stream post /v2/accounts/{account sid}/legs/{leg sid}/actions/start stream content type application/json { "direction" "bidirectional", "url" "wss\ //bot example com/stream", "content type" "audio/x mulaw;rate=8000" } at this point, audio flows between the customer and your bot approach 2 create leg + start stream + say/play (parallel) in many customer facing scenarios, even a 1–2s delay feels like silence to improve perception, you can play a short greeting while the stream session is warming up step 1 create the leg same as approach 1 step 2 start actions in parallel on leg answered, issue two actions start stream post /v2/accounts/{account sid}/legs/{leg sid}/actions/start stream { "direction" "bidirectional", "url" "wss\ //bot example com/stream", "content type" "audio/x mulaw;rate=8000" } start greeting (choose one) say post /v2/accounts/{account sid}/legs/{leg sid}/actions/start say { "text" "hello", "loop" 0 } play post /v2/accounts/{account sid}/legs/{leg sid}/actions/start play { "url" "https //example com/contact center tone wav", "loop" 0 } step 3 stop greeting when the stream is ready as soon as you receive the stream started event, stop the placeholder post /v2/accounts/{account sid}/legs/{leg sid}/actions/stop say or post /v2/accounts/{account sid}/legs/{leg sid}/actions/stop play this ensures the bot audio seamlessly takes over without overlap when to use each approach scenario recommended flow bot first, ivr style journeys approach 1 sales / collections (instant feel) approach 2 contact center simulation approach 2 tech support bot only approach 1 key notes parallelism exotel supports issuing start stream and start say/start play together on the same event greeting length keep placeholder audio short (200–500 ms) so the bot can take over naturally stop timing always stop say/play when you receive stream started next steps get legs apis enabled for your account explore stopsay/stopplay timing to fine tune transitions
🤔
Have a question?
Our knowledgeable support team and an awesome community will get you an answer in a flash.
To ask a question or participate in discussions, you'll need to authenticate first.