Ruby voip

5,321 views

Published on

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,321
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
48
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Ruby voip

  1. 1. VOIP and Ruby The Convergence of Web and VoiceApplications using Open Source Software Justin Grammens Localtone Interactive justin@localtone.com
  2. 2. VOIP is NOT About Cheap Phone Calls Other companies are already doing this cheaper and better.
  3. 3. VOIP Applications!Its about the applications that we can build!
  4. 4. What We Will Cover➢ Why do VOIP now?➢ Asterisk➢ Adhearsion➢ Telegraph➢ Demos
  5. 5. 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!
  6. 6. Why Now?➢ 2.7 Billion mobile phones. 1.4 Billion fixed-lines.➢ 1/3 of “Internet Users” access the internet fromtheir mobile phone.➢ iPhone has shown consumers why they needthe interactive internet on their phone. Others willfollow.➢Most phone users can be identified by astandardized numerical system.
  7. 7. VOIP / Web AnalogyTechnology Web VOIPProtocol HTTP SIP – Industry Standard FTP IAX – Asterisk Specific RTP H.323 – Obsolete Jingle – Gtalk Skype - ProprietaryCodec gzip, jpg, gif, g.711 – high bandwidth mp3, ogg, wma, gsm – medium bandwidth flv, mpeg, avi g.729 – low bandwidthServer Apache / Lighttpd Asterisk, Freeswitch AGI – Asterisk GatewayInteractivity CGI Interface AMI – Asterisk Manager Interface
  8. 8. Asterisk➢ + Open Source Private Branch Exchange (PBX)➢ + Very powerful and flexible➢ + Relatively Stable➢ - Messy to deal with in terms of extendingfunctionality.➢ +++ Free!
  9. 9. Asterisk : Terminology➢ Channel – A channel is what can setup andreceive calls.➢ Dialplan – Script of what to do with a call. Writtenin the asterisk macro language.➢AGI – Stdin/out TCP method allowing externalapplications to dynamically write dialplans.➢ AMI – Allows sending of commands and listenfor stateful events.
  10. 10. Typical Voice System VOIP Clients SIP Rails Origination/ AGI / / PSTN TerminationNetwork Server SIP / IAX Asterisk AMI Adhearsion Server / Telegraph AnalogPSTN Interface ZaptelNetwork Card / Other
  11. 11. 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 congratulationsexten => 1000,1,Goto(default,s,1)
  12. 12. Difficulties in Asterisk➢ Conditional Loops ➢ Error Handling➢ Complex Data ➢ Date and time Structure handling➢ Database / LDAP ➢ RegEx Pattern Integration Matching➢ Extending the ➢ Variables language ➢ Object Oriented➢ Portability - Asterisk Design v.s Freeswitch, etc.
  13. 13. Ruby / Asterisk Integration Tools➢RAGI – Just for AGI. Not integrated with Rails.No longer active.➢ RAMI – Just for Management Interface. No RailsIntegration. Not Active.➢Adhearsion – Active. Good for writing pure voiceapplications. Not tied with Rails (but can bewithout too much effort).➢Telegraph – Active. Tightly integrated with Rails.Embraces the Voice/Web Analogy.
  14. 14. Adhearsion Standalone server that talks with Asterisk Developed by Jay Phillips of Codemecca Open Source Current version is 0.7.7Development on 0.8 is nearly complete. Lots of new changes.
  15. 15. 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)
  16. 16. Adhearsion - dialplan.rbadhearsion { play %w(press-1 for minneapolis press-2 for chicago orpress-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}
  17. 17. Adhearsion - DemosSIP Phone Adhearsion XLite Asterisk dialplan.rb extensions.conf [ adhearsion ] adhearsion { code.. code.. exten => 8000,1, } Agi(agi://...)
  18. 18. Adhearsion - DemoNotes:Start up Asterisk : sudo asteriskShow asterisk CLI.Start up Adhearsion 0.8 Server :~/development/adhersion/trunk/bin/ahn start .in the rumadhearsion directoryPoint Xlite Phone to Localhost dial extension 8000
  19. 19. Adhearsion – Weather DemoDemo #1 - Weather - Parses data fromYahoo RSS feed <yweather:forecastday="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
  20. 20. Adhearsion – Simon SaysDemo #2 - Play Simon Says Gamedef 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
  21. 21. 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
  22. 22. Adhearsion ● Its abstracted and portable across other PBXes ● Its simple ● Its extensible ● Its readable ● Its maintainable ● Its fun!
  23. 23. Adhearsion Wheres the Rails?Not directly integrated with Rails – by choice.Written to stand on its own, but you can link in your models using ActiveRecord. Looking for VOIP in the MVC framework? Look no further than Telegraph...
  24. 24. TelegraphWritten by a company named Idapted.➢➢Extracted from production application ( Idaptedsdistributed voice system for English languagelearning – EnglishQuad )➢ Started with RAGI / RAMI➢ Tightly Integrated with the Rails/Web Interface➢ They claim it “embraces the Voice/Web analogy”
  25. 25. TelegraphInstalls into any Rails project as a pluginscript/plugin installsvn://rubyforge.org/var/svn/telegraph/trunkstart up the serverscript/agi_server – Interfaces with the gateway(incoming calls)script/ami_server – Interfaces with the Asteriskmanager
  26. 26. Telegraph – Banking DemoSIP Phone Rails XLite Application Asterisk AGI Server
  27. 27. TelegraphAdd 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
  28. 28. Banking Demoindex.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=>indexend
  29. 29. Telegraph - DemoStart up telegraph server :telegraph/banking_demoruby script/asterisk_serverruby script/serverVisit http://localhost:3000/accountDial Extension 9000
  30. 30. Real World Application eStara Offers 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. Well do this.
  31. 31. Demo Topology Cell Phone Origination/ Rails Application Termination Server PSTN Internet Asterisk AGIDemos: AMI1. Using the browser to initiate phone call.2. “Who Wants To Be A Billionaire” game.
  32. 32. Demo – Using PSTN➢Telegraph Demos -➢ Use the browser to initiate a wakeup call.➢ Use the browser to initiate phone calls to 10 digitphone numbers and bridge the calls➢ Use the browser to initiate a call and verifycorrect code was entered.➢Adhearsion Demo -➢ Adhearsion – My “Who Wants To Be ABillionaire” application.
  33. 33. Resourceshttp://rubyhoedown2007.confreaks.com/session03.htmhttp://www.slideshare.net/jpalley/respondto-voice-the-convergence-of-voice-and-web-interfaces-with-rails-and-asteriskhttp://adhearsion.com/http://telegraph.rubyforge.orghttp://www.voip-info.org

×