In this tutorial we will explore the integration of Twilio to entertain Conference Calls.
- Create your account at Twilio.
- After Successful Signup on Home/Dashboard , you will find your Credentials.
- Click on Phone Number Tab and create your first Number.
- Enable Geographic Permission for your Region.
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
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"
path = File.join(Rails.root, "config/twilio.yml")
TWILIO = YAML.load(File.read(path))[Rails.env] || {'sid' => '', 'from' => '', 'token' => '','url' => ''}
config.after_initialize do
::TWILIO = Twilio::REST::Client.new(TWILIO_CONFIG['sid'], TWILIO_CONFIG['token'])
end
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.
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
- 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.
<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.
Action Incoming
def incoming
@conference_room_no = params["Digits"]
render "conference"
end