The enhanced Twilio API Ruby client
Available methods
Twi::Message
When receiving an incoming direct message via webhook:
= Twi::Message.new params
.id # => 'SM083e290bef7794c407f14e22a891aa6d'
.content # => 'Hello world'
.sender # => '8009007000'
.recipient # => '8008008000'
.wallflower # nil
.opt_in? # false
.opt_out? # false
.image_urls # => ['https://example.com/image.png']
When building a Twilio-like webhook payload:
Twi::Message.params_for id: 'SM12', content: 'Hello', sender: '8009007000', recipient: '8008008000'
# => { MessageSid: 'SM12', Body: 'Hello',From: '+18009007000', To: '+18008008000' }
Twi::Delivery
When receiving a delivery notification via webhook:
delivery = Twi::Delivery.new params
delivery.id # => 'SM083e290bef7794c407f14e22a891aa6d'
delivery.status # => 'draft'
delivery.code # => '30006'
When building a Twilio-like webhook payload:
Twi::Delivery.params_for id: 'SM12', status: 'sent'
# => { SmsSid: 'SM12', MessgeStatus: 'sent', ErrorCode: nil }
Twi::Event
When receiving events about a conversation:
event = Twi::Event.new params
event.id # => 'SM083e290bef7794c407f14e22a891aa6d'
event.conversation_id # => 'CH123'
event.target # => :participant
event.participant # => #<Participant id: 'SH12', phone: '9008009000', identity: nil>
To Do
- have a Rails engine with the webhook URLs already set?
- have an interface to send and receive SMS with photos
- another webhook for conversations
- another one to be notified of deliveries
- Assistant > create a phone number
- have an error code URL for each error code and a sid_url
- Declare some phones like Twilio.homeowner_phone or Twilio.numbers[:ddd] and a default Twilio.number and similar Twilio.messaging_service
- a way to reopen closed conversations
- a way to create conversations
- and upload pictures in a conversation
- x_twilio_webhook_enabled: true
- return SIDs so we can store them
- Set up defaults likw Twi::Lio.sid
- Twi.mock = true