So a user calls a Twilio phone number. Twilio looks for a voice_url attached to that number (from their dashboard) and sees some XML with instructions on how to handle the call. The XML file also has an "action" parameter that points to a url.
Ideally, this URL should be able to retrieve parameters sent by Twilio and save them to a DB. This is where I'm stuck; how can I see which parameters are sent and how can I save them? I'm assuming the URL in the "action" parameter points to a controller?
I'm using the twilio-rb gem.
Some relevant links:
http://www.twilio.com/docs/api/twiml/dial#attributes-action
http://www.twilio.com/docs/api/twiml/twilio_request
When Twilio makes a POST to the URL mentioned by the Action parameter, it will send all of the attributes mentioned here: http://www.twilio.com/docs/api/twiml/twilio_request.
You should create your own route and controller for responding to the incoming Twilio request. When Twilio makes the request, you should be able to get the variables out of the POST request like any POST request. See for example How to access POST variables in Rails?.
Related
I am using the Call Resource from Twilio API and I need to get the extra parameters I have passed to calls I have made. In my application I pass the extra params with query params such as .../Calls.json?foo=bar. These extra params hold information for the client and such. However when I try to get all the calls from Twilio API through https://api.twilio.com/2010-04-01/Accounts/AC789cf80fc3910717722e21f7714c5b98/Calls.json I get all the calls but there is no trace of these extra params passed to the call. I was able to get some of these params in the Notifications resource where it included the Request URI I made, but the Notifications resource did this only for error messages. What is the way to do something like this? Should I include status callbacks and check for each one manually?
These query parameters are sent to your application, which consumes them. This is how you would access them, not as you found, via the historic /Calls resources logs.
How to Share Information Between Your Applications
Passing Custom Information via Requests to Twilio
I have some issues trying to pass a custom parameter to TwiML Bin. See attached pictures.
Everything works except the paramter.
Any ideas of what I am doing wrong?
Setup:
Twilio developer evangelist here.
ApplicationSID is from TwiML applications which are containers for a set of URLs and configurations that tell Twilio what to do when one of your Twilio numbers receives a call or SMS message.
If you're using dynamic content from custom HTTP request parameters (ie. name in this case), you should take your TwiML bin's URL and pass it the Name parameter like this in, for example, Python, to generate a call with the custom parameters:
client.calls.create(
url="your-twiml-bin-url?Name=Jeremy",
to="your-phone-number",
from_="your-twilio-phone-number")
The documentation Twilio has on their website doesn't contain raw POST bodies, and it has conflicting sources on how the attributes are named/which attributes are included in the body.
Field names and their casing don't match:
https://www.twilio.com/docs/api/twiml/sms/twilio_request#request-parameters
https://www.twilio.com/docs/api/rest/message
Should I expect Message Resource type for all of their POST requests to our URLs(Status Updates and Message Responses) ?
Should I expect only the field names advertised on their Twilio's request page?
Do they provide all parameters or any additional parameters in their request not advertised on the documentation(Twilio's request)
I'm assuming they would also provide "MessageStatus" field in their POST requests, but I don't see it on all documentation pages.
The headers in their requests?
Twilio developer evangelist here.
Of the two pieces of documentation you are referring to there, only one is about the request Twilio makes to you when you receive an SMS message. The other is the Messages resource of the REST API.
So, in answer to your questions:
1) The attributes you receive are the ones described in the request documentation. If you want to confirm this, then I recommend setting your webhook URL to a Request Bin which is an easy way to inspect a webhook request like this. Alternatively, if you are using ngrok to test webhooks locally, then check out the ngrok dashboard which also allows you to inspect (and replay) requests.
2) Yes!
3) There are no extra parameters that I know of.
4) MessageStatus is not included. You can look it up using the Messages resource, but in my experience at the point of receiving the webhook the status is "receiving". Once you are done processing the webhook the status changes to "received".
5) The headers are mostly standard. There are extra ones for security, such as the X-Twilio-Signature header. Again, I recommend inspecting a request with Request Bin or ngrok to fully understand the entire request.
Let me know if this helps at all.
Edit
The Content-Type header for POST requests from Twilio is application/x-www-form-urlencoded.
In a message status callback, the parameters are all the usual parameters plus the MessageSid, a MessageStatus, and if relevant an ErrorCode.
I know in the "Settings > API Integration" I can add a URL that will receive a POST when a Case (Customer Inquiry) is created, however the contents of that POST only contains two IDs e.g. ObjectID=1234567&ObjectType=2001
Is there a way that I can send a custom POST to some URL with the actual form data? E.g. if I wanted to send the person who submitted the form a text message via a third-party SMS API
No; you'll need to respond to that POST with one that extracts the data you need from BC, then transform & forward that data to the SMS service.
This implies that you'll have a third server to handle those intermediary steps.
http://docs.businesscatalyst.com/reference/soap-apis-legacy/crm/case_retrieve.html
Another approach to do this is to write some ajax post function to post form data to the desired URL before submission.
In the twilio web interface, when I look at a specific call, I can see all the associated requests under the request inspector. Is there any way to retrieve this data via the REST API?
Specifically, I'm trying to retrieve the 'Digits' parameter to see what a caller dialed in response to a <gather>
Twilio evangelist here.
There is currently no way to download the entire HTTP request/response using the API. This is something you would have to log yourself as the call is occuring. If you save the call sid at the same time as the Digits, that would allow you to tie those digits back to a specific call.
Hope that helps.