Custom hangup for specific extensions

Is there a way to execute “,h” only for a specific extension?

When my extension 1181@extern hangs up, then this should be executed:

exten => h,1,NoOp(Unlocking 1181)
same => n,Set(DB(locked/1181)=)

and when my extension 1179@extern hangs up, then this should be executed:

exten => h,1,NoOp(Execute Shell Script)
same => n,System(/etc/asterisk/script.sh)

Currently, I have only:

[extern]
exten => 1181,1,Answer()
.......
n,Hangup()

exten => h,1,NoOp(Unlocking 1181)
same => n,Set(DB(locked/1181)=)

If another extension, that is NOT 1181, hangs up, this is still executed:

exten => h,1,NoOp(Unlocking 1181)
same => n,Set(DB(locked/1181)=)

Thank you in advance for your help.

SOLVED:

exten => h,1,NoOp()
same => n,Log(NOTICE, "Call from extension ${EXT_NR} has hung up.")

same => n,GotoIf($["${EXT_NR}" = "1198"]?ext1198,1)
same => n,GotoIf($["${EXT_NR}" = "1181"]?ext1181,1)
same => n,GotoIf($["${EXT_NR}" = "1179"]?ext1179,1)

exten => ext1198,1,NoOp(1198 Detected)
same => n,Playback(/second)

exten => ext1181,1,NoOp(1181 Detected)
same => n,Playback(third)

exten => ext1179,1,NoOp(1179 Detected)
same => n,Playback(third)

So in Asterisk CLI it looks like this:

    -- Executing [h@extern:2] Log("PJSIP/11112-00000071", "NOTICE, "Call from extension 1198 has hung up."") in new stack
[2024-08-08 10:59:52] NOTICE[27376][C-0000004b]: Ext. h:2 @ extern:  "Call from extension 1198 has hung up."
    -- Executing [h@extern:3] GotoIf("PJSIP/11112-00000071", "1?ext1198,1") in new stack
    -- Goto (extern,ext1198,1)
    -- Executing [ext1198@extern:1] NoOp("PJSIP/11112-00000071", "1198 Detected") in new stack

Needed all extension to set like this:

same => n,Set(EXT_NR=XXX)

EXAMPLE in extensions.conf for PJSIP:

[extern]
exten => 1181,1,Answer()
same => n,Set(EXT_NR=1181)  
...

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