Example: Answering an incoming call
Example: Answering an incoming call
Connect an inbound call to a Grok voice agent
For the complete documentation index, see llms.txt.
Overview
This minimal example answers an inbound call and connects it to the Grok Voice Agent API with only core settings and barge-in support—no extra tools or function calling.
⬇️ Jump to the Full VoxEngine scenario.
Prerequisites
- Set up an inbound entrypoint for the caller:
- Phone number: https://voximplant.com/docs/getting-started/basic-concepts/phone-numbers
- WhatsApp: https://voximplant.com/docs/guides/integrations/whatsapp
- SIP user / SIP registration: https://voximplant.com/docs/guides/calls/sip
- App user: https://voximplant.com/docs/getting-started/basic-concepts/users (see also https://voximplant.com/docs/guides/calls/scenarios#how-to-call-a-voximplant-user)
- Create a routing rule that points the destination (phone number / WhatsApp / SIP username / app user alias) to this scenario: https://voximplant.com/docs/getting-started/basic-concepts/routing-rules
- Store your Grok API key in
ApplicationStorageunderXAI_API_KEY.
Architecture
Usage highlights
- Create a
VoiceAgentAPIClientwithGrok.createVoiceAgentAPIClient(...). - Configure the session with
voice,turn_detection, and a shortinstructionsprompt. - Bridge audio with
VoxEngine.sendMediaBetween(call, client). - Enable barge-in by clearing the media buffer when the caller starts speaking.
Turn detection & barge-in
When InputAudioBufferSpeechStarted fires, clear the media buffer so the caller can interrupt the agent:
Configure before you run
- Set
XAI_API_KEYinApplicationStorage. - Adjust the
SYSTEM_PROMPTin the example to match your brand voice and guardrails.
Try it
Suggested test prompts:
- “Hello”
- “What can you help me with?”
- “Goodbye.”
Notes
See the VoxEngine API Reference for more details.
Full VoxEngine scenario
voxeengine-grok-answer-incoming-call.js