twilio Message tag not working - message

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}.

Related

Parsing twilio transcription GET request within studio flow?

EDIT: My question is similar to Twilio - Studio - HTTP Request except that the response I get is in xml rather than JSON. So is there a way i can specify a particular xml tag using liquid?
I have designed a studio flow which is as follows
On Incoming call:
Plays message telling caller to leave a voicemail
Records voicemail
Upon hangup, retrieves the transcription of the voicemail using the 'Make HTTP Request' widget using "GET https://user:pass#api.twilio.com/2010-04-01/Accounts/{AccountSid}/Recordings/{RecordingSid}/Transcriptions/ "
Sends that response to a phone number via SMS by putting "{{widget.http_request.body}}" in the message box of the "send_message" widget.
Now I'm so close to that goal however I am having trouble on step 4. I need the response to be turned into just the tag within the xml response. Instead I get the entirety of it which looks like this:
<?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse>
<Transcriptions end="0" firstpageuri="/2010-04-01/Accounts/AC8275ec8e6fb8c37d6b2a5eca99f0dae6/Recordings/RE1595c7b8bc2b8850401ba44fba0dd24d/Transcriptions?PageSize=50&Page=0" nextpageuri="" page="0" pagesize="50" previouspageuri="" start="0" uri="/2010-04-01/Accounts/AC8275ec8e6fb8c37d6b2a5eca99f0dae6/Recordings/RE1595c7b8bc2b8850401ba44fba0dd24d/Transcriptions?PageSize=50&Page=0">
<Transcription>
<Sid>TRbcdfd8fb2fe226ed741b14a05a46cfef</Sid>
<DateCreated>Wed, 17 Aug 2022 19:27:18 +0000</DateCreated>
<DateUpdated>Wed, 17 Aug 2022 19:27:42 +0000</DateUpdated>
<AccountSid>AC8275ec8e6fb8c37d6b2a5eca99f0dae6</AccountSid>
<Status>completed</Status><Type>fast</Type>
<RecordingSid>RE1595c7b8bc2b8850401ba44fba0dd24d</RecordingSid>
<Duration>7</Duration>
<TranscriptionText>Hello. Hello, Hello, Hello, Hello. Hello.</TranscriptionText>
<ApiVersion>2010-04-01</ApiVersion>
<Price/>
<PriceUnit>USD</PriceUnit>
<Uri>/2010-04-01/Accounts/AC8275ec8e6fb8c37d6b2a5eca99f0dae6/Transcriptions/TRbcdfd8fb2fe226ed741b14a05a46cfef</Uri>
</Transcription>
</Transcriptions>
</TwilioResponse>
As you can see, I only need the content between the "TranscriptionText" tags, but currently my HTTP_Request widget returns all of the above. How can I do this within studio? I am trying to keep everything contained in Twilio so any solutions involving outside servers are not desired.
Thank you!
Try adding .json to the end, like below, to get a JSON response Studio can parse.
/2010-04-01/Accounts/{YourAccountSid}/Recordings/{RecordingSid}/Transcriptions.json

How to use action tag with twiml response containing multiple messages

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.

How do I make the endpoint hit from a TwiML redirect in a VoiceResponse return a MessagingResponse?

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.

Where to find CallSid or From when using twiliojs Twilio.Device.connect to dequeue a call?

In my js I am just using:
Twilio.Device.connect({QueueFriendlyName: 'generic'});
The TwiML generated in the app:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
<Queue>
generic
<Queue>
</Dial>
</Response>
I succesfully dequeue a call and connect with the caller.
But in the connect callback handler:
Twilio.Device.connect(function (conn) {
console.log(conn);
console.log(conn.parameters);
});
I can't find anywhere CallSid, From, or any familiar call data, conn.parameters is empty.
Is it normal? Is there anyway to retrieve these information?
Also, is it possible to pass back to the softphone client any data collected with Gather in the TwiML?
It doesn't look like this specifically answers your question, but I ended up here looking for a similar answer (why my parameters weren't being populated), and thought I'd share with the rest of the internet:
On outbound calls, twilio does not populate the connection parameters, that is just for incoming calls.
To get parameters populated on outbound calls, upgrade to at least twilio.js 1.2 -- 1.1 (which is what I was using) does not support parameters for outgoing calls.
(Thanks to skim

Twilio - Dial with Record attribute error

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.

Resources