Using Dynamic Routes to branch call flow based on extension state

The “hint” in Asterisk is a dialplan mechanism that is defined to track the state of one or more resources such as a local device. Many things in FreePBX dialplan have an associated hint such as voicemail boxes, toggle feature codes, etc. It’s the hint that determines the behavior of the LED when you program a BLF button on a phone, but it can have other uses as well. From the Asterisk console run the command:

core show hints

and get a list of all hints available on the system. Some will be obvious such as a local extension or a parking slot:

[email protected]      : PJSIP/6002&Custom:DN  State:Idle            Presence:not_set         Watchers  0
[email protected]       : park:[email protected]   State:Idle            Presence:not_set         Watchers  0

Others look a bit more cryptic such as these patterns for queue login/pause toggles:

_*45*[email protected]  : ${DB(AMPUSER/${EXTEN  State:Unavailable     Presence:                Watchers  0
_*46*[email protected]  : ${DB(AMPUSER/${EXTEN  State:Unavailable     Presence:                Watchers  0

The point of this post is to show how one might set up a Dynamic Route to branch a call flow based on a hint state. I’m pressed to come up with a good use case for this one, but I do recall a conversation from quite a while ago that started out with the words, “Our old analog PBX we installed in 1987 had this feature where …”. The ask was to provide a setup for a virtual public meeting that allowed inbound callers into a conference without a PIN, and ‘security’ was provided by means of blocking them them if the conference was not already in progress. Of course local extensions were free to call in unrestricted. When meeting time came, a local extension dials in, which unlocks it for all the external callers.

So knowing that local conferences have an associated hint, one can query the state of a hint with the Asterisk function EXTENSION_STATE. Hint state will one of these values: UNKNOWN, NOT_INUSE, INUSE, BUSY, INVALID, UNAVAILABLE, RINGING, RINGINUSE, HOLDINUSE, ONHOLD.

Create a dynroute with ‘Source Type’ set to Asterisk Variable, and use the expression:

${EXTENSION_STATE([email protected])}

where [email protected] is the hint you want to monitor from ‘core show hints’ above. Since pretty much all hints are included in from-internal, you can use [email protected] where the x’s correspond to the dialed digits. Then create a Match Entry for ‘INUSE’ to go to the conference. All other cases will go to hangup with the default destination. Like this:

It was not part of the conversation years ago when setting this up, but if doing this today I would set up a second dynroute to check the number of users in the conference with CONFBRIDGE_INFO and dump any calls that exceed some threshold to hangup in order to prevent it from getting accidentally DOS’d.

You can use the same technique to check state of a local extension, or a voicemail box, parking lot, etc.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.