Reputation: 11
I'm trying to figure out if it's possible to use a single REST request to have Twilio call out to a phone number, and play out a voice message. The content of the voice message will be different each time, so that message would need to be passed as a parameter.
In looking at the Twilio API "Making Calls" doc, I see this curl sample:
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.json \
--data-urlencode "Url=http://demo.twilio.com/docs/voice.xml" \
--data-urlencode "To=+14155551212" \
--data-urlencode "From=+14158675309" \
-u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
This specifies a URL for an XML configuration. For dynamic text, is the expectation that I should publish an xml file to a URL before making the REST call, and then provide that URL in the call? Is there a way to provide the XML as POST data to the end point, rather than using a URL?
Thanks in advance.
gmc
Upvotes: 1
Views: 1202
Reputation: 73075
Twilio developer evangelist here.
You can't include the XML as POST data I'm afraid. However, we do offer TwiML Bins which you can use to host your XML without getting a server of your own. Recently we added support for templating in TwiML Bins. This means that you can pass URL parameters to a TwiML Bin URL and use those parameters in your response.
So, if you are intending to use speech to text to read out a message with <Say>
then you could write the following TwiML as a TwiML Bin:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>{{ Message }}</Say>
</Response>
You'll get a URL that looks like: https://handler.twilio.com/twiml/EHsomerandomcharacters
You can then use that URL in your call creation, with a URL parameter of Message
to read a different message each time.
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.json \
--data-urlencode "Url=https://handler.twilio.com/twiml/EHsomerandomcharacters?Message=Hello+from+your+TwiML+Bin!" \
--data-urlencode "To=+14155551212" \
--data-urlencode "From=+14158675309" \
-u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
Let me know if that helps at all.
Upvotes: 2