Tuesday, 24 January 2017

B-ACD with Work & After Hour Schedule Using TCL Script

Recently, I had a request for a B-ACD to play a menu on a voice gateway at 8:00 a.m. and a different menu after 4:30 p.m.  At the time, I knew that Event Manager could do the schedule, and actually, it worked, but the menu(b-acd, not aa) session was struck and stayed with old one. Using “call application session stop id [id]” can stop it, but a question came up with how could I use “show call application sessions” to extract the session id?
R4331#show call application sessions
Session ID 5D
           App: queue
          Type: Service
           Url: flash:/bacd/app-b-acd-3.0.0.4.tcl

Anyhow, it took me a while and here are the steps:

Step 1 - Create two folder for work hour and after hour audio files

R4331#dir flash:
Directory of bootflash:/
353409  drwx             4096  Jan 23 2017 09:40:49 +00:00  bacd
16065  drwx             4096  Jan 22 2017 23:11:47 +00:00  bacd-ah

Step 2 - upload b-acd scripts and audio files to each folder:

Work hour folder
R4331#cd bacd   
R4331#dir
Directory of bootflash:/bacd/

353410  -rw-            33880  Jan 22 2017 21:34:07 +00:00  app-b-acd-3.0.0.4.tcl
353411  -rw-            61527  Jan 22 2017 21:34:30 +00:00  app-b-acd-aa-3.0.0.4.tcl
353412  -rw-            75650  Jan 22 2017 21:35:03 +00:00  en_bacd_allagentsbusy.au
353413  -rw-            83291  Jan 22 2017 21:35:32 +00:00  en_bacd_disconnect.au
353414  -rw-            63055  Jan 22 2017 21:36:03 +00:00  en_bacd_enter_dest.au
353415  -rw-            37952  Jan 22 2017 21:36:16 +00:00  en_bacd_invalidoption.au
353416  -rw-           496521  Jan 22 2017 21:36:29 +00:00  en_bacd_music_on_hold.au
353417  -rw-           103017  Jan 23 2017 09:42:05 +00:00  en_bacd_options_menu.au
353419  -rw-            50391  Jan 23 2017 09:40:49 +00:00  en_bacd_welcome.au

After hour folder
R4331#cd ../bacd-ah
R4331#dir
Directory of bootflash:/bacd-ah/

16066  -rw-            33880  Jan 22 2017 23:10:08 +00:00  app-b-acd-3.0.0.4.tcl
16067  -rw-            61527  Jan 22 2017 23:10:18 +00:00  app-b-acd-aa-3.0.0.4.tcl
16068  -rw-            75650  Jan 22 2017 23:10:27 +00:00  en_bacd_allagentsbusy.au
16069  -rw-            83291  Jan 22 2017 23:10:36 +00:00  en_bacd_disconnect.au
16070  -rw-            63055  Jan 22 2017 23:10:46 +00:00  en_bacd_enter_dest.au
16071  -rw-            37952  Jan 22 2017 23:10:56 +00:00  en_bacd_invalidoption.au
16072  -rw-           496521  Jan 22 2017 23:11:06 +00:00  en_bacd_music_on_hold.au
16073  -rw-           122896  Jan 23 2017 09:43:03 +00:00  en_bacd_options_menu.au
16074  -rw-            51472  Jan 23 2017 09:42:30 +00:00  en_bacd_welcome.au

Step 3 - inbound dial-peer to divert to b-acd application:

dial-peer voice 225 voip
service aa   ← it’s work-hour application temporary  
destination-pattern 5037526652
session protocol sipv2
session target ipv4:10.1.1.190  ←CME IP address
incoming called-number 5037526652
dtmf-relay rtp-nte
codec g711ulaw
no vad

Step 4 - outbound dial-peer to CUCM for extensions:

dial-peer voice 221 voip
destination-pattern 503[06]49....
session protocol sipv2
session target ipv4:10.1.1.10  ←pub
dtmf-relay rtp-nte
codec g711ulaw
no vad
!
dial-peer voice 220 voip
preference 1
destination-pattern 503[06]49....
session protocol sipv2
session target ipv4:10.1.1.20  ← sub
dtmf-relay rtp-nte
codec g711ulaw
no vad

