Download presentation
Presentation is loading. Please wait.
Published byJada Hudnall Modified over 10 years ago
1
Real-time multimedia and communication in packet networks Asterisk Dialplan and Native Database
3
Last Week’s Prac Create and account for your phone Play around with some of the settings in the sip.conf file
4
Today's Practical 1) Via the dial-plan, Implement a way to record prompts directly from your phone through the extension 9100. 2) Implement a simple “front end” IVR, allowing callers to dial extensions, “1 for sales” and suchlike. Use the ‘show applications’ to find the method for performing recordings Use the ‘show applications’ to find the method for jumping to another context 3) Implement a redial extension using Asterisk’s native database. i.e. extension 9200 will redial the last number you dialled
5
Asterisk dialplan Dialplan routes every call in the system from its source through various applications to its destination i.e.' show applications' Dialplan composed of one or more contexts Each context contains a collection of extensions Each context has a unique name associated with it When you work, add “yourname-” to your contexts to uniquely identify them i.e. mos-first_context
6
Understanding Contexts
7
Basic extension context Diagrammatically an example extension context may look something like this In this example context (called ‘default’) First 4 extensions are associated with ringing phones for various users 5 th extension (100) allows users to check their voicemail 6 th extension (101) is associated with an audio conference room Voicemail Menu100 Chris1007 Conference Room101 Sacha1004 Samuel1002 Mos1001 DescriptionExtension Mos Context
8
Pattern matching Extensions can also match patterns Patterns to be matched must start with an underscore ‘_’ May use any of the following special characters X – any digit from 0-9 Z – any digit from 1-9 N – any digit from 2-9 [14-6] – digits 1,4,5,6. – matches anything (NB use with extreme caution)
9
Pattern matching order Employing pattern matching in your Asterisk dialplan, while very powerful, can be tricky. It is easy to assume that Asterisk runs through the dialplan in a completely sequential manner; while this is generally the case, it does prioritize patterns based on the quality of the match. The reason for this is simple: more than one pattern might match a dialled number. If two extensions match a dialled number, Asterisk will always choose the better (less ambiguous) match. Before deciding which extension matches best, it processes the entire context. Use the “dialpan show x” command in the CLI to explore more
10
Context inclusion One extension context can include the contents of another Long distance calls_0[1-8][1-356789]XXXXXXX Include => Local DescriptionExtension Telkom PBX Numbers_8XXX Include => from-sip DescriptionExtension Local DescriptionExtension from-sip (internal)
11
Asterisk – predefined extensions Each step in an extension is typically notated as follows: exten =>,,, [( )] Certain extension names are reserved for specialized purposes. Specifically: s: The "start" extension t: The "timeout" extension. When a caller is in a voice menu and does not enter the proper number of digits (or enters no digits at all), the timeout extension is executed. If the timeout extension is omitted, then the caller is disconnected
12
Asterisk – predefined extensions i: The "invalid" extension. When a caller enters an invalid extension number, this extension is executed. If omitted, the caller is disconnected h: The "hangup" extension. If present, this extension is executed at the end of call (i.e. when the caller hangs up or is hung up upon). Applications executed in this extension should not try to do anything to the channel itself since it has been hung up already, but can use it for logging, executing commands, etc
13
Dialling a phone Most common extension is that for dialling out another interface In this case we use the Dial application Dial has a number or arguments Do ‘show application Dial’ to see more details exten => 1000,1,Dial(SIP/100,20) exten => 1000,2,Voicemail(u100) exten => 1000,102,Voicemail(b100) example illustrates one of the few exceptions to execution of an extension being out of order On entering the extension (priority 1) attempts to dial the SIP phone 1000 for a maximum of 20 seconds If the phone is busy, it will jump to priority n+101 if such a priority exists in this extension In this case, we have such a priority (102), which sends the caller to voice mailbox 1000, (with busy announcement) If there was simply no answer (or if there was a busy and we didn't have a step 102), execution would continue at step 2, where the caller is put into voice mailbox 1000, (with an unavailable announcement)
14
Routing by callerid Known as the “anti-ex girlfriend” extension exten => 100/0786346926,1,Congestion exten => 100,1,Dial(Zap/1,20) exten => 100,2,Voicemail(u100) exten => 100,102,Voicemail(b100) example builds upon the previous by adding a special rule that if the caller is 0786346926 (routing by Caller ID is indicated by placing / and the Caller ID number to match immediately following), they are immediately presented with Congestion tone
15
Routing by callerid If someone phones who doesn’t send their callerid exten => 100/,1,Congestion exten => 100,1,Wait(3) exten => 100,2,Dial(Zap/1)
16
Routing by Time A lot of companies disable outgoing calls to PSTN after hours, we can do this easily in asterisk: [company] exten => _046XXXXXXX,1,Ringing() exten => _046XXXXXXX,2,GotoIfTime(8:30-12:30| mon-fri|1-29|*?dial- zap,s,1) exten => _046XXXXXXX,3,Playback(so-sorry)
17
Ringing phones in sequence Often it is desired that a given extension first ring one phone, and then if there is no answer, ring another phone (or set of phones) E.g. exten => 1020,1,Dial(Zap/1&Zap/2,15) exten => 1020,2,Dial(Zap/g1,15) exten => 1020,3,Playback(companymailbox) exten => 1020,4,Voicemail(100) exten => 1020,5,Hangup try ringing interface Zap/1 If Zap/1 and Zap/2 are both busy, or no answer after 15 seconds, we try calling any other available phone in the Zap group for another 15 seconds If still no answer (or everyone is busy) then we playback a message announcing that no one is available, and to please leave a message in company mailbox
18
Asterisk Native Database Simple database resembling the Windows registry consisting of records of the form i.e. mosiuoa/foo, bar Developed on top of version 1 of the Berkeley database system We can list current records in the database from the CLI using the command database show We have dialplan interfaces to this database using the commands Set(DB(family/key)=${foo}: Stores a tuple into the database Set(foo=${DB(family/key)}): Stores a database value into a variable DBDel(family/key): Deletes a tuple from the database This database and its interfaces provides us with data persistence, upon which we can develop sophisticated applications and services
19
Today's Practical 1) Via the dial-plan, Implement a way to record prompts directly from your phone through the extension 9100. 2) Implement a simple “front end” IVR, allowing callers to dial extensions, “1 for sales” and suchlike. Use the ‘show applications’ to find the method for performing recordings Use the ‘show applications’ to find the method for jumping to another context 3) Implement a redial extension using Asterisk’s native database. i.e. extension 9200 will redial the last number you dialled
20
Real-time multimedia and communication in packet networks Asterisk Variables, Macros and Auto-dialing
21
Yesterdays Practical Implement an IVR (interactive voice response) to route a user through a menu system using input from the user Use voice recording to store sound files that can be played back to the user i.e. Playback() Use DB API commands to implement a simple redial application of last call made How is it going?
22
Some Dialplan Questions Anti-in law example [mycontext] exten => 101/1000,1,Congestion exten => 101,2,Playback(tt-monkeys) exten => 101,3,Hangup [main-menu] exten => s,1,Playback(welcome) exten => s,2,Goto(mycontext,101,1) the above will give congestion when 1000 calls and terminate if anyone else calls
23
Some Dialplan Questions Repeated extension [default] exten => 101,1,SayAlpha(abc) exten => 101,1,SayAlpha(xyz) exten => 101,2,Set(TIMEOUT(digit)=5) exten => t,1,Playback(vm-goodbye) exten => t,2,Hangup asterisk plays first rule when there is a clash
24
Variables in the dialplan Asterisk makes use of global and channel specific variables Variables are expressed in the dialplan using ${foo} where foo is the name of the variable A variable may be any alphanumeric string beginning with a letter, but there are some variables whose names have special meanings. Specifically: ${CONTEXT} - The current context ${EXTEN} - The current extension ${EXTEN:x} - The current extension with x leading digits dropped ${PRIORITY} - The current priority ${CALLERID} - The current Caller ID (name and number) ${CALLERIDNUM} - The current Caller ID number ${CALLERIDNAME} - The current Caller ID name
25
Variables Global variables specified in the [globals] section of the dialplan or can be set using the SetGlobalVar command Channel variables are set using Set command in the dialplan and are accessible to only one channel Environment variables allow Asterisk to get access to UNIX variables using the ${ENV(foo)} notation [variables] exten => 100,1,SetGlobalVar(FOO=1011) exten => 100,2,Dial(SIP/${FOO}) exten => 100,3,Set(FEE=7521) exten => 100,4,Dial(SIP/${FEE}@sip.ict.ru.ac.za,20)SIP/${FEE}@sip.ict.ru.ac.za,20 exten => 100,5,NoOp(${ENV(HOSTNAME)}
26
Including contexts One context can include zero or more other contexts, optionally with a date/time limitation Contexts are included in the order they are listed The format for include is: include => [| | | | ] Where: is the context to be included are the hours in which this include is considered valid (in the form of a range, in military time, e.g. 9:00-17:00) are the days of the week considered valid (e.g. mon-fri) are the days of the month considered valid (e.g. 22-25) are the months considered valid
27
Including contexts [newyears] exten => s,1,Playback(happy-new-years) [daytime] exten => s,1,Dial(Zap/1,20) [nighttime] exten => s,1,Playback(after-hours-msg) [default] include => newyears||||1|jan include => daytime|9:00-17:00|mon-fri include => nighttime
28
Using Macros While Asterisk extension logic is very flexible, it can also be very verbose when creating many extensions which are similar For simplicity, we can take advantage of macros which simplify dialplans and make it easier to modify flows on a large scale Macros are implemented by creating an extension context whose name begins with macro-, followed by the name of the macro Execution begins at the s extension and ends as soon as the extension drops to a location that is no longer within the macro
29
Using Macros Macros define some useful local variables, specifically: ${MACRO_EXTEN} - The extension calling the macro ${MACRO_CONTEXT} - The extension context calling the macro ${MACRO_PRIORITY} - The active priority when the macro was called ${MACRO_OFFSET} - If set, causes the macro to attempt to return to n + ${MACRO_OFFSET} ${ARGn} - The nth argument passed to the macro
30
Using Macros [macro-oneline] ; Standard one-line phone. ; ${ARG1} - Device to use exten => s,1,Dial(${ARG1},20) exten => s,2,Voicemail(u${MACRO_EXTEN}) exten => s,3,Hangup exten => s,102,Voicemail(b${MACRO_EXTEN}) exten => s,103,Hangup [macro-twoline] ; Standard two-line phone. ; ${ARG1} - First phone ; ${ARG2} - Second phone exten => s,1,Dial(${ARG1},20) exten => s,2,Voicemail(u${MACRO_EXTEN}) exten => s,102,Dial(${ARG2},20) exten => s,103,Voicemail(b${MACRO_EXTEN}) [default] exten => 1000,1,Macro(oneline,Zap/1) exten => 1001,1,Macro(oneline,SIP/1001) exten => 1002,1,Macro(twoline,Zap/3,Zap/4)
31
Using Macros After doing the complex work of defining the oneline macro for a single line phone and the twoline macro for a two-line phone implementing the default context becomes extremely easy, and each extension requires only a single line instead of several similar lines
32
Auto-Dial We can use *s auto-dial feature to create outgoing calls from external applications Typically done by dumping a specially formatted file in /var/spool/asterisk/outgoing Can also be done via * Manager Interface (more on this at a later date)
33
Typical Call File Channel: SIP/1000 MaxRetries: 2 WaitTime: 10 RetryTime: 10 Context: mos-callme Extension: 500 Priority: 1 we can also use the linux command touch -t YYYYMMDDhhmm file to schedule callme in the future
34
Today's Practical Hope you didn´t have any plans for the weekend! 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 or text2wave 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!http://www.voip-info.org/
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.