Twilio TwiML Say then Play in an incoming call - twilio

I need my app to be able to first say something to an incoming call and then play a recording in loop.
This piece of ruby code used to do what I wanted but it seems like it's not working anymore.
return 200, Twilio::TwiML::VoiceResponse.new do |r|
r.say(voice: 'alice', message: 'Hello World')
r.play(
loop: 0,
url: 'https://my-domain/beep'
)
end.to_s
This code generates the following XML
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say voice="Alice">Hello World</Say>
<Play loop="0">https://my-domain/beep</Play>
</Response>
Alice says what she's supposed to say but the looping test beep is not played. I have verified that my server serves a proper Content-Type: audio/x-wav file for beep.
I'd appreciate any pointers on how to achieve what I'm trying to do.

Respond to Incoming Phone Calls in Ruby
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'sinatra'
require 'twilio-ruby'
post '/voice' do
city = params['FromCity']
# Start our TwiML response
Twilio::TwiML::VoiceResponse.new do |r|
# Use <Say> to give the caller some instructions
r.say("Never gonna give you up #{city}.", voice: 'alice')
r.play(url: 'https://demo.twilio.com/docs/classic.mp3')
end.to_s
end

For future reference, this was caused by Twilio caching the old wav file (which happened to be silent on purpose). Once the cache is refreshed, Twilio now plays the correct sound file.
I hope this helps somebody.

Related

How do I modify a in-progress call by sending a digit with Twilio-Python?

I have an app that makes a outbound call to user A.
User A answers and either says "foo" or "bar"
If User A says "foo" -> c.calls(callSid).update(status="complete")
If User A says "bar" -> twilio.update('press the number 2')
How can I implement this?
I'm using the Python helper library and have tried this.
call = c.calls(callSid).update(twiml="<Play digits='2'/>")
But the app errors out.
In your outbound call use TwiML to ask the user to say "foo" or "bar" and then supply a webhook which can be called to process the response, i.e.:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather input="speech" timeout="5" action="<your webhook>">
<Say>Please say foo or bar.</Say>
</Gather>
</Response>
Twilio will do a POST to the specified webhook in action and the user answer will be stored in SpeechResult along with a confidence score in Confidence. You can then continue with your business logic as you outlined.
For more information on Gather have a look at the TwiML documentation.

Twiml discarding voice, loop in SAY verb inside GATHER

I have an API which first creates a call to a number using the C# wrapper, lets say the receiver is +1000000001
var call = CallResource.Create(new PhoneNumber("+1000000001"),
new PhoneNumber("MYVERIFIEDNUMBER"),
url: new Uri("https://api.com/answered"),
method: HttpMethod.Get,
client: _client,
sendDigits: ""
);
When answered the TWIML returned from https://api.com/answered is
<?xml version="1.0" encoding="utf-8"?>
<Response>
<Gather action="https://api.com/connect/6AE3045C0D024F1896BF7ECFCB2FC40A" method="GET">
<Say voice="alice" loop="0" language="en">Press any key to connect to John Doe, , </Say>
</Gather>
</Response>
This should result in an infinite loop in the voice of "alice" for the SAY verb being repeated to the receiver at +1000000001 but it is a male robotic voice and it only repeats once then drops the call. This is first part of the issue.
The second part is the GATHER verb does nothing. I should be able to press a touch tone phone and have the url https://api.com/connect/6AE3045C0D024F1896BF7ECFCB2FC40A return
<?xml version="1.0" encoding="utf-8"?>
<Response>
<Dial>client:6AE3045C0D024F1896BF7ECFCB2FC40A</Dial>
<Hangup></Hangup>
</Response>
which it does on the GET request but I can never get to it because of the GATHER issue
The third part is does this look correct to dial a client app?
<Dial>client:6AE3045C0D024F1896BF7ECFCB2FC40A</Dial>
Thanks for any advice
Looks like Alice defaults to en-US so you can leave the language attribute off. Also, can you make sure you are returning TwiML with the right MIME type, https://www.twilio.com/docs/voice/twiml#twilio-understands-mime-types.
Client is used inorrectly, refer to the TwiML syntax here, https://www.twilio.com/docs/voice/client/twiml.
Let me know if that addresses the issue.

Twilio autopilot handoff action is not working with Twiml Bin

