al telefono con adhearsion e ruby
DESCRIPTION
Hackatron Hangout presentation done on NTRANSCRIPT
![Page 1: Al telefono con Adhearsion e Ruby](https://reader033.vdocuments.net/reader033/viewer/2022052508/559a9e781a28abfb088b463a/html5/thumbnails/1.jpg)
Al telefono con Ruby e Adhearsion
Luca PradoveraHackatron26 Novembre 2013
![Page 2: Al telefono con Adhearsion e Ruby](https://reader033.vdocuments.net/reader033/viewer/2022052508/559a9e781a28abfb088b463a/html5/thumbnails/2.jpg)
• Framework Ruby per applicazioni VoIP
• Componente di logica per le app vocali (3PCC)
• Open source e gestito da una Fondazione
• Versione 2.4.x
• Attivo e rilasciato costantemente
���2
Adh-cosa?
![Page 3: Al telefono con Adhearsion e Ruby](https://reader033.vdocuments.net/reader033/viewer/2022052508/559a9e781a28abfb088b463a/html5/thumbnails/3.jpg)
• Compatibile con Asterisk, FreeSWITCH e… Ruby!
Parliamone (al telefono)!
���3
AMI, IES
SIP WebRTC
HTTP, DRb
![Page 4: Al telefono con Adhearsion e Ruby](https://reader033.vdocuments.net/reader033/viewer/2022052508/559a9e781a28abfb088b463a/html5/thumbnails/4.jpg)
Cos’è una “voice application”• Interagisce con il flusso logico di chiamata
• Gestisce le sorgenti audio, ma non il flusso di media vero e proprio
• Integra i canali di comunicazione ed i servizi a disposizione
���4
Non serve fare così!
![Page 5: Al telefono con Adhearsion e Ruby](https://reader033.vdocuments.net/reader033/viewer/2022052508/559a9e781a28abfb088b463a/html5/thumbnails/5.jpg)
Lista della spesa• Cosa mi serve?
• Adhearsion: gem install adhearsion
• Una piattaforma telefonica (Asterisk o FreeSWITCH): https://github.com/mojolingo/Telephony-Dev-Box
• Un softphone: Jitsi, Blink, X-Lite, e molti altri
���5
![Page 6: Al telefono con Adhearsion e Ruby](https://reader033.vdocuments.net/reader033/viewer/2022052508/559a9e781a28abfb088b463a/html5/thumbnails/6.jpg)
Hello, Adhearsion!• ahn create hackatron
���6
# lib/hello_controller.rb!class HelloController < Adhearsion::CallController!! def run! answer! play "hello-world"! hangup! end!end
![Page 7: Al telefono con Adhearsion e Ruby](https://reader033.vdocuments.net/reader033/viewer/2022052508/559a9e781a28abfb088b463a/html5/thumbnails/7.jpg)
Connettersi ad Asterisk
���7
# config/adhearsion.rb!Adhearsion.config do |config|!! config.development do |dev|! dev.platform.logging.level = :debug! end!! config.punchblock.platform = :asterisk! config.punchblock.username = "manager"! config.punchblock.password = "password"! config.punchblock.host = "asterisk.local-dev.mojolingo.com"!end!!Adhearsion.router do! route 'default', HelloController!end!
![Page 8: Al telefono con Adhearsion e Ruby](https://reader033.vdocuments.net/reader033/viewer/2022052508/559a9e781a28abfb088b463a/html5/thumbnails/8.jpg)
Configurazione• config/adhearsion.rb contiene la configurazione
• rake config:show visualizza nella console i valori attuali e i nomi delle chiavi di ENV
• Se ENV contiene una variabile con quel nome, il suo valore viene sovrascritto, stile 12Factor (http://12factor.net/config)
• Di solito si utilizza un file .env con Foreman
���8
![Page 9: Al telefono con Adhearsion e Ruby](https://reader033.vdocuments.net/reader033/viewer/2022052508/559a9e781a28abfb088b463a/html5/thumbnails/9.jpg)
Se telefonando…• Il metodo consigliato per avviare le applicazioni è Foreman
• foreman start
• Oppure bundle exec ahn start .
���9
{14:14}[2.0.0]~/projects/hackatron ➭ foreman start 14:15:47 ahn.1 | started with pid 35661 14:15:49 ahn.1 | Starting Adhearsion server at /Users/luca/projects/hackatron 14:15:49 ahn.1 | You tried to initialize with an invalid environment name . Valid values are [:production, :development, :staging, :test]. 14:15:49 ahn.1 | [2013-11-26 14:15:49] INFO Adhearsion::Initializer: Setting RAILS_ENV to "development" 14:15:49 ahn.1 | [2013-11-26 14:15:49] DEBUG Punchblock::Connection::Asterisk: Starting up... 14:15:49 ahn.1 | [2013-11-26 14:15:49] INFO Adhearsion::PunchblockPlugin::Initializer: Starting connection to server [2013-11-26 14:15:49] INFO Adhearsion::Console: Launching Adhearsion Console 14:15:51 ahn.1 | [2013-11-26 14:15:51] INFO Adhearsion::PunchblockPlugin::Initializer: Connected to Punchblock server 14:15:51 ahn.1 | [2013-11-26 14:15:51] INFO Adhearsion::Process: Transitioning from booting to running with 0 active calls due to booted event. 14:15:51 ahn.1 | [2013-11-26 14:15:51] INFO Adhearsion::Initializer: Adhearsion v2.4.0 initialized in "development"!
![Page 10: Al telefono con Adhearsion e Ruby](https://reader033.vdocuments.net/reader033/viewer/2022052508/559a9e781a28abfb088b463a/html5/thumbnails/10.jpg)
Demo time!• Connettiamo un softphone alla nostra VM Asterisk usando l’utente SIP
[email protected] e la password “usera”
• Avviamo Adhearsion
• Chiamiamo una extension (numero) qualunque e…
���10
![Page 11: Al telefono con Adhearsion e Ruby](https://reader033.vdocuments.net/reader033/viewer/2022052508/559a9e781a28abfb088b463a/html5/thumbnails/11.jpg)
Cosa mi fornisce?• Menu interattivi con #ask e #menu
• Audio con #play e #speak
• Chiamare altri utenti con #dial
• Funzionalità avanzate: chiamata in uscita (originate), controller di conferma, eventi di chiamata come on_joined e on_end
• Text-to-speech (TTS) e automated speech recognition (ASR) sono supportati secondo gli standard SSML e GRXML se la piattaforma li supporta
���11
![Page 12: Al telefono con Adhearsion e Ruby](https://reader033.vdocuments.net/reader033/viewer/2022052508/559a9e781a28abfb088b463a/html5/thumbnails/12.jpg)
Unit testing• I controller sono normali classi Ruby, testarli con RSpec è semplice
• Fare integration testing è più complesso (SIPp, NuBot)
���12
describe SimonGame do!! let(:example_response) { OpenStruct.new(:response => "5") }! let(:example_number) { "5" }! let(:long_response) { OpenStruct.new(:response => "55555") }! let(:long_number) { "55555" }!! let(:mock_call) { double 'Call' }! subject { SimonGame.new(mock_call) }!! describe "#random_number" do!! before { subject.stub!(:rand).and_return(example_number) }!! it "generates a random number" do! subject.random_number.should eq example_number! end! end!! describe "#update_number" do!! before { subject.number = "123" }! before { subject.stub!(:random_number).and_return "4" }!! it "adds a digit to the end of the number" do! subject.update_number! subject.number.should eq "1234"! end! end!# …!end
![Page 13: Al telefono con Adhearsion e Ruby](https://reader033.vdocuments.net/reader033/viewer/2022052508/559a9e781a28abfb088b463a/html5/thumbnails/13.jpg)
Plugin• I plugin consentono di aggiungere agevolmente funzionalità già realizzate
• http://ahnhub.com/ fa da repository centralizzato
• Alcuni esempi
• Virginia include un server HTTP in Adhearsion
• Matrioska per in-call apps (premo un tasto, eseguo un controller)
• adhearsion-reporter per il supporto ad Airbrake/Errbit e New Relic
• Molto altro! DRb, funzioni specifiche per la piattaforma Asterisk, Voicemail, LDAP, Mongoid…
���13
![Page 14: Al telefono con Adhearsion e Ruby](https://reader033.vdocuments.net/reader033/viewer/2022052508/559a9e781a28abfb088b463a/html5/thumbnails/14.jpg)
Case Studies• Servizio di dettatura con trascrizione e traduzione
• Predictive dialer e call center outbound
• IVR con servizi self-service
• Operatore telefonico virtuale con servizi in-call avanzati
• Servizio di registrazione e sottotitolatura video didattici
• Call center inbound con servizio di segreteria per professionisti
���14
![Page 15: Al telefono con Adhearsion e Ruby](https://reader033.vdocuments.net/reader033/viewer/2022052508/559a9e781a28abfb088b463a/html5/thumbnails/15.jpg)
Riferimenti• http://adhearsion.com/
• @adhearsion su Twitter
• #adhearsion su Freenode IRC
• Mailing list: https://groups.google.com/forum/#!forum/adhearsion
!
• Noi siamo http://mojolingo.com/
• Il mio handle Twitter è @lucaprado
• Github e IRC: polysics
���15
![Page 16: Al telefono con Adhearsion e Ruby](https://reader033.vdocuments.net/reader033/viewer/2022052508/559a9e781a28abfb088b463a/html5/thumbnails/16.jpg)
Grazie a tutti!• http://www.slideshare.net/polysics/al-telefono-con-adhearsion-e-ruby
• https://github.com/polysics/hackatron_ahn_demo
���16
Ridiamo vita alla voce!