Skip to content

Communication APIs for SMS, Voice, Video and Authentication

Notifications You must be signed in to change notification settings

virtualforce/Twilio_Integration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Twilio Conference Call

In this tutorial we will explore the integration of Twilio to entertain Conference Calls.

Step 1: Twilio Account

Step 2: Add and Install Twilio Gem

Modify your Gemfile to include the Devise gem

gem 'twilio-ruby', '~> 4.11.1'

Then update your gems with

bundle install

Now restart your server to get the changes

Step 3: Manage Twilio Credentials for Different Environments

Create file config/twilio.yml

development:
  from: "Twilio Number"
  sid: "Your ACCOUNT SID"
  token: "Your AUTH TOKEN"
  url: "Ngrok Link to Controller"
staging:
  from: "Twilio Number"
  sid: "Your ACCOUNT SID"
  token: "Your AUTH TOKEN"
  url: "Staging Link to Controller"
production:
  from: "Twilio Number"
  sid: "Your ACCOUNT SID"
  token: "Your AUTH TOKEN"
  url: "Production Link to Controller"

Create file config/initializers/twilio.rb

path = File.join(Rails.root, "config/twilio.yml")
TWILIO = YAML.load(File.read(path))[Rails.env] || {'sid' => '', 'from' => '', 'token' => '','url' => ''}

Step 4: Create Twilio Client

Add following to config/application.rb

config.after_initialize do
      ::TWILIO = Twilio::REST::Client.new(TWILIO_CONFIG['sid'], TWILIO_CONFIG['token'])
end

Step 5: Create Controller twilio_controller.rb

  def call_person
    call=::TWILIO.account.calls.create(
                                       url: "#{TWILIO_CONFIG['url']}/conference.xml",
                                       to: Number To Be Dialed,
                                       from: TWILIO_CONFIG['from'],
                                       status_callback: "Call Back URL",
                                       status_callback_method: "POST",
                                       status_callback_event: ['answered'])
  end

Information about the available attributes can be found here.

Step 6: Add TWIML Response when user has Received Call

File: twilio/conference.xml.erb

  <Response>
  <Say>Welcome Text To Be Played by IVR</Say>
  <Dial timeLimit="Set Time Duration of Call in Seconds">
    <Conference muted= "Used to mute Person on Call" record="record-from-start" startConferenceOnEnter="Start Conference When this User Joins" endConferenceOnExit="End Conference When this Person Leaves" eventCallbackUrl= 'URL where Recording will be posted' >
      @conference_room_no
    </Conference>
  </Dial>
</Response>

Action conference

  def conference
    @conference_room_no = 'Your Conference Room Number'
    // You can create your own instance vars here to be used as attrs in XML Repsonse.
  end

Step 7: Twilio Dial In Functionality (When a Persons Dials Twilio Number from Cell Phone)

  • Open Phone Number Tab.
  • Click on the Phone Number to be used.
  • In the Voice Section add your URL against 'A CALL COMES IN' and make it an HTTP GET Request. This is the URL on which Twilio will redirect user when it receives a call.

Create Response TWIML File in the public folder

  <Response>
    <Gather action="URL Where User Will Be Redirected" method='GET' timeout="60">
      <Say>PLease enter conference room number and then press pound sign</Say>
    </Gather>
    <Say>We didn't receive any input. Goodbye!</Say>
  </Response>

The detail information about the Gather TWIML can be found here.

Step 8: Add Action to Receive User's Input

Action Incoming

 def incoming
    @conference_room_no = params["Digits"]
    render "conference"
 end

Releases

No releases published

Packages

No packages published