How to add TwiML to TwiML Bin via Twilio Api only? - twilio

I am automating many Twilio procedures and want to create a TwiML file and add to a subaccount's twiML bin. Is there any way to work with the the twiML bin via Twilio's api? I have looked at their extensive docs and cannot see anything that would help me. I do not want to use the Twilio console for this task.

There is no API for creating, reading, updating or deleting Twiml Bins. As Levi stated, you will want to use Twilio serverless Functions instead, Functions & Assets (API-only), and/or host the application logic on your side and programmatically update the respective webhooks.
Locally Develop and Debug Twilio Functions in Node.js

Related

How to use Twilio API to create a Twilio Function (or any other Twilio built-in service) that forwards incoming calls?

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:
TwiML bins: snippets of TwiML directly hosted in Twilio – but can be created by console only and not API, useless for my scenario.
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?
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?
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!
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.

Is there a way to create a call script in Twilio without creating many TwiML snippets in separate URLs?

I want to use Twilio to create appointment reminder calls. Each call can have a different call flow with different options for the call recipients to press phone keys, different messages, different languages, etc.
I currently use a service that allows a script to be attached to a call and that script runs on the phone service side so that I don't have to deal with scaling issues when making many thousands of calls at once. I can generate different scripts for each call (or each type of call). I want to switch from that service to Twilio if it's practical.
Since TwiML doesn't have the ability to include logic within a single TwiML file, it seems that in order to do the equivalent would require each call to have many TwiML files. Since I would need each call, or at least each type of call to have different TwiML, I would need to programmatically create each of those files (hosted on Twilio to avoid scaling issues with self-hosting), and somehow manage the many thousands of TwiML files that would remain after each call.
Is there a way to make calls where each call can be attached to a script that incorporates call flow logic?
You can use Twilio Studio or Twilio Functions to do that and more. You can find more information at the respective links. It is pretty straightforward to get started.
Studio (REST API Trigger)
Functions
Function Examples

Twilio Flex stream audio over websocket

I am trying to stream audio when an agent picks up call on a flex dashboard. Although one can start streaming when working with twilio APIs. But I didn't find any docs related to this usecase.
Twilio developer evangelist here.
You can insert the fork stream widget into the Studio flow that leads to a Flex agent?
[edit]
As requested, the media stream should join when the call is accepted by an agent. I don't think you can do this in Studio, so you would have to implement this as a Flex plugin. When the plugin detects that a call has been accepted by an agent it could make a request using the call SID to modify the call and inject the <Start><Stream> TwiML.
I don't have more detail on that right now, as I've not built that sort of thing myself. Let me know if this helps.

Integrating rasa bot with twilio voice

I am trying to build a telephony voicebot using Rasa,I’m just getting started with Rasa, and wondering whether it is possible to integrate rasa bot with twilio voice ,sms is working fine on Programmable SMS .Can anyone please help me how to do this?
We have used 2 different ways to achieve this. As this is for my company, I do not have the right to publish any source code, but this should help you find the way:
1-via Twilio studio, you can just use a block to call a Twilio function and there use "got" npm module (to be addded in Twilio function management tab) to launch a rest API call to you RASA NLU server (or RASA core if you need more than just NLU) and get back the intent(+other info if you want).
2-if you have the possibility to host a backend server (a "middelman"), then you can follow the tutorial at Twilio and expose 4 routes for call controle. In your backend, you will recuperate the utterance(speech) of the gather() function and you can make an API call to your RASA server with it as argument. The backend should contain the logic to react on the intent detected by RASA.
Example (for both solutions) : detected intent is "talk to a manager", then the Twilio command should be a transfer of the call to number xxx. If the detected intent is "talk to accounting department", then you should transfer to number yyy. (jut an example but you see the point).
Twilio has a good tutorial to start with (and a github repo you can clone) .
You can start by having a look at https://www.twilio.com/docs/voice/tutorials/how-to-respond-to-incoming-phone-calls-node-js (sorry I link everyting to nodeJS without knowing what you use, but some other languages are also available).
For me solution 1 is faster and allowed us to start quickly.
Solution 2 is more professional because :
-it gives you more controle (possibility to integrate with DB server, action server, CRM, ...)
-make security people happy by hosting business data inside your own infra (instead of Twilio studio and/or Twilio function.
For info : Twilio has a SOC compliance report - a banking-level security program / if you really need to (and you are ready to pay for it)
-it makes you free and you can replace Twilio, RASA or both when you want.
Nb : Twilio does not really help you a lot in the tutorials as they have their own fully integrated solution (Twilio Autopilot) to integrate NLU and voice call.

Is it like If I am using Twilio Flex, then I only have to customize the UI and build the API from scratch?

If I am using Twilio flex then do I need to build the API from scratch and can customize the UI according to me.
Means can I build API of my own? And I don't need to build my own UI, just customize that which is provided by flex.
Twilio developer evangelist here.
When you are building with Flex you can absolutely add your own endpoints so you can call other services from the UI. I've done this before using Twilio Functions, but as long as the URL can respond to HTTP requests you can host it anywhere.
This is a good way to customise Flex to extend it outside of the Twilio API.

Resources