I have a Twilio autopilot task from an incoming call, which performs a greeting then asks a question before redirecting to a new task called 'callnumber'. This all works fine.
The 'callnumber' task looks like this
{
"actions": [
{
"handoff": {
"channel": "voice",
"uri": "https://handler.twilio.com/twiml/TWIMLBINID"
}
}
]
}
TWIMLBINID actually has the correct ID from the Twiml Bin.
This is the Twiml content in the bin:
<Response>
<Say>I will put you in contact with our customer care specialist.</Say>
</Response>
Unfortunately I'm not hearing this Response spoken out and instead just get the standard 'an error has occurred' voice message.
I've tried a few different versions of this, even calling an xml file hosted on my own public web server and seeing the same problem. Also tried the dial verb and still seeing this issue.
I feel like I may have missed some configuration, after seeing similar posts like: Twilio autopilot doesnt say what it is supposed to say
Any help is much appreciated!
I was able to get the TwiML Bin working with similar JSON, when I have it associated with a Task that has samples.
So, for example, a call comes in to your Autopilot assistant and initially triggers the Assistant Initiation Task of hello_world where you modified the predefined JSON with a listen action.
{
"actions": [
{
"say": "How can I help you today?"
},
{
"listen": true
}
]
}
You then respond so the task associated with your handoff JSON/TwiML Bin is executed (based on the samples you provided). If you try to call the handoff task directly, it fails.
I have the same JSON for "actions" of the task-seems perfect.
But 2 Small differences for the TwiMLbin :
1)don't forget to put the xml tag in the TwiLbin :
It should be :
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>For this question, I will put you in contact ...</Say>
</Response>
2)I don't understand how your twiMLbin has such an hyperlink. Normally the syntax is
https://handler.twilio.com/twiml/******SID******
and the SID can not be chosen and mine has 34 characters. (do not use the "friendly name" of the twiMLbin). You have a button in the twiMLbin to copy-paste it directly.
for me it works. Otherwise please provide some more elements
-do you have queries associated to the autopilot task ? if you have task(s) that do not have any queries, the model will refuse to build (you can check this in the screen "natural language router" / tab "build models").
-are you sure you don't have conflicting query that triggers another task than the one you think (typically with short queries, they "vampirize" other intents). For that please provide the logs of the queries (query Vs Task) of your autopilot assistant.
nb : I confirm what philnash said : you should really try with a phone call. I experienced also some "glitches" with the Twilio simulator.

TwiML If User hang up

I am using the following TwiMl code to record a user over the phone:
<Response>
<Record action="#nextPageUrl" maxLength="15" method="GET" trim="trim-silence" finishOnKey="*" />
</Response>
I would like to do something if the user hang up and not pressed * to end the recording. I am looking for something like ifHangUp:
<Record ifHangUp="#someUrl" action="#nextPageUrl" ....
Does twilio support something like this?
If you look at the twiml documentation page: https://www.twilio.com/docs/api/twiml/record you'll see the request sent after in may include the value "hangup" in the "Digits" parameter for the case where the caller hung up the the "action" set. I believe this should provide you a way of detecting a hangup vs a "*".
Basically, for an implementation have a conditional statement on #nextPageUrl examine the the Digits parameter and use a redirect tag to #someUrl if Digit = 'hangup'

Twilio :making a call

I'm not having much luck making a call via Twilio...
I want a button to click while I'm in the office that puts me through to a clients number that I've typed into a web page.
I can do "Click to call": http://www.twilio.com/docs/howto/click-to-call , but that's for the user to phone the company - what I'm after is my company phone phone to call the user.
I thought it would be a simple case of setting the From/To fields in InitiateOutboundCall, and leaving the URL field blank.
It didn't work at all.
I then tried with an empty XML page, because I thought "When the call connects, I don't want the system to do anything else, like saying a message, I just want the two people to talk!
e.g.:
<?xml version="1.0" encoding="ISO-8859-1"?>
<Response> </Response>
When I do that, the client's phone rings, and it says "Company X" on it, but when the phone is picked up it rings off,
I tried with this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<Response>
<Dial>
<Number>123456</Number>
</Dial>
</Response>
And it called the client's phone, then called the staff's phone - but that's the click-to-call I mentioned above.
Please help!
Protected sub makeCall()
Dim options As New CallOptions()
Dim ACCOUNT_SID = ""
Dim AUTH_TOKEN = ""
options.Url = xxxxxxxxxxxxxxxxxxxx?
options.From = "+Number listed in Twilio callers page"
options.To = "+My mobile number"
WriteLine(""):WriteLine(""):WriteLine("")
Dim TwilClient As New TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
WriteLine("TwilClient created.")
Dim outboundCall = TwilClient.InitiateOutboundCall(options)
WriteLine("Call created.")
WriteLine("Call status: " & outboundCall.Status)
If Not IsNothing(outboundCall.RestException )
WriteLine("ERROR!: " & outboundCall.RestException.Message)
End If
IndentLevel +=1
WriteLine("")
WriteLine("SID: " & outboundCall.Sid)
Session("mycallsid") = outboundCall.Sid
Unindent
End Sub
Twilio evangelist here.
Just to clarify, do you want to make a phone call right from within the browser?
If that's the case, you'll need to use Twilio Client, which has a JavaScript SDK that you can use to create an audio connection from your browser to Twilio. Once thats created, you can tell Twilio to connect to a second number and we will bridge the two calls together.
This quickstart shows you how to use Twilio Client with C# to be able to make and receive phone calls from a browser:
http://www.twilio.com/docs/quickstart/csharp/client
Hope that helps.
Devin

Resources