Skip to content

Instantly share code, notes, and snippets.

@lgaetz
Last active February 24, 2022 13:16
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/543da144d051a353ca0fab93b7f34cf2 to your computer and use it in GitHub Desktop.
Save lgaetz/543da144d051a353ca0fab93b7f34cf2 to your computer and use it in GitHub Desktop.
; Feature code prefix to allow FreePBX user to set and unset a dobro-callflow
; it works similarly to a Call Flow Conrol, except the phone user sets the
; destination number when enabling
;
; Latest version:
; https://gist.github.com/lgaetz/543da144d051a353ca0fab93b7f34cf2
;
; Usage:
; Dialplan below goes in the file
; /etc/asterisk/extensions_custom.conf
; and then create a Custom Destination with the details indicated. The idea
; is that you have a dobro-callflow of an arbitrary sequence of digits, say 2000.
; you program a blf with "6502000" and create a Custom Destination with arg "2000"
; The user then dials the feature code to set the redirect and again to toggle off
;
; License: GNU GPL2
;
; Copyright Sangoma Technologies 2019
; Created for Igor Dobrosavljevic at Grand Consulting and shared with permission
;
; Version History
; 2019-03-21 First commit by lgaetz
;
[from-internal-custom]
; define prefix for toggling the office redirect
; dial 6502000 for office 2000 or program blf
exten => _650X!,1,Noop(Entering context from-internal-custom in extensions_custom.conf)
exten => _650X!,n,Goto(set-office-redirect,${EXTEN:3},1) ; strip first 3 digits and pass rest to redirect context
exten => _650X!,hint,Custom:OFFICEFWD${EXTEN:3} ; create hint for blf
; end context [from-internal-custom]
[set-office-redirect]
exten => _X!,1,Noop(Entering context set-office-redirect in extensions_custom.conf - redirect for dobro-callflow ${EXTEN})
exten => _X!,n,set(current_val=${DB(office-redirect/${EXTEN})}) ; uncomment for dbug
exten => _X!,n,GotoIF($[${DB_EXISTS(office-redirect/${EXTEN})}]?unset:set)
; redirect is not set so we will set it and change hint here
exten => _X!,n(set),Playback(please-enter-the&call-forward&number&for&office)
exten => _X!,n,SayNumber(${EXTEN})
exten => _X!,n,Read(DB(office-redirect/${EXTEN}),then-press-pound,5)
exten => _X!,n,Playback(call-forward&for&office)
exten => _X!,n,SayNumber(${EXTEN})
exten => _X!,n,Playback(has-been-set-to)
exten => _X!,n,SayDigits(${DB(office-redirect/${EXTEN})})
exten => _X!,n,Set(DEVICE_STATE(Custom:OFFICEFWD${EXTEN})=BUSY)
exten => _X!,n,set(current_val=${DB(office-redirect/${EXTEN})}) ; uncomment for dbug
exten => _X!,n,Hangup()
; redirect is already set, so delete database entry and change hint
exten => _X!,n(unset),set(foo=${DB_DELETE(office-redirect/${EXTEN})})
exten => _X!,n,Set(DEVICE_STATE(Custom:OFFICEFWD${EXTEN})=NOT_INUSE)
exten => _X!,n,set(current_val=${DB(office-redirect/${EXTEN})}) ; uncomment for dbug
exten => _X!,n,Playback(call-forward&number&for&office)
exten => _X!,n,SayNumber(${EXTEN})
exten => _X!,n,Playback(has-been-cleared&goodbye)
exten => _X!,n,Hangup()
; end context [set-office-redirect]
[check-office-redirect]
; use with custom destination
; with target of format "check-office-redirect,s,1(2000)" (without quotes)
; pass arg in parentheses for the dobro-callflow number
; enable the return option and choose the destination for the call to go when dobro-callflow is unset
exten => s,1,Noop(Entering context check-office-redirect in extensions_custom.conf - checking redirect for office ${ARG1})
exten => s,n,Answer
exten => s,n,GotoIF($[${DB_EXISTS(office-redirect/${ARG1})}]?from-internal,${DB(office-redirect/${ARG1})},1)
exten => s,n,Return
; end context [check-office-redirect]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment