Presentation is loading. Please wait.

Presentation is loading. Please wait.

ASTERISK ADVANCED. Applications Each priority in the dialplan invokes one Application. Applications do the actual work on the call, such as: Answering.

Similar presentations


Presentation on theme: "ASTERISK ADVANCED. Applications Each priority in the dialplan invokes one Application. Applications do the actual work on the call, such as: Answering."— Presentation transcript:

1 ASTERISK ADVANCED

2 Applications Each priority in the dialplan invokes one Application. Applications do the actual work on the call, such as: Answering a ringing call. Gathering input from the caller Bridging one call with another. Sending the caller to a call queue. Voicemail. Performing some logic. Takes one or more parameters separated by comma. Exten => 123, 1, application(one, two, three)

3 Answer( ) : application Answers a channel if ringing. Desirable before allowing asterisk to carry out a dialog(such as IVR). Not desirable if user will be simply placing the call to another person. Eg: exten => 123, 1, Answer( ) exten => 123,n,NoOp() exten => 123,n,Hangup()

4 Playback( ) : application Plays sound file from disk to the caller. It ignores any DTMF input. By default sound directory is /var/lib/asterisk/sounds. Background( ) : application Similar to Playback(), except it accepts DTMF input. DTMF input stops the playback of the sound file. Used for IVR, Interactive Voice Response. Eg: exten => 123, 1, Answer( ) exten => 123, n, Background(menu) exten => 1, 1, Playback(digits/1) exten => 2, 1, Playback(digits/2) Asterisk will sent the call to extension that matches the DTMF input.

5 Hangup( ) : application Hangs up current call. Make it last priority of every extension. Eg: exten => 123, 1, Answer( ) exten => 123, n, Playback (hello-world) exten => 123, n, Hangup( )

6 Goto( ) : application Allows to jump from one point to another within dialplan. Takes between one and three parameters. → Priority number or label(with in same extension). → Extension and priority(within same context). → A context, Extension and Priority(anyware in dialplan). Eg: [goto-demo] exten => 123, 1, Playback(hello-world) exten => 123, 2, Goto(1) exten => 124, 1, Playback(hello-world) exten => 124, 2, Goto(123, 1) exten => 125, 1, Playback(hello-world) exten => 124, 2, Goto(goto-demo,124, 1)

7 Wait( ) Waits for specified number of secons. NoOp( ) Stands for no operation. Use as debugging tool. Prints its arguments to asterisk console if verbosity is set to three or higher. Verbose( ) Takes two parameters. Verbosity level and message itself.

8 Voice mail ( ) : Application Two main voicemail applications. VoiceMail() - Allows caller to leave voicemail. VoiceMailMain() - Lets authenticated user to check their voicemail. exten => 6001,1,Dial(SIP/zoiper,20) exten => 6001,n,VoiceMail(6001@default) exten => 6500,1,Answer() exten => 6500,2,VoiceMailMain(@default)

9 voicemail.conf Mailbox and Voicemail context are defined in voicemail.conf. [default] 6001 => 9999,zoiper,your@email.com 6002 => 9999,prasanth,prasanth@devnull.com

10 Record ( ) : Application Allows to record your own prompts and announcements. Use # to end up the recording. Exten => 6001, 1, Answer() exten => 6001, n, Wait(0.5) exten => 6001, n, Record(day-menu.gsm) exten => 6001, n, Wait(1) exten => 6001, n, Playback(day-menu) exten => 6001, n, Hangup()

11 Dial ( ) : Application Attempt to connect to another device or endpoints. Will place calls to one or more specified channels. Unless there is a timeout specified, the Dial application will wait indefinitely until one of the called channels answers, the user hangs up, or if all of the called channels are busy or unavailable. [Syntax] : Dial(Technology/Resource[&Technology2/Resource2[&...]][,timeout [,options[,URL]]]) Eg: exten => 123, n Dial(SIP/jj_polycom,30) exten => 124, n Dial(SIP/jj_polycom&Sip/ts_xlite, 30)

