-1

In my app, the users see a list of Twilio numbers.

I simply want to give the user the ability to specify a "forward number" for each of these numbers, and my app would call the Twilio API to set this up properly.

I understand that I can give each Twilio number a webhook, which returns TwiML that can facilitate the forward.

But because call forwarding is such a basic feature (the app has no needs to configure anything other than this), I was thinking, Twilio must have something built-in for me so that I don't have to host such a webhook just for call forwarding?

So I looked into the docs and found:

  1. TwiML bins: snippets of TwiML directly hosted in Twilio – but can be created by console only and not API, useless for my scenario.

  2. Twilio Studio: basically their IVR builder. Does seem to have API access. But I only need basic forward and have zero use for call flows etc, so this seems completely overkill?

  3. Twilio function: this appears to be what I want. Twilio hosted functions that do not require self-hosted webhooks. It even has built-in templates for call forwarding in the console. But how do I create and update these programmatically via API so that I can pass in the numbers to forward to? From what I can see in the runtime API, functions can be created/updated with only the basic name/sid properties, so they're essentially empty functions? I do see this FunctionVersionContent API but it seems to be read only?

I'm lost at this point. Is there an API in Twilio I can call to set up basic call forwarding on a Twilio number that's all taken care of on Twilio's side, a feature that is provided to customers of basically any phone service?

thankyoussd
  • 1,875
  • 1
  • 18
  • 39

2 Answers2

2

Twilio developer evangelist here.

There are multiple ways to forward calls with Twilio APIs! And the great thing about APIs is that you can customize the solution to how you wish. I'd recommend looking at setting up call forwarding that references Studio, TwiML Bins, Webhooks, and Functions, this docs page on call forwarding with Studio, this blog post on call forwarding with Studio.

You can update Twilio Functions via the Twilio Serverless Toolkit as well! Let me know if this helps at all!

lizziepika
  • 3,231
  • 1
  • 14
  • 23
  • Sorry those links do not help. Please read my actual post again. I've already read all the docs you linked before I made the post and written down my issue with each one of those approaches. In short: I want to use Twilio API to create a forwarding setup programtically that stays with Twilio without self-hosted webhooks. – thankyoussd Aug 29 '21 at 05:09
  • What do you mean without self-hosted webhooks? Twilio Functions, Studio, and TwiML bins are serverless. – lizziepika Aug 29 '21 at 06:29
0

Figured it out from Twilio support. This can be done via query parameters with TwiML bins or Twilio Functions.

Even though TwilML bins cannot be created/edited with API, each bin has a URL that can be used as a webhook. So defining one bin like this:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial>{{forwardTo}}</Dial>
</Response>

Then update the VoiceUrl to use https://url.to.bin?forwardTo=e164number

This only works if numbers are provisioned in the same account as the TwiML bin. If the numbers are provisioned in subaccounts, we can use public Twilio functions instead.

thankyoussd
  • 1,875
  • 1
  • 18
  • 39