📜 ⬆️ ⬇️

Indication of the DnD mode on the BLF key in Asterisk

image
DnD is a rather demanded function, but usually the mode is turned on on the phone itself, without notifying Asterisk about it, which will call the user’s phone, thinking that it’s in place and ready to answer the call. How do we turn on the DnD mode on Asterisk itself and so that the power button with the activated DnD blinked in red?
To do this, we need a phone with BLF buttons and a couple of macros. Checked on IP phones Grandstream GXP series, a variety. The server is Linux with Elastix, well, you can just Asterisk 1.6+ .

Attention! On some phones, a firmware update is required for the BLF keys to work correctly.

1. Create macros in /etc/asterisk/extensions_override_freepbx.conf. It is of course connected in extensions.conf.
Macro text:
')
[ext-dnd-hints] exten => *761000,1,Goto(app-dnd-toggle,*76,1) exten => *761000,hint,Custom:DEVDND1000 


This macro contains phone numbers to be monitored, in the example extension 1000 is indicated. * 76 is this feature code.
By analogy, you need to create entries for each number that needs the DnD function.

 [app-dnd-toggle] include => app-dnd-toggle-custom exten => *76,1,Answer exten => *76,n,Wait(1) exten => *76,n,Macro(user-callerid,) exten => *76,n,GotoIf($["${DB(DND/${AMPUSER})}" = ""]?activate:deactivate) exten => *76,n(activate),Set(DB(DND/${AMPUSER})=YES) exten => *76,n,Set(STATE=RINGING) exten => *76,n,Gosub(app-dnd-toggle,sstate,1) exten => *76,n,Playback(do-not-disturb&activated) exten => *76,n,Macro(hangupcall,) exten => *76,n(deactivate),dbDel(DND/${AMPUSER}) exten => *76,n,Set(STATE=NOT_INUSE) exten => *76,n,Gosub(app-dnd-toggle,sstate,1) exten => *76,n,Playback(do-not-disturb&de-activated) exten => *76,n,Macro(hangupcall,) exten => sstate,1,Set(DEVICE_STATE(Custom:DND${AMPUSER})=${STATE}) exten => sstate,n,Set(DEVICES=${DB(AMPUSER/${AMPUSER}/device)}) exten => sstate,n,GotoIf($["${DEVICES}" = "" ]?return) exten => sstate,n,Set(LOOPCNT=${FIELDQTY(DEVICES,&)}) exten => sstate,n,Set(ITER=1) exten => sstate,n(begin),Set(DEVICE_STATE(Custom:DEVDND${CUT(DEVICES,&,${ITER})})=${STATE}) exten => sstate,n,Set(ITER=$[${ITER} + 1]) exten => sstate,n,GotoIf($[${ITER} <= ${LOOPCNT}]?begin) exten => sstate,n(return),Return() 


This is the macro itself that switches states; nothing needs to be changed here.

2. We include ext-dnd-hints in the context we need, for example:

 [from-internal] include => ext-dnd-hints exten => h,1,Hangup 


Be careful here, you need to specify all contexts that come from from-internal, otherwise they will stop working.

3. Set up a key on the phone: register the number * 761000 on it and turn on the BLF mode. If the BLF mode does not work, read the text in italics at the beginning of the topic.

4. In the CLI, we do dialplan reload and check whether our hint has appeared. In normal mode, the view will be as follows:

 xtelekom*CLI> core show hint *761000 *761000@ext-dnd-hints : Custom:DEVDND1000 State:Idle Watchers 1 


If the phone does not request DnD status, then Watchers will be equal to 0.

Some phones with an unavailable BLF (blinking red) when calling, add ** more to the number, in which case the number is obtained like *** 761000. For this variant to work, the macro is slightly different, I will place it under the spoiler, because it repeats the first macro:
Another macro
 [ext-dnd-hints] exten => *761000,1,Goto(app-dnd-toggle,*76,1) exten => ***761000,1,Goto(app-dnd-toggle,***76,1) exten => *761000,hint,Custom:DEVDND1000 [app-dnd-toggle] include => app-dnd-toggle-custom exten => *76,1,Answer exten => *76,n,Wait(1) exten => *76,n,Macro(user-callerid,) exten => *76,n,GotoIf($["${DB(DND/${AMPUSER})}" = ""]?activate:deactivate) exten => *76,n(activate),Set(DB(DND/${AMPUSER})=YES) exten => *76,n,Set(STATE=RINGING) exten => *76,n,Gosub(app-dnd-toggle,sstate,1) exten => *76,n,Playback(do-not-disturb&activated) exten => *76,n,Macro(hangupcall,) exten => *76,n(deactivate),dbDel(DND/${AMPUSER}) exten => *76,n,Set(STATE=NOT_INUSE) exten => *76,n,Gosub(app-dnd-toggle,sstate,1) exten => *76,n,Playback(do-not-disturb&de-activated) exten => *76,n,Macro(hangupcall,) exten => sstate,1,Set(DEVICE_STATE(Custom:DND${AMPUSER})=${STATE}) exten => sstate,n,Set(DEVICES=${DB(AMPUSER/${AMPUSER}/device)}) exten => sstate,n,GotoIf($["${DEVICES}" = "" ]?return) exten => sstate,n,Set(LOOPCNT=${FIELDQTY(DEVICES,&)}) exten => sstate,n,Set(ITER=1) exten => sstate,n(begin),Set(DEVICE_STATE(Custom:DEVDND${CUT(DEVICES,&,${ITER})})=${STATE}) exten => sstate,n,Set(ITER=$[${ITER} + 1]) exten => sstate,n,GotoIf($[${ITER} <= ${LOOPCNT}]?begin) exten => sstate,n(return),Return() exten => ***76,1,Answer exten => ***76,n,Wait(1) exten => ***76,n,Macro(user-callerid,) exten => ***76,n,GotoIf($["${DB(DND/${AMPUSER})}" = ""]?activate:deactivate) exten => ***76,n(activate),Set(DB(DND/${AMPUSER})=YES) exten => ***76,n,Set(STATE=) exten => ***76,n,Gosub(app-dnd-toggle,sstate,1) exten => ***76,n,Playback(do-not-disturb&activated) exten => ***76,n,Macro(hangupcall,) exten => ***76,n(deactivate),dbDel(DND/${AMPUSER}) exten => ***76,n,Set(STATE=UNAVAILABLE) exten => ***76,n,Gosub(app-dnd-toggle,sstate,1) exten => ***76,n,Playback(do-not-disturb&de-activated) exten => ***76,n,Macro(hangupcall,) exten => sstate,1,Set(DEVICE_STATE(Custom:DND${AMPUSER})=${STATE}) exten => sstate,n,Set(DEVICES=${DB(AMPUSER/${AMPUSER}/device)}) exten => sstate,n,GotoIf($["${DEVICES}" = "" ]?return) exten => sstate,n,Set(LOOPCNT=${FIELDQTY(DEVICES,&)}) exten => sstate,n,Set(ITER=1) exten => sstate,n(begin),Set(DEVICE_STATE(Custom:DEVDND${CUT(DEVICES,&,${ITER})})=${STATE}) exten => sstate,n,Set(ITER=$[${ITER} + 1]) exten => sstate,n,GotoIf($[${ITER} <= ${LOOPCNT}]?begin) exten => sstate,n(return),Return() 



Next time I’ll tell you how to monitor the status of the queue in the same way.

PS Sometimes on the grandstream you need to restart the phone, otherwise the button does not work correctly.

Source: https://habr.com/ru/post/155899/


All Articles