Twilio action for record - twilio

I'm trying to create a Twilio workflow that places a call and records what the user says. For that I'm using Record, but I'm not entirely sure what to place in the action parameter.
Even though I understand Twilio will send information about the call to that URL, I don't necessarily require it. Is there a way to have some sort of a sinkhole for information?
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say voice="woman">Hi! Say your name:</Say>
<Record method="GET" action="URL_here" timeout="2"/>
</Response>

I don't think there is another option but to create a bin or another endpoint and return an empty response like:
<?xml version="1.0" encoding="UTF-8"?>
<Response />
If you omit the action attribute you'll end up with a loop which is probably not what you're looking for.
The 'action' attribute takes a relative or absolute URL as a value. When recording is finished Twilio will make a GET or POST request to this URL including the parameters below. If no 'action' is provided, will default to requesting the current document's URL.
After making this request, Twilio will continue the current call using the TwiML received in your response. Keep in mind that by default Twilio will re-request the current document's URL, which can lead to unwanted looping behavior if you're not careful. Any TwiML verbs occurring after a are unreachable.
(https://www.twilio.com/docs/voice/twiml/record?code-sample=code-using-attributes-in-a-record-verb&code-language=output-twiml)

Related

Setting dynamic voice attribute inside TwiML Bin from Twilio Studio via TwiML Redirect

I'm trying to use a variable from a Studio Flow to set the type of voice to be used by a gather input interaction generated by a TwiML Bin, but when I attempt to reference the variable as the definition of the voice attribute I get a syntax error. I know that the {{VoiceEnglish}} variable reference works correctly since it will say the correct value if I put it inside of the Say tags, but is there no way to use it for any attributes? Example of what I would like to work is below:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather input="dtmf" timeout="15" numDigits="1" action="https://webhooks.twilio.com/v1/Accounts/[AccountSID]/Flows/[FlowSId}?FlowEvent=return" method="GET">
<Say voice="{{VoiceEnglish}}" language="en-US">English verbiage here</Say>
<Say voice="{{VoiceSpanish}}" language="es-MX">Spanish verbiage here</Say>
</Gather>
</Response>
I think that the TwiML syntax is reported as invalid because it cannot tell that the result of {{VoiceEnglish}} or {{VoiceSpanish}} will be a valid voice.
You are able to to save the TwiML Bin as long as you agree to the modal:
Once you save it, you can use it in your Studio Flow as long as you provide valid VoiceEnglish and VoiceSpanish parameters in the redirect URL.

Twilio Voice API - Use "inline" TwiML instead of XML url when creating outgoing call

I'm using the Twilio Voice API to create an outbound call:
$call = $twilio->calls->create(
"+14155551212", // to
"+15017122661", // from
array(
"url" => "http://demo.twilio.com/docs/voice.xml"
)
);
As you can see, the script used for the call is accessed with the "url" parameter pointing to a XML file.
The XML is hard coded though. Is there a way to write "inline" TwiML inside this create function so I can pass in PHP directly to make the script dynamic? Then I wouldnt be using a hard coded XML file but dynamic PHP instead.
For example, if I have:
$customer_name = $customer['name'];
I'd like to be able to pass this into the script to be read when a listens to the call.
How can I accomplish this?
Twilio developer evangelist here.
There is currently not a way to create a call and directly give it static TwiML to execute.
If you don't want to host static TwiML you could choose to host your TwiML in Twilio's TwiML Bins.
If you want the TwiML to be dynamic, but you don't want to host it yourself, you could use Twilio Functions to respond to your webhook.
Let me know if that helps at all.

Twilio Twimlets - Is there a way to change the voice?

I am using the Twimlet to gather what button the recipient of the call presses. All that is working fine and dandy, but is there a way to change the voice of the Twimlet message to alice?
Her voice sounds much better than the man's and I'd like to use it all the way through my call sessions, instead of having the man's voice just during the twimlet portion.
I know how to do it in TwiML, by adding the voice='alice' parameter, but since Twimlets don't offer that deep of customization, is there any way for me to define it?
You can, but you have to put an 'echo' type of twimlet in front of your 'menu' twimlet. In the 'echo' twimlet, use 'Redirect' after 'Say' to redirect to the url of your 'menu' twimlet.
Code for 'echo' twimlet:
<Response>
<Say voice="alice">Hey. Press a key on your phone.</Say>
<Redirect method="POST">[the url of your menu twimlet]</Redirect>
</Response>
On your 'menu' twimlet leave the message empty.

How to pass parameters in Twilio's outbound calls?

I believe Twilio's outbound call could be HTTP POST request. Is there a way I can pass my custom POST body (json etc) when making outbound voice call request? I'm writing a generic call center where I would like to pass the conversation workflow when making outbound calls so that the code which receives the call knows how to run the conversation. I looked at the documentation (https://www.twilio.com/docs/api/twiml/twilio_request) and looks like we can only pass standard parameters (from, to etc). Thanks for any help.
I believe the only parameter you can customize is the Url Parameter.
Your JSON is pretty much a string (you might have to url encode it and also watch for the length), but you could put it in the query string of the Url Parameter.
?json=url_encoded_json

Twilio Outgoing Call - Twiml url

in the basic Twilio outgoing call, there is one parameter to be set which is the url, like this example:
call = client.calls.create(to="+14085551234", # Any phone number
from_="+12125551234", # Must be a valid Twilio number
url="TwiML-app-url")
Here is the TwiML file that is being passed in my url:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather action="**my-ruby-script**" method="get">
<Say>Please choose a number then press the pound sign</Say>
</Gather>
</Response>
How can I handle the action with a ruby script? The ruby script needs to get the digit that is inputed by the user, then generate a new TwiML response based on that input.
Ricky from Twilio here.
In order to do this you'll want to make sure your ruby script is available via publicly accessible URL. Since you specified GET as the method for your action Twilio will send the digits the user pressed in the query string in the parameter named Digits. Then you can use the Ruby helper library to generate the TwiML you want to respond with.
You didn't mention if you were using a framework so I'll show a snippet using Sinatra but the general idea would apply in other frameworks as well.
require 'twilio-ruby'
require 'sinatra'
get '/process_gather' do
# params['Digits'] <- here is where the button the user pressed will be stored.
# You can do a conditional check here as you see fit.
response = Twilio::TwiML::Response.new do |r|
r.Say 'hello there', voice: 'alice'
end
response.text
end
Hope that helps!

Resources