Hi guys,
I've written a script to toggle between day / night mode for a tenant, with the idea being it's faster than the IVR and doesn't take up as many keys on the phone as having a night button and a day button.
I'm now looking to try and have a BLF setup for this so the users can see at a glance if it's in night mode or day mode.
I've got SIP SUBSCRIBE setup from the phone to subscribe for status changes to feature code, and I've tried setting up Hints and Presence States in the dialplan to update this when called, but can't seem to get this working in Thirdlane's particular Asterisk.
Any pointers for how to setup a custom device state changed from the dialplan? I'm on 9.1.2.37 MT.
Below is an copy of my code so far if it's useful to anyone:
[macro-mode-toggle]
exten => s,1,NoOp(Current mode is ${TL_GET_OFFICEMODE(${tenant})} )
exten => s,n,GotoIf($["${TL_GET_OFFICEMODE(${tenant})}" = "day"]?night)
exten => s,n,GotoIf($["${TL_GET_OFFICEMODE(${tenant})}" = "night"]?day)
exten => s,n(day),Set(result=${TL_SET_OFFICEMODE(${tenant},day)})
exten => s,n,Playback(tl/day-mode)
exten => s,n,Playback(ha/set)
exten => s,n,Hangup()
exten => s,n(night),Set(result=${TL_SET_OFFICEMODE(${tenant},night)})
exten => s,n,Playback(tl/night-mode)
exten => s,n,Playback(ha/set)
exten => s,n,Hangup()
Thanks Volodya,
Thanks Volodya,
I got it in the end, for anyone else looking to do this it now toggles between day & night mode and updates the BLF on the phone so the users can see at a glance it's status.
exten => s,1,NoOp(Current mode is ${TL_GET_OFFICEMODE(${tenant})} - Dialed - ${MACRO_EXTEN})
exten => s,n,GotoIf($["${TL_GET_OFFICEMODE(${tenant})}" = "day"]?night)
exten => s,n,GotoIf($["${TL_GET_OFFICEMODE(${tenant})}" = "night"]?day)
exten => s,n(day),Set(result=${TL_SET_OFFICEMODE(${tenant},day)})
exten => s,n,Set(DEVICE_STATE(Custom:C${MACRO_EXTEN}-${tenant})=NOT_INUSE)
exten => s,n,Playback(tl/day-mode)
exten => s,n,Playback(ha/set)
exten => s,n,Hangup()
exten => s,n(night),Set(result=${TL_SET_OFFICEMODE(${tenant},night)})
exten => s,n,Set(DEVICE_STATE(Custom:C${MACRO_EXTEN}-${tenant})=BUSY)
exten => s,n,Playback(tl/night-mode)
exten => s,n,Playback(ha/set)
exten => s,n,Hangup()
The downside is that day
The downside is that day/night is a persistent state recorded in a database and custom device states are volitile. You’re going to really need an external cron job to scan for states in the database and update their state through the AMI. Otherwise a restart such as a nightly update will result in inconsistencies.
Hello Nick,
Hello Nick,
As a small improvement to your script I would suggest to set some variable with present mode state from Memcache like so:exten => s,1,Set(CURRENT_MODE=${HASH(T,officemode)})
And then use this variable instead of calling ODBC function TL_GET_OFFICEMODE.
Thanks for your contribution!
Hello Nick,
How did you configured your hints, were you able to see them by running core show hints in asterisk CLI? Also, did your phone subscribed correctly? sip show subscriptions
You can try using CustomPresence in case you were not: https://wiki.asterisk.org/wiki/display/AST/Presence+State#PresenceState-func_presencestateAndTheCustomPresenceProvider, https://wiki.asterisk.org/wiki/display/AST/Extension+State+and+Hints.