ruby Twilio Sinatra

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby Twilio Sinatra相关的知识,希望对你有一定的参考价值。

# Need the Sinatra Library to make a web app!
require 'sinatra'

# This is the URL that can be used for the Voice URL on your Twilio Number
post '/messages' do
  content_type 'text/xml'
  "<Response>
    <Message>This is an SMS reply.</Message>
  </Response>"
end

# This is the URL that can be used for the Voice URL on your Twilio Number
post '/voice' do
  content_type 'text/xml'
  "<Response>
    <Say>This is a text-to-speach block.</Say>
    <Play>http://cdn.wawra.co/sw.mp3</Play>
  </Response>"
end
require 'twilio-ruby'

client = Twilio::REST::Client.new "YOUR TWILIO SID", "YOUR TWILIO TOKEN"

# Get a list of messages sent to a given number...
messages = client.account.messages.list to: "YOU TWILIO NUMBER"

# Now print out each message
messages.each do |msg|
  puts "#{msg.from}:   #{msg.body}"
end

# Get all of the phone numbers:
numbers = messages.collect do |msg|
  msg.from
end

# For each number call back using the '/voice' action in the sinatra application.
numbers.each do |num|
  client.account.calls.create(to: num, from: "YOU TWILIO NUMBER", body: "http://server-with-sinatra-app/voice"
end

以上是关于ruby Twilio Sinatra的主要内容,如果未能解决你的问题,请参考以下文章

ruby sinatra_test.rb

ruby Sinatra路线版本.rb

ruby Sinatra演示应用程序 - 比特币价格

在google appengine上部署ruby + sinatra应用程序

Sinatra / Warden / Ruby - 如何确保我的用户只能使用单个会话登录?

ruby 一个示例sinatra omniauth客户端应用程序