Inbound Voice Agent Question
# support
c
Requirement is to have an Agent receive inbound calls and transfer the call based on requirements. We are receiving the call through our Twilio number. However, we are unable to really control the Vapi Voice agent that is receiving the call through our program. Ideally we would like to be able to create the agent on the fly like we an outbound call request. The reason we would like to do that is so we can control all the prompts, transfers etc through our program. It appears that we are only able to control the inbound vapi agent through the dashboard only. Are we understanding this wrong? Please can you help?
v
Hi @chunkey, I'm an AI assistant for Vapi. I'll analyze available sources and get back to you shortly.
----------------------------- **While I generate an answer, here are some sources that might be helpful**: * [Outbound Calling]() * [Dashboard]() * [Inbound Calling]() * [Introduction]() -----------------------------
### Answer You can indeed control the Vapi voice agent programmatically for both outbound and inbound calls. For inbound calls, you need to follow these key steps: 1. **Create an Assistant**: You can dynamically create an assistant using the API. Define the assistant's properties, such as transcriber, model, voice, and functions [(1)]() . 2. **Programmatically Manage Inbound Calls**: Once the assistant is set up, you can manage inbound calls by attaching the assistant to an inbound phone number. This configuration can also be done via the API, not just through the dashboard . 3. **Control Prompts and Transfers**: To control prompts and transfers via your program, you can use the
assistant-request
and
function-call
endpoints. This allows you to handle interactions and transfer logic dynamically [(2)]() , [(3)]() . To illustrate, here's an example of creating an assistant with a specific configuration programmatically:
Copy code
json
{
  "transcriber": {
    "provider": "deepgram"
  },
  "model": {
    "provider": "openai",
    "model": "gpt-4",
    "messages": [
      {
        "role": "system",
        "content": "You're a support assistant for Vapi. Help with customer queries."
      }
    ]
  },
  "voice": {
    "provider": "azure",
    "voiceId": "en-US-JennyNeural"
  },
  "firstMessage": "Hello, how can I assist you today?",
  "recordingEnabled": true
}
[(1)]() , [(3)]() For controlling inbound calls: 1. **Set up a phone number**: Either purchase or import a number using the
Phone Numbers
API. 2. **Attach the Assistant**: Dynamically attach the assistant to handle inbound calls using the
assistant-request
endpoint [(1)]() . If you're seeing issues with connecting the inbound calls through Twilio, ensure the correct JSON response structure is being sent back from your server as it might be causing the assistant to not attach properly [(4)]() .
Got it. Tagging @User for additional help.
s
@User I followed the bot's suggestions exactly, but in our scenario, I need to forward calls to multiple numbers based on specific conditions.
Copy code
When condition X is met, use the transferCall function with this phone number: +1123123123.

When condition Y is met, use the transferCall function with this phone number: +1123123141.
I referred to the call forwarding document https://docs.vapi.ai/call_forwarding. Vapi mentions an option called
forwardingPhoneNumbers
, but I'm unable to implement it in our code. Can you suggest how to use this option?
s
You don’t have to write the code you just send a api request for multiple forwarding numbers that’s it
s
Yeah @Sahil , I need to send an API request but I'm not sure how to use the forwardingPhoneNumbers request field in my API request. Can I get a request (Json request) snippet, please?
@Sahil I solved the issue. Thank you "forwardingPhoneNumbers": [ { "number": "+123456789", "message": "Transfer Message" }, { "number": "+123456666", "message": "Transfer Message" } ]