Class: Twilio::Rails::SMS::Responder
- Inherits:
-
Object
- Object
- Twilio::Rails::SMS::Responder
- Defined in:
- lib/twilio/rails/sms/responder.rb
Overview
The class responsible for pattern matching and delegating how to handle an incoming SMS. Called by Twiml::MessageOperation to generate the body of the response. For a given message it iterates over all registered ‘sms_responders` and replies with the first one that handles, or raises if none are found to handle the message.
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#sms_conversation ⇒ Object
readonly
Returns the value of attribute sms_conversation.
Instance Method Summary collapse
-
#initialize(message) ⇒ Responder
constructor
A new instance of Responder.
-
#respond ⇒ String
Iterates over all registered ‘sms_responders` and replies with the first one that handles, or raises if none are found to handle the message.
Constructor Details
#initialize(message) ⇒ Responder
Returns a new instance of Responder.
13 14 15 16 |
# File 'lib/twilio/rails/sms/responder.rb', line 13 def initialize() @message = @sms_conversation = .sms_conversation end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
11 12 13 |
# File 'lib/twilio/rails/sms/responder.rb', line 11 def @message end |
#sms_conversation ⇒ Object (readonly)
Returns the value of attribute sms_conversation.
11 12 13 |
# File 'lib/twilio/rails/sms/responder.rb', line 11 def sms_conversation @sms_conversation end |
Instance Method Details
#respond ⇒ String
Iterates over all registered ‘sms_responders` and replies with the first one that handles, or raises if none are found to handle the message.
22 23 24 25 26 27 28 29 |
# File 'lib/twilio/rails/sms/responder.rb', line 22 def respond Twilio::Rails.config.sms_responders.all.each do |name, responder_class| responder = responder_class.new() return responder.reply if responder.handle? end raise Twilio::Rails::SMS::InvalidResponderError, "No responder found for message_id=#{ .id } : #{ .body }" end |