Forward a Twilio Call From A Bubble Endpoint

Hi, so I’m trying to build something with Bubble and Twilio and I’m running into a challenge that I did not expect and I was hoping someone could point me in the right direction on how to do what I’m trying to do.

Here’s what I’m trying to do. Note: this is for an internal application in my company.

When a twilio number is called it triggers a webhook which is directed at an endpoint in bubble.

At that endpoint I want to do 2 main things:

  1. Search through our database of customers in Bubble to see if any match the incoming phone number that called our number. (this part works fine. It’s actually very easy to set up).

  2. I want to forward that incoming call through Twilio to call a user. I want that user to be designated by a dynamic value in bubble. The idea is that we have multiple people handling incoming calls throughout the week but only one person at a time. So it would get a value from Bubble for who the “active phone person” is and then respond back to Twilio where to forward the call.

The problem I’m running into is the response back to Twilio. Twilio wants that in XML but bubble responds back in JSON or plain text.

So if put Return Data From API as the first step of my workflow at that endpoint and put the following response in it will read the number but it won’t actually execute the Dial Action in Twilio.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial>415-123-4567</Dial>
</Response>`

If I don’t put any response from the API, Twilio will just say application error.

I wish that I could just respond back with that Dial command and have the number be the dynamic value of the user I want the call directed to. But apparently, it’s not that easy.

What are some ways I can achieve the functionality I’m looking for? Am I missing something obvious? It’s also important to note that I am not trying to trigger a new call, I’m trying to dynamically forward an incoming call to Twilio. I’ve built outbound calling in our bubble app where it calls a number and connects it to the user’s phone number but this is different because I’m dealing with directing an incoming call. I’m trying to essentially use a bubble endpoint like a little switchboard to route the incoming call where it needs to go.

Any help to point me in the right direction is super appreciated!