[asterisk-users] Get context with hangup handler

Steve Edwards asterisk.org at sedwards.com
Wed Jan 5 23:21:07 CST 2022


On Wed, 5 Jan 2022, Dovid Bender wrote:

> I thought of this but that would mean I would need to add this to the 
> beginning of every context which I can do, but I was trying to avoid.

Every extension in every context.

Or maybe get funky with a wildcard extension with priority = 1 and 
starting all of your real extensions with priority = 3. Something like 
this (which uses gosub() just for ease of testing):

; test wildcard extension
         same = n,                       gosub(wildcard-extension,1234,1)
         same = n,                       gosub(wildcard-extension,s,1)
         same = n,                       gosub(wildcard-extension,testing,1)
         same = n,                       hangup()

[wildcard-extension]
; save the current context so it can be used in the hangup handler
         exten = _!.,1,                  verbose(1,[${EXTEN}@${CONTEXT}])
         same = n,                       set(LAST-CONTEXT=${CONTEXT})
         same = 4,                       return

; note all the 'real' extensions start with priority = 3
         exten = 1234,3,                 verbose(1,[${EXTEN}@${CONTEXT}!${PRIORITY}])

 	exten = s,3,                    verbose(1,[${EXTEN}@${CONTEXT}!${PRIORITY}])

         exten = testing,3,              verbose(1,[${EXTEN}@${CONTEXT}!${PRIORITY}])

; be explicit with 'h' so it doesn't get handled by the wildcard extension
         exten = h,1,                    verbose(1,[${EXTEN}@${CONTEXT}])
         same = n,                       hangup()

Hopefully somebody else has a more elegant solution.

-- 
Thanks in advance,
-------------------------------------------------------------------------
Steve Edwards       sedwards at sedwards.com      Voice: +1-760-468-3867 PST
             https://www.linkedin.com/in/steve-edwards-4244281



More information about the asterisk-users mailing list