12 ● Variables Defined either by system administrator or Asterisk. Channel variables Global variables Retrieve value of variable ${VARIBLE}. Channel variable ➔ Defined only for a call. ● Eg: exten => 123, n, Set(COUNT=3) Global variable ● Available any where in dial plan. ● Defined in the [globals] section of the dial plan. ● Eg: Tom=SIP/ts_xlite ● exten => 6000, 1, Dial(${Tom}) ●

13 Variables: $(DIALSTATUS) Dial application sets variable named $(DIALSTATUS) with following values after attempting to make a call. → CHANUNAVAIL → CONGESTION → NOANSWER → BUSY → CANCEL → DONTCALL exten => 6000, 1, NoOp(Calling tom) exten => 6000, n, Dial(${Tom}, 30) exten => 6000, n, Goto(${DIALSTATUS}) exten => 6000, n(NOANSWER), Voicemail(6000@default)6000@default exten => 6000, n, Hangup() exten => 6000, n(BUSY), Hangup()

14 Variables: $(EXTEN) Contains the value of the number that was dialed. Useful for pattern matching. Eg: exten => _XXX, 1, SayDigits(${EXTEN}) Application: Read() Allows to get DTMF input from caller and assign it to a variable. Eg: exten => 6000, 1, Read(Digits, enter-exten-of-person) exten => 6000, n, SayDigits(${Digits}) exten => 6000, n, Goto(1)

15 Pattern Matching Allows to accept ranges of numbers by creating patterns. Saves needing to have a specific entry for every possible combination. Always starts with an underscore. X → 0-9 (for sorting ten possible matches). N → 2-9 (for sorting eight possible matches). Z → 1-9 (for sorting nine possible matches). Eg: _ZXX, 1, SayDigits(${EXTEN}) -[0-5] → will match numbers 0 through 5 -[0-468]→ will match numbers 0 through 4, 6 and 8. Eg: exten => _1[1-3]x, 1, NoOp() // 110 through 139

16 Wildcard Match Allows to match any length of string. Wildcard character is a period (.) Eg: exten => _5XX., 1, NoOp(${EXTEN}) Starting with 500-599, of any length. exten => _., 1, NoOp(${EXTEN}) Match on any thing. Eg: exten => _NXXXXXXXXX,1,Dial(IAX2/to_iaxprov/${EXTEN})

17 Includes: Enhancing the Dialplan For using a context inside another context. Eg: include => my_context If nothing matches in the local context, Asterisk starts looking for match in included contexts. [start] Include => context_1 ← Step 1 Include => context_2 ← Step 4 [context_1] Include => context_la ← Step 2 Include => context_lb ← Step 3 [context_2] Include => context_2a ← Step 5 Include => context_2b ← Step 6

18 MACROS Macros are essentially templates that handle repetitive actions. Can call that macro for each extension that does the same thing. They look lot like contexts. The macro name must start with “macro-” Always use 's' extension.

19 MACROS cont.. Arguments can be used to pass values into macro. Values passed in the arguments show up in the macro as ${ARG1}, ${ARG2}, ${ARG3} etc. Eg: [macro-stduser] exten => s, 1, Dial(${ARG1}, 30) exten => s, n, Voicemail(${ARG2}@default, u)${ARG2}@default exten => s, n, Hangup() [users] exten => 6001, 1, Macro(stduser, SIP/ts_xlite, 6001) exten => 6002, 1, Macro(stduser, SIP/polycom, 6002) exten => 6003, 1, Macro(stduser, IAX2/g1, 6003)

20 AstDB Database AstDB allows to do all these functions:- Retain data between calls. Store shared(global) parameters. Keep track of feature state. AstDB is small, simple database that stores key/value pairs. Not relational DB like MySQL or PostgreSQL. Easy to store and retrieve data from Asterisk dialplan. Storage is organized into families, keys and values. Family/key1/key2=value Can access AstDB from Dialplan as well as CLI.

