Creating Communication Applications using the Asterisk ... · Creating Communication Applications...
Transcript of Creating Communication Applications using the Asterisk ... · Creating Communication Applications...
![Page 1: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/1.jpg)
Creating Communication Applications using the Asterisk RESTful Interface
API Strategy & Practice 2017, Portland Oregon Chris Howard, Digium
![Page 2: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/2.jpg)
Who am I?
ChrisHoward• DigiumTrainingManager• #2373• [email protected]• @cch_123• https://www.linkedin.com/in/christopher-c-howard
![Page 3: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/3.jpg)
Background
Digium–DeveloperProductsTrainingmanager.AsteriaSolutionsGroup–DirectorofSoftwareDevelopmentNortel/Architel/MetaSolv–SeniorConsultantTeledyneBrown/EERSystems–Programmer(Adayay!)
![Page 4: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/4.jpg)
Introduction to Asterisk
![Page 5: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/5.jpg)
Introduction to Asterisk
• What is Asterisk? • What can Asterisk do? • Who is Digium?
![Page 6: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/6.jpg)
What is Asterisk?
Open Source Communications Platform • Asterisk is
– software that turns an ordinary computer into a communications server
![Page 7: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/7.jpg)
Asterisk Use Cases
• Traditional PBX
• VoIP only PBX
• Hybrid PBX
• VoIP Gateway
• Feature Server
• Call Center
• Carrier Platform
• WebRTC Server
![Page 8: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/8.jpg)
Asterisk History
2014
– A
ster
isk
13
2008
– A
ster
isk
1.6.
0 20
09 –
Ast
eris
k 1.
6.1
2009
– A
ster
isk
1.6.
2
2010
– A
ster
isk
1.8
2011
– A
ster
isk
10
1999
– A
ster
isk
0.1
2004
– A
ster
isk
1.0
2005
– A
ster
isk
1.2
2006
– A
ster
isk
1.4
Vers
ion
Time
2012
– A
ster
isk
11
2013
– A
ster
isk
12
2016
– A
ster
isk
14
2017
– A
ster
isk
15
![Page 9: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/9.jpg)
Asterisk Characteristics • Very mature code base for a teenager
– Over 17 years old – Enterprise-class reliability and performance
• Global Community – Over 1 Million production servers
• Dual License – Open source - GPLv2 – Commercial OEM
• Supported – Community support – Commercial open source support available
![Page 10: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/10.jpg)
Obligatory first application
Open Source Communications Platform
WebServer CommunicationsServer
<html> <head>Hello</head> <body> <h1>Hello World!</h1> </body> </html>
exten => 100,1,Answer() same => n,Wait(1) same => n,Playback(hello-world) same => n,Hangup()
![Page 11: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/11.jpg)
Who is Digium?
• “The Asterisk Company” • Mark Spencer • 2 Fold Mission
– Open Source – Commercial
• 200+ employees • Headquartered in Huntsville, AL • Atlanta, San Diego
![Page 12: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/12.jpg)
Business Lines
• Digium has 2 primary business lines – Business Communications Systems – Custom Communications Solutions
• And a wholly owned subsidiary, Digium Cloud Services
12
![Page 13: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/13.jpg)
Business Products
SwitchvoxHardwarePBX
SwitchvoxMobileApps
SwitchvoxCloud
SIPTrunking
SwithvoxSwitchboard
![Page 14: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/14.jpg)
Developer Products
CoursesAsteriskEssentials(online)AsteriskFastStartAsteriskAdvancedAsteriskAPIsforDevelopersCertificationsdCAAdCAP
TrainingSupport
SubscriptionsBusinessHourSupport24/7oncallwarrantysupport
https://www.respoke.io/
Hardware Platforms
![Page 15: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/15.jpg)
Asterisk APIs History
![Page 16: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/16.jpg)
Asterisk RESTFul Interface (ARI) Overview
WhenAsteriskwasfirstcreatedbackin1999,itsdesignwasfocusedonbeingastand-alonePrivateBrancheXchange(PBX)thatyoucouldconfigureviastaticconfigurationfiles.Whilethislevelofconfigurationissufficientformanyapplications,forsomedomains,itisfarmorepreferabletomanipulateAsteriskviaanexternalsystem.So,notlongintotheproject,twoAPIswereaddedtoAsterisk:theAsteriskGatewayInterface(AGI)andtheAsteriskManagerInterface(AMI).
AsteriskAPIHistory
![Page 17: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/17.jpg)
ARI Overview
TheAGIandAMIinterfacesarepowerfulandopenedupawiderangeofintegrationpossibilitiesfordevelopingAsteriskbasedappsandintegratingAsteriskwithothersystems.
• UsingAGI,remotedialplanexecutioncouldbeenabledwhichalloweddeveloperstocontrolchannelsinAsteriskusingPHP,Python,Java,andotherlanguages.
• WithAMI,thestateofAsteriskcouldbedisplayed,callsinitiated,andthelocationofchannelscontrolled.UsingbothAPIstogether,complexapplicationsusingAsteriskastheenginecouldbedeveloped.
AsteriskAPIHistory(continued)
![Page 18: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/18.jpg)
The AGI Dialplan App
YouwillneedtocreateanextensionthatcallstheAGIdialplanapplication.
[internal] exten => 301,1,NoOp(Hello World) same => n,Answer() same => n,AGI(hello-world.pl) same => n,Hangup()
TheAGIapplicationhandsoffcallcontroltotheprogramspecifiedintheargument.(defaultlocation/var/lib/asterisk/agi-bin/)
![Page 19: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/19.jpg)
AGI Execution Flow
AsteriskAsterisk DialplanDialplan AGI
Channel
Start
Noop
Answer
AGI– hello_world.pl
StreamFilehello_world
AGITerminates
Hangup
Streamhello_world
Hangup
![Page 20: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/20.jpg)
AGI Demo
• Showhello-world.plscript.
• TurnonAGIDebug.
• Placecalltohello-worldAGIextension.
![Page 21: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/21.jpg)
Asterisk Manager Interface
[root@localhost ~]# nc 127.0.0.1 5038 Asterisk Call Manager/3.2.0 Action: Login Username: test Secret: mysecret Response: Success Message: Authentication accepted
![Page 22: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/22.jpg)
Asterisk Manager Interface – Originate Action
Action: Originate Channel: PJSIP/7001 Context: astricon Exten: 7002 Priority: 1 Response: Success Message: Originate successfully queued
![Page 23: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/23.jpg)
Asterisk Manager Interface – Events
Event: DeviceStateChange Privilege: call,all Device: PJSIP/7001 State: INUSE
![Page 24: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/24.jpg)
AMI Demo
• LogintoAMI
• IssueOriginateCommand
• Displayeventsfiredfromoriginate
![Page 25: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/25.jpg)
AGI/AMI Libraries and Frameworks
Name Language Website APIsAdhearsion Ruby http://www.adhearsion.com/ AMI/FastAGI
Asterisk-Java Java https://asterisk-java.org/ AMI/FastAGI
PAGI PHP http://marcelog.github.io/PAGI/ AGI
PAMI PHP http://marcelog.github.io/PAMI/ AMI
PHPAGI PHP http://phpagi.sourceforge.net/ AGI/FastAGI
Panoramisk Python https://github.com/gawel/panoramisk AMI/FastAGI
Pyst2 Python https://github.com/rdegges/pyst2 AMI/AGI
StarPy Python https://github.com/asterisk/starpy AMI/FastAGI
Nanoagi C++ https://sourceforge.net/projects/nanoagi/ AGI
AsteriNET .NET(C#/VB) https://github.com/AsterNET/AsterNET AMI/FastAGI
Ding-Dong Node.js https://www.npmjs.com/package/ding-dong FastAGI
AGI/AMILibrariesandFrameworks
![Page 26: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/26.jpg)
Asterisk RESTful Interface (ARI) Overview
![Page 27: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/27.jpg)
ARI Overview
WhileAMIisgoodatcallcontrolandeventmonitoringandAGIisgoodatallowingaremoteprocesstoexecutedialplanapplications,neitheroftheseAPIsweredesignedtoletadeveloperbuildtheirowncustomcommunicationsapplication.
AsteriskAPIHistory–ARIRational
![Page 28: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/28.jpg)
ARI Overview
NeitherAPIexposesthekindsofcommunicationsprimitivesthatexistinAsteriskneededtoeasilybuildsuchanapplication.Thatwasn’ttheirintendedpurpose.
So,theAsteriskDeveloperCommunitysetouttobuildabetterAPIthatwouldmakeiteasiertobuildcustomcommunicationsapplications.ARIwastheresultofthiseffort.
AsteriskAPIHistory–ARIRational(continued)
![Page 29: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/29.jpg)
The Asterisk RESTfull Interface (ARI)
![Page 30: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/30.jpg)
ARI Overview
• ARIisaRESTinterfaceallowsapplicationdeveloperstobuildrich,customcommunicationsapplicationsinthelanguageoftheirchoice.
• ARIexposestherawprimitiveobjectsinAsterisknormallyreservedforCmodules—channels,bridges,endpoints,media,etc.—throughanintuitiveRESTinterface.
• Asanasynchronousinterface,ARIconveysthestateoftheobjectsbeingcontrolledbytheuserviaJSONeventsoveraWebSocket.
WhatistheAsteriskRESTfulInterface(ARI)
![Page 31: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/31.jpg)
ARI Overview
• Thewebsocketinterfacethatlistensforevents.
• TheRESTinterfacewhereyoucansendcommandsandreceiveresponses.
ARIconsistof2“parts”.Thisisanimportantconcepttoremember.Thereare2distinctinterfacesthatmakeupARI.
![Page 32: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/32.jpg)
AGI vs. AMI vs. ARI
ARIisnotareplacementforAMIorAGI.
• AGIallowsyoutocontroldialplanexecutionofachannel.• AMIallowsyoutomanagecallsatahighlevel.
• ARIallowsyoutoreplacedialplanapplicationswithyourowncustomcommunicationsapplication.
ARIisnotabouttellingachanneltoexecutetheVoiceMaildialplanapplicationorredirectingachannelinthedialplantoaVoiceMailextension.
ItisaboutlettingyoubuildyourownVoiceMailapplication.
![Page 33: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/33.jpg)
ARI Quick Start Guide
1.EnabletheAsteriskHTTPserviceinhttp.conf:[general]enabled = yesbindaddr = 0.0.0.0
2.ConfigureanARIuserinari.conf:
[general]enabled = yes pretty = yes [asterisk]type = userread_only = nopassword = asterisk
![Page 34: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/34.jpg)
The Stasis Dialplan App
YouwillneedtocreateanextensionthatcallstheStasisdialplanapplication.
[internal] exten => 403,1,NoOp() same => n,Answer() same => n,Stasis(hello-world) same => n,Hangup()
StasisisthemechanismthatAsteriskusestohandcontrolofachanneloverfromthedialplan-whichisthetraditionalwayinwhichchannelsarecontrolled-toARIandtheclient.
![Page 35: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/35.jpg)
Websock Connection
Nowwewillneedtosetupawebsocketconnectiontoasteriskindicatingthatwearethehello-worldapplication.wscat -c "ws://192.168.1.100:8088/ari/events?api_key=admin:digium&app=hello-world"
Wecanusethewscatapplicationtoconnecttoasterisk,identifyourselfandsaywearetheapp-helloworld.
InthecaseofARI,aWebSocketconnectionisusedtopassasynchronouseventsfromAsterisktotheclient.
TheseeventsarerelatedtotheRESTfulinterface,butaretechnicallyindependentofit.TheyallowAsterisktoinformtheclientofchangesinresourcestatethatmayoccurbecauseofandinconjunctionwiththechangesmadebytheclientthroughARI.
![Page 36: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/36.jpg)
The ARI Websock Session
WhenyoucalltheextensionoftheStasisapplicationyouwillseeaStasisStartmessageinyourwscatsection.Notethe“id:”attribute.Wewillusethattoissuecommandstothecall.
{ "type": "StasisStart", "timestamp": "2017-04-05T11:04:14.869-0700", "args": [], "channel": { "id": "1491415454.6", "name": "PJSIP/302-00000003", "state": "Up", "caller": { "name": "302", "number": "302" }, "connected": { "name": "", "number": "" },x "accountcode": "", "dialplan": { "context": "internal", "exten": "401", "priority": 3 }, "creationtime": "2017-04-05T11:04:14.714-0700", "language": "en" }, "application": "hello-world"}
![Page 37: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/37.jpg)
ARI Request/Response NowthatthechannelisintheStasisapplicationwecansendRESTrequesttoit.Thefollowingisanexampleusingcurl.curl -v -u apitest:mysecret -X POST "http://192.168.1.100:8088/ari/channels/1491415454.6/play?media=sound:hello-world"
NotethatthechannelidneedstomatchtheideintheStrasisStartmessage.Theresponsewillbesimilartothefollowing:{ "id": "adb889f4-6dba-404c-b8f1-743b32a2c0fc", "media_uri": "sound:hello-world", "target_uri": "channel:1491415454.6", "language": "en", "state": "queued"* Connection #0 to host 192.168.101.50 left intact}
![Page 38: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/38.jpg)
The ARI Websock Session After Request
ThewebsocketsessionwillshoweventthatweregeneratedbasedontheARIrequest.
< { "type": "PlaybackStarted", "playback": { "target_uri": "channel:1491415454.6", "media_uri": "sound:hello-world", "id": "6455cfc1-3714-4584-90b2-3133f8cd1d4f", "state": "playing", "language": "en" }, "application": "hello-world"}< { "type": "PlaybackFinished", "playback": { "target_uri": "channel:1491415454.6", "media_uri": "sound:hello-world", "id": "6455cfc1-3714-4584-90b2-3133f8cd1d4f", "state": "done", "language": "en" }, "application": "hello-world"}
![Page 39: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/39.jpg)
AMI Demo
• CreateStasisExtension• Usewscattomonitorevents• Sendhello-worldsoundtothechannelfromtheevent
ARIDemo
![Page 40: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/40.jpg)
ARI REST Resource Categories
• Asterisk• endpoints• channels• bridges• recordings• sounds
• playbacks• deviceStates• Mailboxes• events• applications
![Page 41: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/41.jpg)
ARI Swagger Specification
The REST API that makes up ARI is documented using Swagger, a lightweight specification for documenting RESTful API's. The swagger specifications are located in the rest-api/api-docs directory of the Asterisk distribution.
![Page 42: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/42.jpg)
ARI Swagger Specification
![Page 43: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/43.jpg)
ARI Applications
• Thewebsocketinterfacethatlistensforevents.• TheRESTinterfacewhereyoucansendcommandsand
receiveresponses.
ThepreviousdemoshowedthearchitectureoftheAsteriskRESTfullinterfaceandanexampleofusingthe“2channel”approach.
Youcanusethese2channelstocreateanAsteriskApplicationhoweveritisratherdifficultkeepingupwiththewebsocketeventsandcontrollinganactivesystem.
![Page 44: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/44.jpg)
ARI Applications
TheAnswer… ARIFrameworks!
OneofthebeautifulthingsaboutARIisthatit'ssoeasytojustbangoutarequest.Howeveryoudon’twanttolotsofdirectHTTPcallsthroughoutyourapplicationandhowdoyoukeepupwithalloftheeventsthatyouarerespondingto…
![Page 45: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/45.jpg)
ARI Frameworks
ARIFrameworksareanabstractionlayerfortherawARIcalls.TheabstractionlayersallowforlanguagenativefunctionsandeventhandlersthathandlealloftheunderlyingARIeventsandActions.MostframeworkswerebuiltfromtheARIswaggerspec.
![Page 46: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/46.jpg)
Available ARI Frameworks
Library Language Resourceari-py Python https://github.com/asterisk/ari-py AsterNET.ARI C# / .NET https://github.com/skrusty/AsterNET.ARI ari4java Java https://github.com/l3nz/ari4java node-ari-client NodeJS https://github.com/asterisk/node-ari-client phpari PHP http://www.phpari.org/ Phparia PHP http://phparia.org/ asterisk-ari-client Ruby https://github.com/svoboda-jan/asterisk-ari
![Page 47: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/47.jpg)
ARI Frameworks
Note:Forthissessionwearegoingtofocusonusingthenode-ari-clientframework.Let’srevisitthehello-worldsamplethatwebuiltusingwscatandcurlbutnowusingthenode-ari-clientframework.
![Page 48: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/48.jpg)
ARI Frameworks – hello-world.js
![Page 49: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/49.jpg)
AMI Demo
• Showthehello-world.jsapplication• StarttheNodeApp.• Dial403tohearthesound.
ARIFrameworkDemo
![Page 50: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/50.jpg)
ARI Application
Let’slookatcreatingacommunicationapplicationlikeaconferencebridge.Nowforafewquickrequirements:• Unlimitedparticipants• Press1mutesself• Press2unmutesself• Press3releasesamonkeytothebridge• Press4removesallmonkeysfrombridge
![Page 51: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/51.jpg)
ARI Application – Create/Add Channel to Bridge Thefirstthingweneedtodowhenawestartthe“ariconf”ARIapplicationistocreateabridge.var client = require('ari-client'); client.connect( 'http://192.168.1.100:8088', 'admin', 'digium', function(err, ari) {
var bridge = ari.Bridge(); bridge.create({ type: 'mixing,dtmf_events', name: 'ariconf’ }); ari.start('ariconf'); }
)
![Page 52: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/52.jpg)
ARI Application – Cleanup Bridges Note:Bridgesdon’tdiewhenARIscriptdies.function cleanupBridges() {
ari.bridges.list( function(err, bridges) { var ariconfBridges = bridges.filter( function(candidate) { return candidate['name'] === 'ariconf'; } ); ariconfBridges.forEach( function(bridge) { bridge.destroy(function(err) {}); }); } );
}
![Page 53: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/53.jpg)
ARI Application – Add New Channels to the Bridge
Nowthattheapplicationhasstartedandwehaveabridgecreatedwewillwanttoaddanynewchannelthatentersthe‘ariconf’Stasisapplicationtothebridge.Thiswillbehandledinthe“StasisStart”event.Firstweneedtofindthebridgeandthenweaddthechanneltothebridge.
![Page 54: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/54.jpg)
ARI Application – Add Channel to Bridge
function joinBridge(channel) { ari.bridges.list( function(err, bridges) { var bridge = bridges.filter( function(candidate) { return candidate['name'] === ‘ariconf’; } )[0]; if (!bridge) { console.log("bridge not found!"); } else { bridge.addChannel({channel: channel.id}); } );
}
![Page 55: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/55.jpg)
ARI Application – Add Channel to Bridge
ari.on( 'StasisStart’, function(event, incomingChannel) { incomingChannel.answer (
function(err) { joinBridge(incomingChannel, "ariconf"); } ); }
);
NowcallthejoinBridgefunctionfromthe“StasisStart”event
![Page 56: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/56.jpg)
ARI Application – Handle DTMF
SonowthatwehaveaConferenceBridgeapplicationthatcanhandlemultiplecallswewanttoaddafewfeaturesthataretriggeredbyDTMFkeypresses.Thisisdoneusingthe“ChannelDtmfReceived”events.
![Page 57: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/57.jpg)
ARI Application – DTMF Events
incoming.on( 'ChannelDtmfReceived', function(dtmfEvent, channel) { const digit = dtmfEvent.digit; switch (digit) { case '1': setMute(channel); break; case '2': setUnmute(channel) break; default: console.log('Unknown DTMF digit: %s', digit); } }
);
![Page 58: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/58.jpg)
ARI Application – Create/Add Channel to Bridge Thecodeforthemute/unmuteisprettysimple.
function setMute(channel) { ari.channels.mute({ channelId: channel.id, direction: 'in’ });
} function setUnmute(channel) {
ari.channels.unmute({ channelId: channel.id, direction: 'in’ });
}
![Page 59: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/59.jpg)
ARI Application – Monkey Time
NowthatwehavethebasicDTMFhandlersinplacewecanaddmorefunctionality.Whenthecallerpresses3wewilladdascreamingmonkeytothebridge.Wewillusetheoriginatecommandtoimplementthis.Firstoriginateacalltothebridgeandwhenthebridgeanswerswewillconnecttheothersidetosomedialplanthatplaysthett-monkeyssoundfile.
![Page 60: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/60.jpg)
ARI Application – Monkeys Dialplan
Thedialplanforthett-monkeysplayback
[monkeys] exten => monkeys,1,Noop(playback tt-monkeys) same => n,Playback(tt-monkeys) same => n,Hangup()
![Page 61: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/61.jpg)
ARI Application – Add Monkey to Bridge
function originateMonkey(channel) { ari.channels.originate({ endpoint: 'Local/' + channel.dialplan.exten + '@astricon', context: 'monkeys', extension: 'monkeys', priority: "1", variables: { "__monkey": "true” } });
}
WeoriginatetotheconferencebridgeusingaLocalchannel.Oncethebridgeanswerswesendittothemionkeysdialplantopaybackthett-monkeyssound.
Note:wesetachannelvariablecalledmonkey
![Page 62: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/62.jpg)
ARI Application – Kick the Monkey
Nowsincewehaveawaytoaddmonkeystotheconferencebridgeitsurewouldbenicetobeabletokickthemout.Wecandothisbylookingatallofthechannelsinthebridgeandifanyofthemhavethemonkeychannelvariablethenwecancallhangup()onthechanneltoremovethem.
![Page 63: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/63.jpg)
ARI Application – Add Monkey to Bridge
function originateMonkey(channel) { ari.channels.originate({ endpoint: 'Local/' + channel.dialplan.exten + '@astricon', context: 'monkeys', extension: 'monkeys', priority: "1", variables: { "__monkey": "true” } });
}
WeoriginatetotheconferencebridgeusingaLocalchannel.Oncethebridgeanswerswesendittothemionkeysdialplantopaybackthett-monkeyssound.
Note:wesetachannelvariablecalledmonkey
![Page 64: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/64.jpg)
ARI Application – No More Monkeys On My Bridge
bridge.channels.forEach( function(channel) { ari.channels.get({ channelId: channel }, function(err, bridgechannel) { bridgechannel.getChannelVar({ variable: 'monkey’ }).then( function(monkey) { bridgechannel.hangup(); } ).catch(); }
);
![Page 65: Creating Communication Applications using the Asterisk ... · Creating Communication Applications using the Asterisk RESTful Interface API Strategy & Practice 2017, Portland Oregon](https://reader034.fdocuments.in/reader034/viewer/2022050619/5af76d1d7f8b9a5f588b83a2/html5/thumbnails/65.jpg)
Asterisk APIs Training
Note:ThereisanAsteriskAPIsforDevelopersclassscheduledforNov-14toNov-16attheDigiumHQinHuntsville,AL.https://www.digium.com/training/asteriskQuestions?