Class: Hermes::TwilioProvider
- Defined in:
- lib/providers/twilio/twilio_provider.rb
Instance Attribute Summary
Attributes inherited from Provider
#credentials, #defaults, #deliverer, #weight
Instance Method Summary collapse
Methods inherited from Provider
#initialize, #message_failure, #message_success, #provider_name, required_credentials
Methods included from Extractors
#complex_extract, #extract_from, #extract_html, #extract_text, #extract_to
Constructor Details
This class inherits a constructor from Hermes::Provider
Instance Method Details
#client ⇒ Object
35 36 37 |
# File 'lib/providers/twilio/twilio_provider.rb', line 35 def client Twilio::REST::Client.new(self.credentials[:account_sid], self.credentials[:auth_token]) end |
#payload(rails_message) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/providers/twilio/twilio_provider.rb', line 23 def payload() payload = { to: extract_to().full_number, from: extract_from(), body: extract_text(), } payload[:status_callback] = .twilio_status_callback if .twilio_status_callback return payload end |
#send_message(rails_message) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/providers/twilio/twilio_provider.rb', line 5 def () payload = payload() if self.deliverer.should_deliver? result = self.client.account..create(payload) # set the sid onto the rails message as the message id, used for tracking [:message_id] = result.sid else # rails message still needs a fake sid as if it succeeded [:message_id] = SecureRandom.uuid end self.() rescue Exception => e self.(, e) end |