21 Storing Data in AstDB Write data to database using DB function. Exten => 123, 1, Set(DB(family/key1/key2)=value) CLI> database put family Key1/key2 value Reading Data from AstDB Read data from database using DB function. Exten => 123, 1, Set(MYVALUE=${DB(family/key1/key2)}) CLI> database show family Key1/key2 Check Key exist in AstDB Check using DB_EXISTS function. Exten => 123, 1, Verbose(2,${DB_EXISTS(family/key)}) Returns 1 if key exists, otherwise zero.

22 Delete values from AstDB Deleting values using DBDel( ) application. Returns value of the key. Exten => 123, 1, Set(oldvalue=${DB_Del(family/key1)}) CLI> database del family key1/key2

23 Relational Database queries in the Dialplan It will be nice if through Dialplan connection can be established to relational database. func_odbc turns database queries into dialplan functions. Can read values from database as well as write new values to database. Asterisk will talk through ODBC database layer to talk to the database.

24 Our Plan Setup the database. Get the ODBC system talking to the database. Tell Asterisk how to talk to ODBC. Define what SQL queries we would like to run. Use funk_odbc functions from the dialplan to execute those queries.

25 Database setup Create user and database for Asterisk in your favorite relational database. ODBC Setup Configure ODBC to talk to database. Configure ODBC driver which is in /etc/odbcinst.ini /etc/odbcinst.ini [MYSQL] Description=ODBC for MySQL Driver=/usr/lib/odbc/libmyodbc.so Setup=/usr/lib/odbc/libodbcmyS.so FileUsage=1 Our Plan Setup the database. Get the ODBC system talking to the database. Tell Asterisk how to talk to ODBC. Define what SQL queries we would like to run. Use funk_odbc functions from the dialplan to execute those queries.

26 ODBC Setup, cont'd Configure the ODBC DSN in /etc/odbc.ini. /etc/odbc.ini [accounts] Description = Account information Driver = MySql Trace = 0 Database = asterisk Servername = 127.0.0.1 Username = root Password = root Port = 3306

27 Asterisk talking to ODBC This ODBC connection points to the DSN defined in odbc.ini. /etc/asterisk/res_odbc.conf [bank] enabled => yes dsn => accounts pre-connect => yes

28 func_odbc Can configure queries in func_odbc. funk_odbc converts SQL queries to custom dialplan functions. /etc/asterisk/func_odbc [NAME_BANK] dsn=bank readsql=SELECT username FROM accounts where account_id='${ARG1}' [BAL_BANK] dsn=bank readsql=SELECT balance FROM accounts where account_id='${ARG1}'

29 funk_odbc cont.. funk-odbc would create a dialplan fn. Named ODBC_DUMMY() that we can use from the dialplan. To read from the database use dialplan syantax NoOp(${ODBC_DUMMY(5)}) To write to the database use dialplan syantax NoOp(ODBC_DUMMY(5)=test)

30 /etc/asterisk/extensions.conf exten => 9000,1,Answer() exten => 9000,n,NoOp() exten => 9000,n,Read(VAR,accounting,1,,2,5) exten => 9000,n,NoOp(${VAR}) exten => 9000,n,SayAlpha(${ODBC_NAME_BANK(${VAR})}) exten => 9000,n,SayNumber(${ODBC_BAL_BANK(${VAR})}) exten => 9000,n,Hangup()

31 Configure Asterisk with PostgreSQL http://www.asteriskguru.com/tutorials /realtime_pgsql.html

32 Seven layer database DIP


Download ppt "ASTERISK ADVANCED. Applications Each priority in the dialplan invokes one Application. Applications do the actual work on the call, such as: Answering."

Similar presentations


Ads by Google