Possible to use more than one Twilio studio flow with the same phone number? - twilio

I am trying to understand the relationship between phone numbers and studio flows.
Is it one flow per number, so I'd have to pay for a number for each of the flows?
Thanks
Edit: clarification.
Using a pay-as-you-go plan with a deposit and one $1/m phone number.

I need to answer this because the information provided by Twilio support, and my experience, contradict the answer I accepted earlier. Thank you to everyone who attempted to answer this.
My confusion was around the possibility to trigger multiple flows from the same number. This is possible, but the SMS replies to the flow messages drop off unless the flow is initiated from the phone number associated with this specific flow in the console.
So, if I have number-1 and flow-1, I need to associate number-1 with the flow-1 in the number settings. ONLY then will SMS responses to the flow actually go to the flow.
So, the answer to my question is:
Each flow needs its unique phone number, and the number needs to be associated with the flow in the number settings.
This requirement ensures that flows "know" the channel they're on, and will not change as the Twilio Studio moves out of beta.

Indeed in the console, you can only configure one flow for a number. When A MESSAGE COMES IN will trigger the configured flow.
If you have other flows that are not configured with a number, you can pass your Twilio number as from parameter when you trigger the flow via API call. If you don't pass the from number you'll get an error.
Sample Node.js code to trigger the flow via the REST API:
+19993335555 is your Twilio number
const accountSid = 'ACc0966dd96e4d55d26ae72df4d6dc3494';
const authToken = 'your_auth_token';
const TwilioClient = require('twilio')(accountSid, authToken);
TwilioClient.studio
.flows("FW9d816f0b90d2a10b913868462e339d29")
.engagements.create({
to: "+13335557777",
from: "+19993335555"
})
.then(function(engagement) {
console.log(engagement.sid);
});
Docs:
(https://www.twilio.com/docs/studio/user-guide#rest-api)

Related

WebHook in Twilio API

I can't find how to set up or change the Webhook through API.
Is it possible to change it, set it when I am buying a number, or select one Webhook URL for all numbers?
I tried to find this info in the documentation but there was helpful to me
Yes, you can do that with the following command from the CLI:
twilio phone-numbers:update <TWILIO_NUMBER> --voice-url https://xxxxxxxx.ngrok.io --sms-url https://xxxxxxxx.ngrok.io
or with Node
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
client.incomingPhoneNumbers('PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
.update({voiceUrl: 'https://www.your-new-voice-url.com/example'})
.then(incoming_phone_number => console.log(incoming_phone_number.friendlyName));
You can find other snippets in the docs (scroll to "Example 2 Update IncomingPhoneNumber to use a new Voice URL").
PS: If you want to reuse the same configuration for multiple phone numbers, you might want to see whether TwiML Apps can help you too.
You will have to log into your Twilio console.
From the Develop tab, select Phone Numbers, then Manage > Active Numbers.
You can set the default Webhook (and back-up alternate Webhook) by clicking on the desired number and entering it under the respective Phone or (if available) SMS fields. You will likely have to set the Webhook (takes 2 seconds) for each phone number purchased as the default is the Twilio Demo URL (replies back with Hi or something)
The nature of a Webhook should allow any change in functionality to be done externally (on your end) through your Webhook script's functionality and thus dynamically changing the Webhook URL through the API on a case-by-case basis is discouraged and frankly should not be necessary. Someone may correct me if mistaken.

How make a direct phone call to exist between two customers using Twilio API

I have this idea where I need to connect customer A (who is hiring) with customer B (who is to be hired) via a direct phone call with just a push of a button, and customer B (who is to be hired) don't want anyone to just have access to his personal phone number (to avoid spam calls).
Well, to make this work I found out that Twilio can handle programmable voice calls which I implemented using ASP.NET Core but that's not exactly what i wanted because customer A (who is hiring) is not allowed to speak directly with customer B (who is to be hired) while the TwiML is at work.
Using Twilio, is there a way for these two customers to communicate via direct calls while hiding the phone number of customer B (who is to be hired) from customer A (who is hiring)? To throw more light to this, on behalf of customer A I want to place a call to customer B's phone number using Twilio's phone number. Any help will be appreciated, thank you.
Twilio developer evangelist here.
You absolutely can connect two customers via a direct call while hiding customer B's number.
I'll give you the very basics first, then suggest some ways to make it more scalable.
To create a number that A can call that will connect A to B you need to buy that number from Twilio and configure it so that when a call comes in to A it returns TwiML that connects to B. For this initial example, you could use a TwiML Bin or some static TwiML that you host. The TwiML needs to use <Dial> and <Number>, like this:
<Response>
<Dial callerID="YOUR_TWILIO_NUMBER">
<Number>Customer B's phone number</Number>
</Dial>
</Response>
Now, when A calls the number they will get connected to B. And if you set the callerId to your Twilio number it will also appear to B to come from your Twilio number, keeping their phone number private too.
Using hard-coded TwiML like this doesn't scale though. You have a few options to improve this.
First, you could have A initiate the call from your application, by clicking a button. That button could trigger a call to A using the REST API and pass it the TwiML above so that when A answers the phone
it then dials B. Like:
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
class Program
{
static void Main(string[] args)
{
// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");
string twilioNumber = Environment.GetEnvironmentVariable("TWILIO_NUMBER");
TwilioClient.Init(accountSid, authToken);
var call = CallResource.Create(
twiml: new Twilio.Types.Twiml($"<Response><Dial callerId='{twilioNumber}'><Number>CUSTOMER_B_NUMBER</Number></Dial></Response>"),
to: new Twilio.Types.PhoneNumber(CUSTOMER_A_NUMBER),
from: new Twilio.Types.PhoneNumber(twilioNumber)
);
Console.WriteLine(call.Sid);
}
}
Another alternative is to let A call directly from within your application using Twilio Client to make the phone calls from your browser.
To dig a bit deeper, you can also use Twilio Proxy to create a session between the two customers and your Twilio number, creating a connection that would allow either of A or B to call the Twilio number and get connected to the other for the duration of the session. Under the hood Proxy works to automate the delivery of the TwiML described above whilst also maintaining the session between the users until it is done with and the number can be reused by customer A to connect to a new customer. Check out the Proxy quickstart to get a better idea how it works.
Using one of Twilio Proxy or Twilio Client is probably the best for your application, but it depends on the interface you want to provide for your users.

How do I call a number with Twilio Studio flow REST API execution

The purpose is simply to call a number (my number) and have a message start playing.
I have created a Studio Flow like so:
And published that flow.
I've also bought a phone number and it is activated for voice & messaging. I can receive a test voice call with code and using TwiML).
In the settings of my phone number I have the following:
Accept: Voice Calls
Configure with: .. Studio ..
A call comes in: Studio Flow (and selected the correct flow)
I then proceed to use Postman to try and trigger my Flow using a POST request with the following parameters:
And the following body parameters where the To number is my number which is verified in my trial account, and the from is the number i purchased in twilio:
After clicking on Send in postman I receive a 200 OK message, but I am not receiving a call on my phone. What step am I missing?
Twilio developer evangelist here.
The variable you are using as the number to dial out from Studio is {{contact.channel.address}} but the contact variable refers to "data about the current contact engaging with your flow, such as their phone number".
Since you have triggered the flow with a REST API call there is not a contact that is currently engaging with the flow, so this won't give you the number you want.
You are, however, sending in some parameters from your HTTP request from Postman, notably a To parameter. Your data that you send to the flow endpoint like this will be available under the trigger context variable.
So, you should update your widget to use {{trigger.To}} instead (and you probably don't need From, as that is the number associated with the flow, or Body).
Let me know how you get on with that.

App - App Call in Twilio

I had been trying to sort out how can I make an app to app call using Twilio SDK, every time I end up reading the documentation that make me call a Phone number.
Can anyone please guide me towards the right direction ?
I have been following this link for long:
https://www.twilio.com/docs/quickstart/client/ios#gather-twlio-account-information
Twilio developer evangelist here.
With the quick start tutorial that you have been following, there is an example application that can make calls to both phone numbers and to other applications. The key is, instead of setting a phone number when you dial, you can also set another client identity. The quick start server applications for this give the example app a random identity which you can see in the top bar of the app, which you can use in this case.
So, when you type in another client identity, device.connect is called with a dictionary with one key, To, set to the identity (https://github.com/TwilioDevEd/client-quickstart-swift/blob/master/SwiftTwilioClientQuickstart/DialViewController.swift#L165):
connection = device.connect(["To":dialTextField.text!], delegate: self)
This will then be present in the request that Twilio makes to your TwiML app and, taking the Ruby example server as our example here, you can then use this identity to return a TwiML <Dial> to another <Client> (rather than a <Number>).
The key overall is that you set an identity for each of your application users (which is random in the example), you can then call other identities by passing the identity you want to call into device.connect and reading that out of the parameters in Twilio's request to your TwiML application. If you then return TwiML to direct Twilio to <Dial> the <Client> with the identity you sent then an app to app call will be made.
Let me know if that helps at all.

Twilio: Dial extension number along with twilio number

I am using Twilio for inbound calls, where user can call an application through Twilio-Number (brought from Twilio) and will be redirected to admin.
Now, We want Admin to call User using same Twilio-Number. We wabt to call this as <Twilio_Number>#<user_id>. We want to pass <user_id> as extension, so that when Admin clicks on the link with tel=<Twilio_Number>#<user_id>, it will initiate a phone-call to twilio-number.
In our app, we will find user's mobile using his id and redirect call to user's mobile number.
I have referred this doc: https://www.twilio.com/docs/howto/companydirectory
But would need few more details like:
How will Twilio recognize the extension number? And by which name is it provided in call-request parameters?
Currently, we received these parameters in twilio-voice call request
CallSid, AccountSid, ApiVersion, Direction, To, Called, Caller, From. In the same request-parameters, how I can get extension digits?
Thanks.
Have you had the chance to review the IVR information provided on Twilio's site? I believe it is a better solution for what you are trying to accomplish.
https://www.twilio.com/docs/howto/ivrs-the-basics
(Please follow the links to the next section at the bottom of the pages.)
After reviewing the documents, please open a support request with specific questions via https://www.twilio.com/user/account/support/ticket/create
Look forward to your ticket.
Take care!
I don't know if you solved this problem yet (probably yes) but what you can do is, create a record in DB with the extension (id agent) and when Twilio go to your callback url updated the records depending of the state.
Hope this works to you. I'm doing this with the same scenario.

Resources