I'm using the twimlbin service to test a simple bit of Twilio xml:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>This call may be recorded for quality purposes</Say>
<Dial record="true" action="http://testmyapp.ca/sendmail.php" method="GET">
555-404-3200
</Dial>
</Response>
At the action url I receive the url of the recording and the duration and send an email to myself. All goes well, the email is sent, but the voice on the phone says an application error has occurred. The error is a 12100 error (http://www.twilio.com/docs/errors/12100). From the debugger service I get "Error on line 1 of document : Premature end of file. Please ensure that the response body is a valid XML document." I'm not doing anything but sending an email from my php file - should I be returning a response to Twilio here from my php file? I've commented out any output from sendmail.php I receive the email with the GET parameters I expect but the voice still says an application error has occurred. Any help much appreciated.
It sounds like when Twilio makes a request to your action URL, your response doesn't contain any TwiML. If the call is to continue, you should add some Twiml - possibly just a <Hangup>, or even an empty <Response/> should do. See the documentation for <Dial> on Twilio's website.
I had this same problem and here is how I solved it. Just add this header to your mail.php file:
<?php
/**
* This section ensures that Twilio gets a response.
*/
header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<Response></Response>'; //Place the desired response (if any) here.
That's it. No need to place a response. After that header, comes the section that sends the email.
I read somewhere that you need a Hangup response. No need for that.
Also, I should mention my mail.php file ended with a line like this
echo '</Response>';
I just deleted that line. It was unnecessary.
I hope this helps anybody else running into the same problem.
Related
I am listening to incoming call on one of my endpoints and trying to generate a twilio response to forward that email to few other phone numbers. I also want to have action tag configured for each of this messages. My xml looks something like this -->
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Message action="https://test-5411.twil.io/test-log" to="+1831273xxxx" from="+1516407xxxx">
Hello 1!
</Message>
<Message action="https://test-5411.twil.io/test-log" to="+1831555xxxx" from="+1516407xxxx">
Hello 2!
</Message>
<Message action="https://test-5411.twil.io/test-log" to="+1831444xxxx" from="+1516407xxxx">
Hello 3!
</Message>
</Response>
Twilio docs say that -
There are certain situations when the TwiML interpreter may not reach verbs in a TwiML document because control flow has passed to a different document. This usually happens when a verb's 'action' attribute is set.
I think I am running into this exact situation. In my case, only the first phone number receives the SMS and the other 2 don't. Is there a workaround for this ?
Twilio developer evangelist here.
I had a play around with this and in this case you are right that using an action will mean that the subsequent <Message>s won't ever be reached. I also tried putting further <Message> elements in the response to the webhook to the action, but that didn't work either.
So the workaround here is to use the REST API to send the messages instead of using TwiML.
I have a situation where I want a TwiML VoiceResponse to call another endpoint which returns a MessagingResponse. However, I am getting an XML Validation warning for the MessagingResponse because of what I suspect is a mismatch in the inbound type (a call) and the outbound type (an SMS).
Please note that there is a requirement that I cannot use the Twilio client as suggested here https://support.twilio.com/hc/en-us/articles/360017437774-Combining-Voice-SMS-and-Fax-TwiML-in-the-Same-Response. I would like to achieve this with pure TwiML.
I have a call webhook set up on my Twilio phone number which hits a POST /call endpoint on my NodeJS server. The endpoint responds with TwiML which plays a tone and calls a redirect to another endpoint on my server.
TwiML returned:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Play digits="www9"/>
<Redirect method="POST">[url-omitted]/notify</Redirect>
</Response>
Then, on the same server I have a second POST /notify endpoint which let's say, for simplicity, sends an SMS to a specific number.
TwiML returned from redirect endpoint:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Message to="+11234567890">Hello world!</Message>
</Response>
Expected Result
The expected result is that when I call the Twilio number from my cellphone, I hear the "9" tone and then receive a text message with "Hello world!".
Actual Result
I only hear the "9" tone and never receive a text message.
When I look in the Twilio console, I can see that a call was made to the POST /notify endpoint, and it responded with the expected TwiML, but it has a 12200 - Schema validation warning.
Msg "XML Validation warning"
line "2"
parserMessage " Invalid content was found starting with element 'Message'. One of '{Play"
ErrorCode "12200"
cols "32"
LogLevel "WARN"
url "https://handler.twilio.com/twiml/[id-omitted]"
As noted, I suspect the above error message is because this all originated from a call and not an SMS.
Twilio developer evangelist here.
The <Message> TwiML verb is only usable during messaging flows, which is why you got the schema validation warning.
You can use the deprecated <Sms> verb to send messages during voice calls, however I don't recommend this as it uses the old messaging API and doesn't handle things like unicode or messages longer than 160 characters.
Instead, I recommend you use the Messages REST API to send messages during the call.
I use statuscallbackurl to get the call details and post to another system. documentation says we can get the recording url from RecordingUrl the posted parameters.
But I do not get this url. My response xml is below. Let me know how to get the recording url.
Thanks.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial action="url" callerId="+19999999999" timeout="15" sequential="true" record="true">
<Number>+19999999999</Number>
</Dial>
</Response>
Twilio evangelist here.
I believe that the recording URL will only be sent to the URL you've specified in the action parameter.
From the docs:
"...a RecordingUrl parameter will be sent to the 'action' URL on the associated verb. You must set an 'action' URL to receive the RecordingUrl."
I see that you've specified the action parameter. Are you saying that the RecordingUrl parameter is not included in the request to that URL?
Hope that helps.
I'm trying to setup a simple call forwarding app using twiml only.
The process flow I'm trying to accomplish is;
Call twilio #
say prompt to ask for the phone number to dial
dial to that phone number
Reading the documentation it looks fairly simply to gather the number;
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather action=“this is where the dial action goes” timeout="10" finishOnKey="*">
<Say>Please enter the phone number and press *.</Say>
</Gather>
</Response>
This should simply enough ask for a phone number, and log it as digits.
Next up the process should be to use dial to dial those digits, but that's where I'm a little lost. I've used dial several times, but not sure how to chain these two together.
<?xml version=”1.0″ encoding=”UTF-8″?>
<Response>
<Dial>
"the digits passed from gather"
</Number>
</Dial>
</Response>
Ideally I think it makes sense the dial command goes into the action="" section of the gather, but I'm not sure if that's doable.
Any ideas on where to go from here?
Your response needs to include the opening tag for Number...
<?xml version=”1.0″ encoding=”UTF-8″?>
<Response>
<Dial>
<Number>
*digits*
</Number>
</Dial>
</Response>
https://www.twilio.com/docs/api/twiml/number
To connect the original Say/Gather response to the generated response, you need to specify a callback action, while I think you may be able to specify an XML file (making sure to set the method to GET instead of the default POST), but I don't believe xml has the ability to use a passed parameter. You need to use php or something that can be passed the digits (with PHP it's like this):
<?php
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<Response><Dial><Number>$_REQUEST['Digits']</Number></Dial></Response>";
?>
https://www.twilio.com/docs/api/twiml/gather
The digits that were pressed are sent in a POST request to the action of the Gather tag.
So:
<Gather action="/someotherpage.aspx">....</Gather>
On the someotherpage.aspx the Request.Form["Digits"] will have the value they entered.
Why is this failing?
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Message>
<Body>Store Location: 123 Easy St.</Body>
<Media>https://demo.twilio.com/owl.png</Media>
</Message>
</Response>
I am receiving the following error:
Warning: 12200 - Schema validation warning
Parse error found on line 1 of the Raw Response
https://www.twilio.com/user/account/log/calls/CA7920533e98ffed29426d29e7e27746c8
I did a diff with the original example, and it's EXACTLY the same!
Original example is listed here:
https://www.twilio.com/docs/api/twiml/sms/message
I looks like you are building your application with Twilio as a Voice call application instead a SMS Message application.
The url https://www.twilio.com/user/account/log/calls/CA7920533e98ffed29426d29e7e27746c8 suggested that you are accesing your application as a voice call application, if not it would be https://www.twilio.com/user/account/log/messages/{some other id}.