For the next task we will need Asterisk dynamic routing using MySQL: some company has technical department that should provide emergency services on non-working hours. Based on time and date conditions, a call should be routed to a shared department’s extension (technicians) or be sent to a man on duty on non-working time and weekends. A number to dial on non-working hours should be taken from a database during a call execution. In our example, we use MySQL database with a table that contains columns “day”, “month”, “technician” and “number”. The commented extensions.conf example is below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
[tech_hotline] exten => hotline,1,NoOp(Call from ${CALLERID(all)} to tech emergency service) ;Our working hours will be from Monday to Friday 9:00 - 18:00 ;I used two GotoIfTime directives for easy management, you can do the same with one. same => n,GotoIfTime(*,sat-sun,*,*?duty) ;on weekends jump to "duty" label same => n,GotoIfTime(9:00-18:00,mon-fri,*,*?:duty) ;the same outside working hours ;in other case dial techincal department same => n,Dial(Local/technicians@services/n,30,rt) same => n,Hangup() same => n(duty),Set(Month=${STRFTIME(${EPOCH},,%m)}) ;get month's number (for example 10 for October) same => n,Set(Day=${STRFTIME(${EPOCH},,%d)}) ;get a day of month same => n,NoOp(Month=${Month}, Day=${Day}) same => n,Set(NUM=${ODBC_GETDUTYDATA(phonenum,${Day},${Month})}) ; get a phone number that should be called on this day (see func_odbc.conf below) same => n,Set(TECHNICIAN=${ODBC_GETDUTYDATA(technician,${Day},${Month})}) ;get a name of techninician same => n,NoOp(On ${Day}.${Month} number ${NUM} should be called) same => n,NoOp(Dialing the duty engineer ${TECHNICIAN}: ${NUM}) same => n,Dial(Local/${NUM}@outbound/n,20,rt) ;dialing the number taken from DB same => n,Hangup() [services] exten => technicians,1,Dial(SIP/1000&SIP/1001&SIP/1002) same => n, Hangup() |
Here is the func_odbc.conf example:
1 2 3 4 |
[GETDUTYDATA] dsn=dutylist readsql=SELECT ${ARG1} FROM dutylist WHERE day='${SQL_ESC(${ARG2})}' AND month='${SQL_ESC(${ARG3})}' synopsis=Get the duty information based on date |
I hope this will help someone.
Good luck!