I am building a phone-number verification app using Twilio. Following this tutorial closely. However, I am unable to generate a valid XML like how this specific page says. How can I fix this?
My main problem is that I am unable to get Twilio to read the TwiML document which I set up in twilio-quickstart.rb. I have run ruby twilio-quickstart.rb and exposed my port using ngrok. On the browser, I can see the words in TwiML tags but in the call, keep getting Application Error. Twilio logs indicate HTTP retrieval failure with this message.
An attempt to retrieve content from
http://adfsfsdf.ngrok.io/hello-monkey returned the HTTP status code
404.
Suspecting an error with the way the XML document is generate (I may be wrong)
In the browser...Instead of getting this...
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>Hello Monkey</Say>
</Response>
I am getting this...
Press 1 to verify your number
Whereas one of the example urls given shows the xml page clearly.
Just to be sure - I have set up my ngrok properly.
How can I generate the XML document properly? Or, how I can overcome the HTTP retrieval error that Twilio logs are showing?
Twilio developer evangelist here.
There are a few things that could be going on here, so I might not be right to start with, but we can work to get this sorted for you.
The error you're getting from Twilio is a 404, meaning that Twilio can't find the URL it's looking for. If you can hit your own endpoint and get a response then there is probably something wrong between you and Twilio.
I'm not sure how you've set ngrok up, but that may be the issue. Everytime you restart ngrok you get a new subdomain, so you may need to update your URL on your Twilio number.
In the case of not seeing the XML in the browser, it's because the quickstart doesn't set the right content type. You can fix that, in Sinatra, by setting the content type, and you'd do so like this:
get '/hello-monkey' do
content_type "text/xml"
Twilio::TwiML::Response.new do |r|
r.Say 'Hello Monkey'
end.text
end
Let me know if this helps at all.
Related
There's a lot going on, but I think I've narrowed it down to something simple. I hope someone can provide any kind of guidance as to what in the world I'm doing wrong.
I've got javascript voice (2.0) working with node.js. I can call inbound and outbound, and I can send a call from a studio flow to a javascript client. This all works. The issue is that when a javascript client user presses "reject" (out of the box example code) or the call isn't answered, it's just dropped. It doesn't return to the studio flow, and I suppose it isn't designed to.
To fix this, I am trying to get the call using the example for client.calls(call sid).update, and I can take the call and issue Say commands and play mp3 files as shown in the example. But when I try to return the call to the studio flow using the webhook url (with or without ?FlowEvent=return appended) it fails. I've tried using the twiml: syntax and providing valid twiml, and I've tried using the url: syntax and providing a url that produces valid redirect twiml (using the echo twimlet).
The URL I'm using is https://webhooks.twilio.com/v1/Accounts/{my_account_sid_here}/Flows/{valid_flow_sid_here}?FlowEvent=return (with and without ?FlowEvent=return at the end)
twiml like this;
<Response><Redirect method="POST">https://webhooks.twilio.com/v1/Accounts/{my_account_sid_here}/Flows/{valid_flow_sid_here}?FlowEvent=return</Redirect></Response> (with and without ?FlowEvent=return at the end)
I'm using the Parent Call Sid (the call sid for the stream never does anything so I assume that isn't the one to use) and the call, when updated, results in a voice message that says "We're sorry, an application error has occurred." I don't know if that is coming from studio or the twilio call processor. If I use the example url with the rick roll mp3 it works.
I've checked the debug messages and they seem to indicate that the flow webhook URL is returning a 400 status code. The documentation says to "To retrieve the Studio Webhook URL in your Studio flow, click the red Trigger widget. The URL starting with https://webhooks.twilio.com/v1/... is the Webhook URL for this Flow" and that's where I got the URL which includes the account sid and flow sid, which I've also checked for correctness.
I'm not sure what to try next.
I've been stuck on this same 400 error for almost a week; if anyone can help I will be thrilled.
In the product I'm working with, there are two APIs. Call one API Joe and the other one Sean. So, Joe the API can already do the thing I'm trying to implement in Sean, which is having a route like /users/:user_guid/:date/files/:file_guid that pulls down files from Ceph. The files are stored in a bucket owned by a third service, but both Joe and Sean have been granted read permission.
So both Joe and Sean are using information in the route to construct a GET request to Ceph. They are also drawing from cephrgw.yml files to get a personalized secret access key for authentication.
The Ceph logs show the two APIs' requests being the same (when I request the same file) except for their personalized secret access key... but Joe gets a 200 and returns the file while Sean gets the mysterious 400 Bad Request without other specification. This led me to believe it was an authentication issue BUT here's the thing: If I comment out Joe's cephrgw.yml file and replace it with Sean's--so now Joe has Sean's secret access key and the GET requests are absolutely identical--Joe still gets a 200.
The logs show no difference between the requests but I'm getting a different result. I'm stumped. What could cause a 400 Bad Request from Ceph that wouldn't influence the GET URL?
Edit: this could be of use too. When I send the request from Sean in postman, I get back a 200 in Sean's logs; rails says everything went just fine since it successfully sent the request. But I get the 400 in Ceph and a weird xml error in postman that looks like this (blanks are names removed):
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>InvalidArgument</Code>
<RequestId>tx000000000000000019efd-006116fe6d-1879_____</RequestId>
<HostId>1879_______</HostId>
</Error>
I'm a very new programmer and am messing around with creating URL's to send SMS or MMS messages via Twilio (my application is for home automation where if my camera detects motions, I want to send a still image to an MMS number via a URL).
Can someone post the format for sample URL for an MMS message that I can paste in a browser?
For example, if I have a To parameter of To=+7145551212 and a From parameter of From=+7145551111 and MediaURL=http://test.com/image.jpg, what would the format of the URL need to be?
I have my Account SID and AuthToken as well. Just need an example of what a completed URL would look like so I can work backwards from there.
Thanks!
Paul
If I'm understanding you correctly, I think it would be this :
https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Messages
And then your parameters need to be in the POST body of the request, like
To=+7145551212&From=+7145551&MediaURL=http://test.com/image.jpg
But Brodan's comment is correct- you can't do this through just pasting a URL into your browser, because it's a POST request. You could use cURL, something like this :
curl --data "To=+7145551212&From=+7145551&MediaURL=http://test.com/image.jpg" https://api.twilio.com/2010-04-01/Accounts/123456/Messages
But your best option would really be to use one of the Twilio helper libraries. Here's a link to their description of the endpoint, they have examples of using those libraries in a variety of languages.
Note : I have never used Twilio myself.
Ahoy!
I installed Twilio in Laravel and ran the code below at the routes (though also I reproduced it at the Controller using this same code in a function)
Now I dont have any issue with namespaces or trying to access the class as it gives no error when using the method against it.
The snippet is as simple as this:
Route::match(array('GET', 'POST'), '/incoming', function()
{
$twiml = new Services_Twilio_Twiml();
$twiml->say('Hello - your app just answered the phone. Neat, eh?', array('voice' => 'alice'));
$response = Response::make($twiml, 200);
$response->header('Content-Type', 'text/xml');
return $response;
});
So I got my phonenumber and went to the Twilio page and added to the URL to which the phone is bound the URL where this snippet is located
sort of www.maweb.con/incoming
I then ring the phone from the kitchen (this shouldn't make a difference lol) and then I get an email error from Twilion saying that when "they" went to that URL to retrieve information and that all they got was an Internal Server error 500.
I stuck my nose into the details of the error and I found this:
<abbr title="Illuminate\Session\TokenMismatchException">TokenMismatchException</abbr> in
I am familiar with that kind of errors, that happens also when you are trying to send a parameter via an Ajax snippet. You need to make an exception at the VerifyToken php file in the Middleware, but I cannot know what the parameter is now, since it must be using the Twiml library and god knows what's in there, it is a blackbox.
I haven't Required the twilio. I just installed it via composer, but like I said, it does recognize the class services_twilio_twlim now. The error is when trying to obtain a response when accessing to that URL.
For a Web not based on a framework I have included:
<?php
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
require_once('twilio-php-master/Services/Twilio.php');
?>
<Response>
<Say>Hello Monkey</Say>
</Response>
So, here is something that I hope will help others when working with Twilio applications:
First of all Twilio is fantastic and I love it but one needs to know how to, of course, as with everything:
You need to know the critical importance between the coding scenarios: you may be working with a PHP framework or you may be coding native PHP and not using any MVC
If you are using Laravel, you will need to import the class by:
use Services_Twilio_Twiml;
and I assumme you have installed the Twilio class through Composer.
if you are not on a Framework just do the old require_once(path to your Twilio.php file) something like Twilio-php-master/Services/Twilio.php
Now, the issue that had me stuck for a while.
Even if you correctly enter the URL at your Twilio page and your telephone is correctly configured to point at it, if you are using Laravel, as Twilio sends its data through POST (by default) the Token Protection against XSS in Laravel will block it by means of the VerifyCSSR Middleware file.
Since you cannot see what values is Posting, you cannot add them to the exceptions and your application will never work.
Therefore, you need to send it via the URL query, that is, change it to HTTP GET.
I am using twilio right now by writing a python script and hosting that with ngrok. When I visit the webpage hosted and view the source, I just see TwiML. Is it possible to just write TwiML w/o code?
Twilio employee here.
Of course you can! If you want to, you can just link the URL to an xml file that you've written and stored on your server - no programmatic generation of the TwiML is required.
One of the simplest ways is to write some plain TwiML on TwiMLbin and just link to the public url for it.
Twilio is just looking for an XML string response to the request it sends - it doesn't care or understand how you generate it.