Skip to content

Instantly share code, notes, and snippets.

@lgaetz
Last active November 5, 2022 14:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lgaetz/76006451910295a4625555361c9b5085 to your computer and use it in GitHub Desktop.
Save lgaetz/76006451910295a4625555361c9b5085 to your computer and use it in GitHub Desktop.
; FreePBX dialplan to create a dynamic voicemail blast group.
; Place this in /etc/asterisk/extensions_custom.conf and reload
; GNU GPL3+
; latest version: https://gist.github.com/lgaetz/76006451910295a4625555361c9b5085
; version history 2022-11-04 First commit
; 2022-11-05 Added recording playback to toggle
[from-internal-custom]
; Create feature code previx with hints. Each extension can enable/disable vm group membership by dialing the
; feature code prefix to their extension number. If assigned to a BLF, the LED will indicate group membership.
; An AstDB key is generated or deleted to indicate dyn vm blast group membership
exten => _**55XXXX,hint,Custom:DYNVM_${EXTEN:4} ; set up hint for 4 digit extensions and strip leading 4 digits
exten => _**55XXXX,1,Noop(Entering user defined context from-internal-custom in extensions_custom.conf)
exten => _**55XXXX,n,Gosub(toggle-dynvm-ext,${EXTEN:4},1)
exten => _**55XXXX,n,hangup
[toggle-dynvm-ext]
; context to determine the current state of the extension group membership and change to opposite
exten => _.,1,Noop()
exten => _.,n,GotoIF($[${DB_EXISTS(dynvm/${EXTEN})}]?unset:set)
exten => _.,n,Return
exten => _.,n(set),Set(DEVICE_STATE(Custom:DYNVM_${EXTEN})=BUSY)
exten => _.,n,set(DB(dynvm/${EXTEN})=1)
exten => _.,n,Playback(activated)
exten => _.,n,Return
exten => _.,n(unset),Set(DEVICE_STATE(Custom:DYNVM_${EXTEN})=NOT_INUSE)
exten => _.,n,set(foo=${DB_DELETE(dynvm/${EXTEN})})
exten => _.,n,Playback(de-activated)
exten => _.,n,Return
[dial-dynvm-group]
; This destination is used to actually leave the VM blast message. You must create at least one VM Blast group in the
; FreePBX GUI in order for the necessary contexts to be created, it need not be used. The dynamic vm blast group membership is
; determined from the astdb at the time this context is called. In FreePBX create a Custom Destination
; with a dial string of the format "dial-dynvm-group,s,1" without quotes
exten => s,1,Noop()
exten => s,n,Noop(List of extensions to VMBlast ${DB_KEYS(dynvm)})
exten => s,n,set(extarray=${DB_KEYS(dynvm)})
exten => s,n,SET(ext=)
; exten => s,n,SET(ext=&7010) ; uncomment and edit to include extension(s) that are always included
exten => s,n,While($["${SET(ext=${SHIFT(extarray)})}" != ""])
exten => s,n,Macro(get-vmcontext,${ext})
exten => s,n,Set(GRPLIST=${GRPLIST}&${ext}@${VMCONTEXT})
exten => s,n,EndWhile()
exten => s,n,Noop(vm dial string ${GRPLIST})
exten => s,n,Playback(T-to-leave-msg&after-the-tone)
exten => s,n,Goto(app-vmblast,1,1) ; bypasses dtmf confirmation
exten => s,n,hangup()
@lgaetz
Copy link
Author

lgaetz commented Nov 4, 2022

Obvious issues with first commit

  • no validation that extension numbers are legit, could prob use the vmcontext macro to figure that out
  • will fail silently if there are no extensions enabled,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment