Posts Twilio SMS in Ruby
Post
Cancel

Twilio SMS in Ruby

http://twilioinc.wpengine.com/2016/02/how-to-send-twilio-sms-in-ruby-in-5-minutes.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'sinatra'
require 'twilio-ruby'

post '/receive_sms' do
  content_type 'text/xml'

  response = Twilio::TwiML::Response.new do |r|
    r.Message 'Hey thanks for messaging me!'
  end

  response.to_xml
end

post '/send_sms' do
  # Phone number to send to
  to = params["to"]
  # Message to send
  message = params["body"]

  client = Twilio::REST::Client.new(
    ENV["TWILIO_ACCOUNT_SID"],
    ENV["TWILIO_AUTH_TOKEN"]
  )

  client.messages.create(
    to: to,
    from: "+12155844169",
    body: message
  )
end

origin - http://www.pipiscrew.com/?p=3742 twilio-sms-in-ruby

This post is licensed under CC BY 4.0 by the author.
Contents

Trending Tags