ruby - How do I dynamically generate TwiML from my Rails app? -
i have integrated twilio through twilio-ruby rails app. basic sms , voice capabilities working expected, want extend functionality. able generate twiml in controller dynamically, save somewhere (either locally or service), , have twilio access xml. example, customer makes order through app, twiml generated , saved, , twilio makes voice call supplier new order data. keeping concurrent orders in mind, might solution this? best solution storing twiml/xml , having twilio access it? thank you.
dynamically generating twiml during call seem preferred method.
an example of generating twiml content dynamically docs greet caller name:
https://www.twilio.com/docs/quickstart/ruby/twiml/greet-caller-by-name#twiml-quickstartrb
require 'rubygems' require 'sinatra' require 'twilio-ruby' '/hello-monkey' people = { '+14158675309' => 'curious george', '+14158675310' => 'boots', '+14158675311' => 'virgil', '+14158675312' => 'marcel', } name = people[params['from']] || 'monkey' twilio::twiml::response.new |r| r.say "hello #{name}" end.text end
instead of people
array application have parse incoming message bodies (if using sms) order , make appropriate call supplier.
if however, use case requires creating hosted twiml on fly, twiml bins in twilio console allow interpolation.
that means able like:
curl -x post api.twilio.com/..../calls -d 'url=https://hander.twilio.com/ehxxx?message=hello+world' -u cxxx:yyyy
and twiml bin contain necessary twiml:
<response><say>{{message}}</say></response>
this way, not need make 2 rest calls , wouldn't amass thousands (or more) of redundant bins unwieldy maintain or clean up.
Comments
Post a Comment