Inbound Calls handling (solution suggestion)
# support
u
Hello, Although this is not a specific bug, it is a something that we are struggling to figure out how to solve. We do have a system that we built and we are leveraging VAPI for orchestration of outbound calls, now what happens is that huge amount of calls end up in voicemail and then people call back. We use Twillio for connection and we do have backend logic that connects, Twillio with VAPI and our DB. Now the question is once we get called back Twillio will send us a webhook, we would like to then initiatiate the logic on our end to lookup that number (did we ever called it in the past) and if we did call it then pickup the call (inbound) and have the same assistant handling the conversation. What do you suggest to be the best approach/solution here? Any suggestions? Thanks, Mirko
v
To handle inbound callbacks and route them to the same assistant, set up your Twilio webhook to hit an endpoint that looks up the caller's number in your outbound call logs. If found, respond to Vapi with a dynamic assistant configuration for that user. Here’s a Node.js/Express example:
Copy code
js
app.post("/api/assistant-selector", async (req, res) => {
  if (req.body.message?.type === "assistant-request") {
    const phoneNumber = req.body.call.from.phoneNumber;
    const previousCall = await db.findOutboundCallByNumber(phoneNumber);
    if (previousCall) {
      return res.json({ assistantId: "your_assistant_id" });
    }
    return res.json({ error: "No previous call found." });
  }
});
This ensures returning callers are routed to the correct assistant context automatically. Source: - [Personalization with user information](https://docs.vapi.ai/assistants/personalization)
u
Thanks for the detailed suggestion, that makes sense and aligns with what we’re trying to achieve. Let me explain our situation in more detail so you can see where we’re hitting friction. Our current flow looks like this: 1. Outbound calls: We use VAPI to orchestrate outbound calls. Many end up in voicemail, and people often call us back. 2. Inbound callbacks: Twilio sends us a webhook when a call comes in. At that point, we need to check if the number exists in our DB and map it back to the campaign/assistant that originally placed the outbound call. 3. Campaign/agent design: When a campaign is created, we spin up one agent. On inbound, we check which campaign the caller last belonged to. Then, two possible approaches: a. Update that agent dynamically with an inbound prompt (so the same assistant picks up). b. create two agents upfront when a campaign is created (outbound + inbound). The problem we’re running into is around Twilio + VAPI + SIP routing: 1. We currently use a single SIP number on Twilio, and all inbound calls go through it into VAPI. 2. To decide which assistant should answer, we need to swap the “active agent” behind that SIP based on the DB lookup. But here’s the catch: whenever we update/swap the agent on that SIP, it takes about 30 minutes for the change to propagate. This makes it impossible to do real-time routing to the right assistant. So the core question for us is: How can we dynamically route inbound calls to the correct assistant context without having to wait 30 minutes for a SIP/assistant update?
c
Hi Uros Jovanovic, How can I assist you with your Vapi setup or call handling questions today? If you have any queries regarding integrating Vapi with Twilio for call management or need help with specific configurations, feel free to let me know. You might find useful guidance in [Call Handling with Vapi and Twilio](https://docs.vapi.ai/calls/call-handling-with-vapi-and-twilio).
2 Views