TwilioBase

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file lib/twilio_base. To experiment with that code, run bin/console for an interactive prompt.

TODO: Delete this and the text above, and describe your gem

Installation

Add this line to your application's Gemfile:

gem 'twilio_base'

And then execute:

$ bundle

Or install it yourself as:

$ gem install twilio_base

Migrations

The gem has a migration to create a global config to store the various sids required from a Twilio environment (either an existing environment or one created via the engine). To install the migration in your host app use bin/rails twilio_base:install:migrations and then run migrations as usual.

Protocols & Routing

Consistency in approach is a key goal of this library. Protocols and Routers are designed to facilitate consistency in how we handle outbound voice communications from any application.

Protocols

Protocols allow you to specify sip or pstn as a protocol for initiating outbound voice calls. You can also rely on default if you wish to set a default method for the application as a whole.

PSTN

TwilioBase::Protocols::Voice::Pstn.new(params: {}, to: '+447755747275')

SIP

In order to use SIP, you must specify some SIP Session Border Controller (SBC) settings using the SIP_ENDPOINTS ENV var e.g.

{
 sbc_one: ['[email protected]', '[email protected]'],
 sbc_two: ['[email protected]', '[email protected]']
}
TwilioBase::Protocols::Voice::Sip.new(
  params: {
    sbc_provider: :sbc_one
  },
  to: '+447755747275'
  )

Default

TwilioBase::Protocols::Voice::Default.new(params: {}, to: '+447755747275')

The default will be determined by the VOICE_PROTOCOL ENV var.

Options

Option Details Required
action_url A url, which will receive actions from the outbound call. No
action_url_attributes A hash of attributes to append to the action_url as parameters. No
status_callback_url A url, which will receive callbacks associated with the outbound call. No
timeout The length of time, in seconds, that the call will ring for before timing out. No
sbc_provider The SIP Session Border Controller that you would like a call to deliver to. The protocol will load balance across any endpoints associated with a given SBC. SIP only
sip_endpoint The SIP address that you would like a call to deliver to. SIP only
wait_url A url , which points to an audio file that will be played if the call is put on hold. No

N.B. When using sip you must either specify a valid sbc_provider or a sip_endpoint in the parameters when initialising the protocol.

Routers

Routers allow us to specify a preferred option for routing an outbound call, either by direct dial or task router. A router accepts a Protocol to generate the correct Twiml.

Direct Dial

TwilioBase::Routers::Voice::DirectDial.new(protocol: protocol).route

Task Router

TwilioBase::Routers::Voice::TaskRouter.new(protocol: protocol).route

Default

TwilioBase::Routers::Voice::Default.new(protocol: protocol).route

The default will be determined by the ROUTING_METHOD ENV var.

Testing

The Twilio api is completely represented by a series of fake classes that can be used in your test suite. To enable them to be used in your host app's specs add the following to your rails_helper:

Fakes

Dir[Pathname(Gem::Specification.find_by_name('twilio_base').gem_dir)
  .join('spec', 'support', 'twilio_base', 'fake', '**', '*.rb')]
  .each { |f| require f }

Twilio::REST::Client = TwilioBase::Override::Fake::Clients::Rest

You can then refer to the fake classes in test via TwilioBase::Fake...

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/DVELP/twilio_base. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Code of Conduct

Everyone interacting in the TwilioBase project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.



DVELP
logo

TwilioBase was created and is maintained by DVELP Ltd.