Project

twi

0.0
A long-lived project that still receives updates
Enhances OpenSSL::HMAC with timestamp.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

 Project Readme

The enhanced Twilio API Ruby client

Available methods

Twi::Message

When receiving an incoming direct message via webhook:

message = Twi::Message.new params
message.id # => 'SM083e290bef7794c407f14e22a891aa6d'
message.content # => 'Hello world'
message.sender # => '8009007000'
message.recipient # => '8008008000'
message.wallflower # nil
message.opt_in? # false
message.opt_out? # false
message.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>

Twi::Phone

To create an incoming phone number:

phone = Twi.create_phone area_code:, friendly_name:
phone.id # => 'SM083e290bef7794c407f14e65a891aa6d'
phone.number # => '5556667777'

Available mocks

Use these methods to mock request to Twilio when testing an app:

Credentials

Mock an error when creating an incoming phone number:

Jbr.mock.phone_error = { code: '21452' }

Mock successfully creating an incoming phone number:

Jbr.mock.phone = { id: 'SM083e290bef7794c407f14e65a891aa6d', number: '8009005000' }

To Do

  1. have an interface to send and receive SMS with photos
  2. have an error code URL for each error code and a sid_url
  3. Declare some phones like Twilio.homeowner_phone or Twilio.numbers[:ddd] and a default Twilio.number and similar Twilio.messaging_service
  4. a way to reopen closed conversations
  5. a way to create conversations
  6. and upload pictures in a conversation
  7. x_twilio_webhook_enabled: true