Class: Lita::Handlers::Twilio
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::Twilio
- Defined in:
- lib/lita/handlers/twilio.rb
Instance Method Summary collapse
Instance Method Details
#receive_sms(request, response) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/lita/handlers/twilio.rb', line 23 def receive_sms(request, response) return unless request.params.delete('token') == config.server_token if request && request.params && !request.params.empty? decoded = MultiJson.load(request.params.keys.first) robot.(target, "Message from #{decoded['From']}: #{decoded['Body']}") end end |
#send_sms(response) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lita/handlers/twilio.rb', line 31 def send_sms(response) begin client = ::Twilio::REST::Client.new(config.account_sid, config.auth_token) if client.account..create(:from => config.phone_number, :to => response.matches[0][0], :body => response.matches[0][1]) robot.(target, "Sent message to #{response.matches[0][0]}") end rescue Exception => e robot.(@target, "Failed to send message: #{e.}") end end |
#target ⇒ Object
19 20 21 |
# File 'lib/lita/handlers/twilio.rb', line 19 def target @target ||= config.default_room end |