Presented at RailsConf 2007, this presentation introduces the Telegraph plugin for briding Asterisk and Rails.
Telegraph brings the beauty of Rails programming to the VoIP world. It reshapes the mess of the Asterisk API into MVC cleanliness allowing the rapid development of Rails based voice and web applications.
respond_to :voice - the convergence of voice and web interfaces with Rails and Asterisk
1. respond_to :voice
The Convergence of Web and Voice
Interfaces with Rails and Asterisk
or
An introduction to Telegraph - Voice done
MVC
Jonathan Palley
Co-Founder, Idapted Inc.
jpalley@idapted.com
2. VoIP Development Is NOT
about cheaper phone calls
Already done and telcos can do cheaper...
5. The Plan
• Voice as the next Killer Interface
• The Voice/Web Analogy
• Asterisk in 5 minutes
• Telegraph - Bridging Voice and Rails
6. Why add voice? Why
now?
Only Recently Available
Ripe for Innovation
Ubiquitous
7. Lowered Barriers to Voice App
Development
• DB Driven applications (Rails/etc.)
• Phone system (VoIP/OSS PBX)
8. Space To Innovate
• Existing Voice Design Thinking = Phone
Prompt Hell
• Few applications merge voice and web.
Most users do.
• Underlying OSS Servers/Technology
Available
9. Ubiquity
• 2.7 Billion mobile phones. 1.4 Billion fixed-
lines.
• 1/3 of “Internet Users” access the internet
from their mobile phone.
• Each of those 4.1 billion users can be
uniquely identified by a standardized
numerical system
Source: http://communities-dominate.blogs.com/brands/2007/02/mobile_the_7th_.html
10. The Voice/Web Analogy: Technology
Technology Web VoIP
SIP - Ind. Standard
HTTP
IAX - Asterisk only
FTP
Protocol H.323 - Obsolete
RTP
Jingle - Gtalk
etc
Skype - Proprietary
g.711 - high bandwidth
gzip
gsm - medium bandwidth
Codec jpg/gif/etc.
g.729 - low bandwidth
wmv/rm/etc
iLBC - low bandwidth
Server apache/lighttpd asterisk
AGI
Interactivity CGI
AMI
11. Asterisk: The 5min
Tutorial
• OSS Multipurpose PBX
• Very powerful/flexible
• Relatively Stable
• Very messy to deal with
12. Asterisk: Key Concepts
Concept Explanation
Channel A “Channel” in Asterisk is what can setup/receive calls
Determines what to do with call. Given a call and a
dialed number, what sounds should be played, input
Dialplan
received or connections made? Written in a “BASIC like
language.
Stdin/out or TCP method that allows external
AGI
applications to dynamically write dialplans
Method to send commands to Asterisk (independent of
AMI
calls) and listen for stateful events
13. Voice System Setup
SIP/IAX
VoIP
Clients
Rails/
Origination/ SIP/IAX AGI/AMI
Asterisk
PSTN
Telegraph
Termination
Server
Network
Server
Server
Analog
PSTN Zaptel/Other
Interface
Phones/
Cards
Network
14. Existing Ruby/Asterisk
Integration Tools
Just for AGI.
RAGI Not well integrated into rails
Not active.
AMI.
RAMI No Rails Integration.
Not Active.
Active. Real Apps?
Good for writing pure voice apps
Adhearsion Not tied to Rails or concept of shared voice/web
interfaces.
15. Introducing Telegraph
• Extracted from Real Application (Idapted’s
distributed voice system for oral language
training - EnglishQuad) with input of
others.
• Started with RAGI/RAMI
• Tightly Integrated with Rails/Web
Interfaces.
• Embraces the Voice/Web analogy.
16. Telegraph 1: Making Interfaces (AGI)
• Setup Dialplan
exten => 1, 1, AGI(agi://localhost/my_route?param1=value)
• Add respond_to and voice DSL.
wants.voice do
render_voice do |voice|
voice.play “hello-world”
voice.link_to_dtmf 'bank-lineitem-menu' do
link 1, :action=quot;newquot;
link 2, :action=quot;listquot;
link 3, :action=quot;indexquot;
end
end
end
17. Demo I: Adding Voice Interface to Standard Scaffolding
Application.
Look at account controller in demo app. Description/docs at
telegraph.rubyforge.org
18. Sessions can be shared between
voice and web. Making it easy to link
voice and web actions
19. Demo II: Phone Number Confirmation
Look at verify_number controller in demo app. Description/docs at
telegraph.rubyforge.org
20. Telegraph II: Manipulating the System (AMI)
(follows CRUD)
Calls
Create Recordings
Call/Channel/Queue Status
Read Variables
Mailbox
Context
Update Recording
Variable
Call (Hangup)
Delete Recording
21. Telegraph II: Deal with system info
• Create a model-like class:
class VoiceConnection Telegraph::AsteriskManager
end
• Use CRUD technique’s to get Asterisk parameters, place calls, etc. Examples:
VoiceConnection.create(:call, :channel=”SIP/
dave”, :context=”some_context”, :exten=3)
VoiceConnection.destroy(:call, :channel=my_channel)
VoiceConnection.find(:sip_peer, :peer=”SIP/joe”)
VoiceConnection.update
(:monitor, :channel=my_channel, :file=new_file)
22. Demo III: Placing a call and getting channel status
Look at dialer controller in demo app. Description/docs at
telegraph.rubyforge.org
23. Telegraph III: Dealing
with stateful events
• Add a special AMILogic class to your project
• Add methods to deal with events, use params to access info
sent by asterisk.
• For example
class AmiLogic Telegraph::AMIHandler
def link
puts quot;Linked #{params[:channel1]} to #{params[:channel2]}quot;
end
end
25. Easy Deployment/Scaling
• AGI and AMI Events handled by
independent rails processes that can be
load balanced.
• AMI runs through distributed Ruby
process.
• Deployment/daemonization very easy. Like
mongrel, works with Capistrano
26. Questions/Discussion
telegraph.rubyforge.org
talkingruby.org
Thanks To Rabble and John Shulty for their contributions to the source.
Contact Me:
Jonathan Palley
jpalley@idapted.com
skype: jpalley, gizmo: jonathanpalley
idapted.com || englishquad.com
27. Appendix: The Voice/Web
Analogy: Interfaces
Concept Web Voice
Interacting with system Web Browser IVR Like Systems
DB + Voice Connection
Get/set info system Database/Models
Parameters
Handling connections/
Handling Stateful Events - disconnections/
registrations