Step 5 - music on-hold must be setup on the CME:

telephony-service
max-ephones 5
max-dn 10
ip source-address 10.1.1.190 port 2000
max-conferences 8 gain -6
call-forward pattern .T
call-forward system redirecting-expanded
moh enable-g711 "flash:/bacd/en_bacd_music_on_hold.au"
transfer-system full-consult
create cnf-files version-stamp Jan 01 2002 00:00:00

Step 6 - work hour and after hour voice applications:

!
application
service aa-ah flash:/bacd-ah/app-b-acd-aa-3.0.0.4.tcl
 paramspace english index 1
 param dial-by-extension-option 5
 param handoff-string aa-ah
 param welcome-prompt _bacd_welcome.au
 param operator 0
 param call-retry-timer 15
 paramspace english language en
 param service-name queue-ah
 param menu-timeout 6
 param second-greeting-time 60
 paramspace english location flash:/bacd-ah/
 param max-time-vm-retry 2
 param max-time-call-retry 5037526652
 param voice-mail 5003
 param aa-pilot
 param max-extension-length 10
 param number-of-hunt-grps 3
!
service aa flash:/bacd/app-b-acd-aa-3.0.0.4.tcl
 paramspace english index 1
 param number-of-hunt-grps 4
 param menu-timeout 6
 param dial-by-extension-option 5
 param handoff-string aa
 param operator 0
 paramspace english language en
 param max-time-vm-retry 2
 param max-extension-length 10
 param aa-pilot 5037526652
 paramspace english location flash:/bacd/
 param second-greeting-time 60
 param welcome-prompt _bacd_welcome.au
 param call-retry-timer 15
 param voice-mail 5003
 param max-time-call-retry 700
 param service-name queue
!
service queue flash:/bacd/app-b-acd-3.0.0.4.tcl
 group-name queue
 param name queue
 param queue-len 15
 param aa-hunt3 5036495533
 param aa-hunt4 5030495505
 param aa-hunt1 5036495503
 param number-of-hunt-grps 4
 param queue-manager-debugs 1
 param aa-hunt2 5036495586
!
service queue-ah flash:/bacd-ah/app-b-acd-3.0.0.4.tcl
 param aa-hunt1 5036495503
 param number-of-hunt-grps 3
 param queue-manager-debugs 1
 param aa-hunt2 5036495586
 param name ah
 param queue-len 15
 param aa-hunt3 5030495505

Step 7 - Tcl scripts to clean up stuck call application session and change service on the inbound dial-peer:


work-hour.tcl
set session [exec "show call application session"]
set id [string range $session 11 20]
if { $id == "" } {  } else { exec "call application session stop id $id"}
ios_config "dial-peer voice 225 voip" "service aa"
ios_config "end"
ios_config "write memory" 

after-hour.tcl
set session [exec "show call application session"]
set id [string range $session 11 20]
if { $id == "" } {  } else { exec "call application session stop id $id"}
ios_config "dial-peer voice 225 voip" "service aa-ah"
ios_config "end"
ios_config "write memory"



Upload them to flash:
R4331#dir
Directory of bootflash:/
  21  -rw-              230  Jan 24 2017 09:31:10 +00:00  work-hour.tcl
  22  -rw-              233  Jan 24 2017 09:31:16 +00:00  after-hour.tcl

Step 8 - Event Manager scheduling with Tcl scripts:

 event manager applet WEEKDAY_START
 event timer cron name WEEKDAY_START cron-entry "1 8 * * 1-5"
 action 1.0 cli command "enable"
 action 1.1 cli command "tclsh flash:work-hour.tcl"

 event manager applet WEEKDAY_END
 event timer cron name WEEKDAY_END cron-entry "30 16 * * 1-5"
 action 1.0 cli command "enable"
 action 1.1 cli command "tclsh flash:after-hour.tcl"

No comments:

Post a Comment