I have a very simple question about gathering DTMF inputs from users via an outbound call made to them. I am describing the requirement below.
Main Requirement
I have a python script that makes outbound calls to a particular number. The person accepts the call. I say the information to them via the twiml configured. The person hears the info and presses a key on their phone. I want to capture that key input and just print it as an output using my script.
The problem
I am able to make the outbound call using the client.calls.create method described here. https://www.twilio.com/docs/voice/tutorials/how-to-make-outbound-phone-calls-python
But I am unable to gather the digits. The examples I have seen online are describing how to achieve gathering inputs with a running web application. I am NOT using this method.
I am looking to get this done via a simple script. I initiate the outgoing call from the Twilio number via the script. I don't intend to use any web applications or webhooks here.
I am putting the code below that works until making the call and reciting the options to the user.
How can I get this done? Is this possible? Many thanks.
import os
from twilio.rest import Client
from twilio.twiml.voice_response import Gather, VoiceResponse, Say
account_sid = os.environ['TWILIO_ACCOUNT_SID']='XXXXX'
auth_token = os.environ['TWILIO_AUTH_TOKEN']='YYYYY'
client = Client(account_sid, auth_token)
call = client.calls.create(
twiml='<?xml version="1.0" encoding="UTF-8"?><Response><Gather input="dtmf" timeout="5" numDigits="1"><Say>Please press 1 for sales</Say></Gather></Response>',
to='Destination_Number',
from_='My_Twilio_Number'
)
#TODO - How to Gather Digits from the user????
Twilio developer evangelist here.
There are many ways to interact with a phone call through Twilio, but when you are trying to take user input through <Gather> all of them require Twilio to be able to notify you of the digits that the user pressed. Since this is an asynchronous action, the basic method of doing so is via a webhook, an HTTP request, sent to a web application that you control.
If you do not want to host an application that responds to webhooks yourself, you could achieve this flow using Twilio Studio, which is a drag and drop editor for communications flows, or using Twilio Functions, which is a serverless environment where you can respond to incoming HTTP requests with JavaScript functions.
Related
I'm using the Twilio C# SDK to initiate an outbound call from Twilio, during which user's DTMF input needs to be gathered (Press 1 to be transferred to sales, 2 for support...), and the subsequent action is to forward the call to a designated E164 number that matches the key.
So the VoiceResponse.Gather() method takes this action parameter that is a webhook Uri to which the user input will be posted and we can surely forward the call from there.
var twiml = new VoiceResponse();
twiml.Say("...");
twiml.Gather(numDigits: 1, action: webhookUri);
But is there a way to achieve this simple forward instruction within the current twiml object without involving an external webhook? Basically something that gathers the user input digit, correlates to a E164 number(using a predefined dictionary), then Dial directly.
Twilio developer evangelist here.
No, there is not a way to achieve the instruction after the <Gather> without another webhook. You must pass a URL as the action parameter and respond to the webhook with the next set of TwiML to direct the call onward.
If you do not want to host the application that responds to this webhook yourself, you could achieve this flow using Twilio Studio, which is a drag and drop editor for communications flows, or using Twilio Functions, which is a serverless environment where you can respond to incoming HTTP requests with JavaScript functions.
We are working on a requirement where we are initiating a call from Twilio client SDK [Javascript]. We have an ASP.Net MVC Core application handling incoming Webhook request from Twilio Twiml app. To initiate a call from a client side, we are using Twiml dial verb and providing from and to number. Further our requirement is to send a voice message as soon as an answering machine is detected.
As we have used Dial verb of Twiml, we can't pass detect answering machine and hence can't send voice message. This is by design of Dial verb as it is an attended calling mechanism. After going through a documentation, I have found that, REST API allows to detect and answering machine and also allows sending a voice message. Twilio REST API shall be used for an unattended call initiation and rule based workflow. Twiml Dial verb uses VoiceResponse class to initiate a call whereas Twilio REST API uses CallResource to initiate a call.
I wanted to confirm my understanding before I start working on possible alternatives.
We are thinking of implementing above use case with below steps
Make a Twilio REST API call to initiate an unattnded phone call with answering machine detection option enabled.
If API responds with answered_by value as human or unknown then we will invoke a webhook that shall patch the call using Twiml Dial verb.
If API responds with answered_by value as machine then it shall use a Twiml which contains a voice message that can be sent to callee.
The above is correct. Is there a specific question, however?
Twilio’s Answering Machine Detection Now Generally Available
https://www.twilio.com/blog/answering-machine-detection-generally-available
We have developed an outbound call mechanism using TwiML app and Dial verb using Javascript SDK & ASP.Net Core MVC with Twilio SDK. We came across an issue where we found that answering machine detection and voice message drop is not supported by Dial verb. We are taking a different approach where we will use Twilio REST API to initiate a call. It has a provision to detect an answering machine and respond to an outcome of answering machine detection such as patching an agent or sending a voice message. Further, There are 2 possible configurations and workflows.
MachineDetection:Enable
Possible values for answered_by are machine_start, human, fax or unknown.
1.1 If value is machine_start then we can't send a voice message as it is not waiting for "beep" after which a voice message can be send.
1.2 If value is human then we can invoke a webhook for patching a user into current call.
1.3 If value is fax then we shall not take any action [Out of scope]
1.4 If value is unknown then we may patch a user to take action. This can be a deciding factor for making user productive. More number of requests ending in Unknown shall degrade the desired outcome.
MachineDetection:DetectMessageEnd
Possible values for answered_by are machine_end_beep, machine_end_silence, machine_end_other, human, fax or unknown.
2.1 If value is machine_end_beep then we can use a TwiML url to send a voice message to a callee.
2.2 If value is machine_end_silence then we can use TwiML url to send a voice message to a callee. Such scenarios needs to be handled with this default action and improved over period of time.
2.3 If value is machine_end_other then we can use TwiML url to send a voice message to a callee. Such scenarios needs to be handled with this default action and improved over period of time.
2.4 If value is human then we can invoke a webhook for patching a user into current call.
2.5 If value is fax then we shall not take any action [Out of scope]
2.6 If value is unknown then we may patch a user to take action. This can be a deciding factor for making user productive. More number of requests ending in Unknown shall degrade the desired outcome.
Rerference:
https://www.twilio.com/docs/voice/answering-machine-detection
https://www.twilio.com/docs/voice/answering-machine-detection#webhook-parameters
Based on above workflows we are deciding to use MachineDetection:DetectMessageEnd configuration option. We do have a query regarding point number 2.4. Below is a scenario,
We have made an API request to initiate a call with MachineDetection:DetectMessageEnd configuration. A callee has picked a phone and introduced himself/herself. Twilio has detected a human and set answered_by to human. This has triggered a webhood which as patched a user to current call. It is very much possible that a user who has joined the conference is not aware of who is at other end and can end up asking who is this? This may anoy a callee and affecting overall customer engagement.
This is the scenario shared by our client based on his experience.
I would like to know how fast Twilio can detect "answerd_by"?
Is there a mechanism that can allow a recording of a callee to be played after patching a call so that a user is aware of who is at another end. Is it something Twilio can provide or we need to use the recording feature to do so?
I understand that Twilio has various options to tweak AMD parameters through a Web API however, we may not have enough data to tweak them before the start of the project. We might get there after rolling this feature in production.
Also our client mentioned that sometimes, a voice message is not delivered completely?
Is this something observed by Twilio customers too?
If so what are the best practices to ensure this shouldn't happen?
I have implemented warm transfer in the my application (C#) but I have to extend it.
Below is my new use case:
Customer calls to our Twilio number. That Twilio number is assigned to a department in our database. Based on that number I retrieve all agents in that department. So, I want this call to go to all the agents in that department and all agents can see an incoming call on their screen.
How can I make a call to multiple agents on their 'client id' (they have generated their capability token with)?
PS: I can't use dial because dial is used for conference once agent picks up the call, I have to do something in CallResource.Create() function in C#
Twilio developer evangelist here.
If you can't do this via <Dial>, you need to loop through all the numbers you want to call within your C# code, calling CallResource.Create() for each of them.
Note, you will likely want to setup to receive statusCallback webhooks so that you can complete the other calls if someone has answered.
When i make a call as voice content to that call, can i send a dynamically generated twiml message rather pointing to a URI that contains twiml message ?
If not is there a a workaround to accomplish this , cause I see DIAL and SAY APIs which get used during call response, so would it be possible to make use of those when creating a new call and passing twiml messages using these APIs ?
https://www.twilio.com/docs/api/twiml/dial
https://www.twilio.com/docs/api/twiml/say
Twilio evangelist here.
Its not possible to send TwiML to the REST API. If you don't want to host the TwiML on your own URL there are a few options:
Use TwiML Bins which lets you host relatively static (there is some templating support) TwiML on Twilios servers.
Use Twilio Functions which let you write, store and execute Node on Twilios servers
Use Twilio Studio to define your call flow. A flow in studio can be triggered via an HTTP request to it, so you can take the flows URL and pass it to the REST API when you start your outbound call.
Hope that helps.
Why twilio not provide a hold option as like their mute option?
It doesn't make sense, to use a API to do this option because it just like the mute option except it needs Hold music to be played during for caller.
Any solution? or update?
as for a solution, I would understand that an agent is only dealing with a single call at any one time, so having to place a caller on hold, should be pretty simply, you could simply take the call and place it into a conference where you can play the music of your choice. You could use the agent name perhaps and add hold to it to easily get the agent back to the call in the conference, so perhaps creating a conference in such a way, where the agent name is agent1, the conference name could be agent1hold. Once the agent has finished with that which he was busy with when placing the call on hold in the first place, he could simply dial back into the conference. you would need to make sure that you setup the conference correctly so that if the caller has to be placed on hold again, and the agent exits the conference, that the conference is not terminated.
Megan from Twilio here.
Basic hold functionality can be handled via modifying live calls:
https://www.twilio.com/docs/api/rest/change-call-state
An example in Python where you would use the URL parameter directing the caller to some TwiML to <Play> the caller some hold music. You easily give this a try by hosting the TwiML with Twimlbin.
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient
# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACCOUNT_SID"
auth_token = "AUTH_TOKEN"
client = TwilioRestClient(account_sid, auth_token)
call = client.calls.update("CALL_SID", url="YOUR_TWIMLBIN_URL",
method="POST")
And some examples of working with other scenarios involving <Conference> can be found on our blog.
In Java: https://www.twilio.com/blog/2015/08/how-to-warm-transfer-a-call-with-java-and-twilio-voice.html
In Python: https://www.twilio.com/blog/2015/09/warm-phone-call-transfers-with-python-flask-and-twilio-voice.html