ruby voip
TRANSCRIPT
![Page 1: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/1.jpg)
VOIP and Ruby
The Convergence of Web and Voice Applications using Open Source Software
Justin GrammensLocaltone [email protected]
![Page 2: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/2.jpg)
VOIP is NOT About Cheap Phone Calls
Other companies are already doing this cheaper and better.
![Page 3: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/3.jpg)
VOIP Applications!
It's about the applications that we can build!
![Page 4: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/4.jpg)
What We Will Cover
➢ Why do VOIP now?
➢ Asterisk
➢ Adhearsion
➢ Telegraph
➢ Demos
![Page 5: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/5.jpg)
Why Now?
Only recently has good Open Source Software been developed ( Rails / Asterisk )
Telecoms are slow to react
Few applications merge voice and web
Cell phone are everywhere!
![Page 6: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/6.jpg)
Why Now?➢ 2.7 Billion mobile phones. 1.4 Billion fixed-lines.
➢ 1/3 of “Internet Users” access the internet from their mobile phone.
➢ iPhone has shown consumers why they need the interactive internet on their phone. Others will follow.
➢ Most phone users can be identified by a standardized numerical system.
![Page 7: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/7.jpg)
VOIP / Web Analogy
Technology Web VOIPProtocol HTTP
FTPRTP
SIP – Industry StandardIAX – Asterisk SpecificH.323 – ObsoleteJingle – GtalkSkype - Proprietary
Codec gzip, jpg, gif,mp3, ogg, wma,flv, mpeg, avi
g.711 – high bandwidthgsm – medium bandwidthg.729 – low bandwidth
Interactivity
Server Apache / Lighttpd Asterisk, Freeswitch
CGIAGI – Asterisk Gateway InterfaceAMI – Asterisk Manager Interface
![Page 8: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/8.jpg)
Asterisk
➢ + Open Source Private Branch Exchange (PBX)
➢ + Very powerful and flexible
➢ + Relatively Stable
➢ - Messy to deal with in terms of extending functionality.
➢ +++ Free!
![Page 9: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/9.jpg)
Asterisk : Terminology➢ Channel – A channel is what can setup and receive calls.
➢ Dialplan – Script of what to do with a call. Written in the asterisk macro language.
➢ AGI – Stdin/out TCP method allowing external applications to dynamically write dialplans.
➢ AMI – Allows sending of commands and listen for stateful events.
![Page 10: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/10.jpg)
Typical Voice System
PSTNNetwork
Origination/Termination
Server
VOIPClients
PSTN Network
AnalogInterface
Card
AsteriskServer
Rails
/
Adhearsion
/
Telegraph
SIP
SIP / IAX
Zaptel/ Other
AGI / AMI
![Page 11: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/11.jpg)
Asterisk Dialplan Language[demo] ; Sample from Asterisk configuration extensions.conf file;; We start with what to do when a call first comes in.;exten => s,1,Wait(1) ; Wait a second, just for funexten => s,n,Answer ; Answer the lineexten => s,n,Set(TIMEOUT(digit)=5) ; Set Digit Timeout to 5 secondsexten => s,n,Set(TIMEOUT(response)=10) ; Set Response Timeout to 10 secondsexten => s,n(restart),BackGround(demo-congrats) ; Play a congratulatory messageexten => s,n(instruct),BackGround(demo-instruct); Play some instructionsexten => s,n,WaitExten ; Wait for an extension to be dialed.
exten => 2,1,BackGround(demo-moreinfo) ; Give some more information.exten => 2,n,Goto(s,instruct)
exten => 3,1,Set(LANGUAGE()=fr) ; Set language to frenchexten => 3,n,Goto(s,restart) ; Start with the congratulations
exten => 1000,1,Goto(default,s,1)
![Page 12: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/12.jpg)
Difficulties in Asterisk
➢ Conditional Loops➢ Complex Data
Structure➢ Database / LDAP
Integration➢ Extending the
language➢ Portability - Asterisk
v.s Freeswitch, etc.
➢ Error Handling➢ Date and time
handling➢ RegEx Pattern
Matching➢ Variables➢ Object Oriented
Design
![Page 13: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/13.jpg)
Ruby / Asterisk Integration Tools➢ RAGI – Just for AGI. Not integrated with Rails. No longer active.
➢ RAMI – Just for Management Interface. No Rails Integration. Not Active.
➢ Adhearsion – Active. Good for writing pure voice applications. Not tied with Rails (but can be without too much effort).
➢ Telegraph – Active. Tightly integrated with Rails. Embraces the Voice/Web Analogy.
![Page 14: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/14.jpg)
Adhearsion
Standalone server that talks with Asterisk
Developed by Jay Phillips of Codemecca
Open Source
Current version is 0.7.7
Development on 0.8 is nearly complete. Lots of new changes.
![Page 15: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/15.jpg)
Adhearsion
Put the line below in extensions.confTells Asterisk to process all calls by our
Adhearsion server
exten => _X.,1,Agi(agi://127.0.0.1)
or... when extension 888 is dialed.
exten => 888,1,Agi(agi://127.0.0.1)
![Page 16: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/16.jpg)
Adhearsion - dialplan.rbadhearsion { play %w(press-1 for minneapolis press-2 for chicago or press-3 for dallas weather otherwise-press 4) selection = input() w = new_weather case selection when '1' then play w.weather_report("Minneapolis, MN") when '2' then play w.weather_report("Chicago, IL") when '3' then play w.weather_report("Dallas, TX") else simon = new_simon_game simon.start end}
![Page 17: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/17.jpg)
Adhearsion - Demos
Asterisk
extensions.conf
[ adhearsion ]
exten => 8000,1,Agi(agi://...)
SIP PhoneXLite Adhearsion
dialplan.rb
adhearsion {code..code..
}
![Page 18: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/18.jpg)
Adhearsion - Demo
Notes:Start up Asterisk : sudo asteriskShow asterisk CLI.
Start up Adhearsion 0.8 Server :~/development/adhersion/trunk/bin/ahn start .in the rumadhearsion directory
Point Xlite Phone to Localhost dial extension 8000
![Page 19: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/19.jpg)
Adhearsion – Weather Demo
Demo #1 - Weather - Parses data from Yahoo RSS feed <yweather:forecast day="Mon" date="31 Dec 2007" low="6" high="19" text="Flurries" code="13" />
rep = %W(weather is-currently #{w.current.temp} degrees today high #{today.high} low #{today.low}) + w.current.desc
![Page 20: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/20.jpg)
Adhearsion – Simon Says
Demo #2 - Play Simon Says Game
def verify_attempt if attempt_correct? call_context.play 'good' else call_context.play %W(#{number.size - 1} times wrong-try-again-smarty) reset end end
![Page 21: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/21.jpg)
Adhearsion
● Write Ruby in our dial plans!
● Ability to use any Ruby gems we need (Active Record, etc.)
● Test and debug our application in isolation.
● Bring OO practices to VOIP development
![Page 22: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/22.jpg)
Adhearsion
● It's abstracted and portable across other PBXes
● It's simple● It's extensible● It's readable● It's maintainable● It's fun!
![Page 23: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/23.jpg)
Adhearsion
Where's the Rails?
Not directly integrated with Rails – by choice. Written to stand on it's own, but you can link in
your models using ActiveRecord.
Looking for VOIP in the MVC framework?Look no further than Telegraph...
![Page 24: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/24.jpg)
Telegraph➢Written by a company named Idapted.
➢Extracted from production application ( Idapted's distributed voice system for English language learning – EnglishQuad )
➢ Started with RAGI / RAMI
➢ Tightly Integrated with the Rails/Web Interface
➢ They claim it “embraces the Voice/Web analogy”
![Page 25: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/25.jpg)
Telegraph
Installs into any Rails project as a plugin
script/plugin install svn://rubyforge.org/var/svn/telegraph/trunk
start up the server
script/agi_server – Interfaces with the gateway (incoming calls)script/ami_server – Interfaces with the Asterisk manager
![Page 26: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/26.jpg)
Telegraph – Banking Demo
Asterisk
SIP PhoneXLite
RailsApplication
AGI Server
![Page 27: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/27.jpg)
Telegraph
Add this to your extensions.confexten => s, n, AGI(agi://localhost/account)
respond_to do |wants| #r index.html wants.html { render } # Telegraph allows render_voice
# which uses the index.voice file wants.voice{ render_voice }end
![Page 28: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/28.jpg)
Banking Demo
index.voice:
voice.play "welcome-to-demo #{say_amount(@balance)}"
voice.link_to_dtmf 'banking-main-menu' do link 1, :action=>'new' link 2, :action=>'list' link :default, :action=>'index'end
![Page 29: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/29.jpg)
Telegraph - Demo
Start up telegraph server : telegraph/banking_demo
ruby script/asterisk_serverruby script/server
Visit http://localhost:3000/account
Dial Extension 9000
![Page 30: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/30.jpg)
Real World Application
eStaraOffers a service where a
user browsing a site can enter their phone number. The system will dial their number, ask the person to hold and then dial customer service.
We'll do this.
![Page 31: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/31.jpg)
Demo Topology
Asterisk
Rails Application
AGI
AMI
CellPhone Origination/
TerminationServer
PSTN Internet
Demos:1. Using the browser to initiate phone call.2. “Who Wants To Be A Billionaire” game.
![Page 32: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/32.jpg)
Demo – Using PSTN➢Telegraph Demos - ➢ Use the browser to initiate a wakeup call.➢ Use the browser to initiate phone calls to 10 digit phone numbers and bridge the calls➢ Use the browser to initiate a call and verify correct code was entered.
➢Adhearsion Demo -➢ Adhearsion – My “Who Wants To Be A Billionaire” application.
![Page 33: Ruby voip](https://reader034.vdocuments.us/reader034/viewer/2022052505/55578007d8b42ad4278b48fc/html5/thumbnails/33.jpg)
Resources
http://rubyhoedown2007.confreaks.com/session03.html
http://www.slideshare.net/jpalley/respondto-voice-the-convergence-of-voice-and-web-interfaces-with-rails-and-asterisk
http://adhearsion.com/
http://telegraph.rubyforge.org
http://www.voip-info.org