Real-time multimedia and communication in packet networks Asterisk AGI and Manager Interface.
-
Upload
martin-freeman -
Category
Documents
-
view
235 -
download
2
Transcript of Real-time multimedia and communication in packet networks Asterisk AGI and Manager Interface.
Real-time multimedia and communication in packet networks
Asterisk AGI and Manager Interface
Last Practical Create a calculator application using the Asterisk dialplan
E.g. phone an extension * answers and provide an IVR menu saying press 1 to go to
the calculator, 2 to go somewhere else, and 3 to go somewhere further
If I press 1 – must be routed to calculator where I am prompted to choose to go to multiplication menu, division menu, add menu or subtraction menu
1,2,3,4 Within each menu – prompt user for expression separated by
star (*) So in addition menu, pressing 100*20 should return 120 While in multiplication menu pressing 100*20 will return
2000 Results can be played using Festival After each result should have option of another operation or
going to one of the other menus (+-/*) Remember to check out http://www.voip-info.org/ - Check out
the Cut function!
Controlling Asterisk
• Number of ways Asterisk can be controlled• Dialplan• Asterisk scheduling (call me)• Asterisk Gateway Interface (AGI)• Manager Interface
AGI• AGI allows us to add functionality to Asterisk with many
different programming languages• Java, Perl, PHP, C, Pascal – Anything!• Provides a standard interface through which programs may
control asterisk• Used for advanced logic or to communicate with resources
such as relational databases and external devices• Allows asterisk to perform tasks that would be otherwise
difficult or impossible
AGI – How it works
• The AGI script is called from the dialplan• Asterisk and your program communicate via the STDIN,
STDOUT and STDERR communications channels (file handles in programming)
• Your AGI scripts reads input via its STDIN file handle• Your AGI script writes back to asterisk via its STDOUT file
handle• Your AGI program writes error message back to asterisk via its
STDERR file handle
Starting your AGI program
• Syntax:• exten => extennumber,priority,application,arguments
• The application is “AGI”• The argument is the filename of your program• The script must be:
• executable (chmod +x filename)• located in /var/lib/asterisk/agi-bin in source versions of
asterisk• Located in /usr/share/asterisk/agi-bin in binary vesions of
asterisk• Example: Run a perl script agi-test.agi
• exten => 1,2,AGI, agi-test.agi
Passing args
• exten 1,2,AGI,agi-test.agi|${ARG1}|${ARG2}• AGI programs always receive two args
• 1 – path to the AGI script• 2 – Arguments passed from the dialplan
• Notes about arguments:• If no arg is given – the arg is empty.• Consists of everything on the line following the verticle bar
after the file name, up until the final vertical bar• Quotes are taken as being part of the argument
Communicating with *
• Use 'show agi' at the CLI will give you a list of commands• At script startup time, * sends a group of variables to your
script which you have to read in• Each item is sent on a line terminated with a newline. The last
item is followed by an empty line• agi_request: agi-test.agi• agi_channel: SIP/1000-bcgd162• agi_language: en• agi_context: mtsietsi• agi_extention: 105• agi_priority: 2
• Commands sent to * must be terminated with newline
AGI examples• Perl - /usr/share/asterisk/agi-bin/agi-test.agi• Java - /usr/share/asterisk/agi-bin/mosJava.java
• /usr/share/asterisk/agi-bin/mosJava.agi
Manager API
• A client/server module that allows us to interact with * via TCP/IP
• Similar to SMTP and HTTP• Communicates using tags
• “header:value” terminated with a newline• First tag must be one of the following
• Action: an action requested by the client.• Response: A response to an action from Asterisk• Event: An event reported by Asterisk to the client
Manager interface (login)
• telnet into 146.231.121.88 on port 5038• Login
• Action: Login• Username: voipuser• Secret: voipuser• Events: off• /r/n
Manager interface (Originate)• Action: Originate• Channel: SIP/1000• Exten: s• Context: mtsietsi• Priority: 1• Timeout: 10000
Manager interface (Monitor)• Action: Monitor• Channel: SIP/ab5s51182s• File: monitor• Mix: 1
Today's Practical
• 1) Extend your calculator to incorporate an AGI program• Do the calculation• Parse the numbers• Take a number to a power• Solve complex problems i.e. y = ax4 + ax3 = ax2 + ax + a