How to return from custom code in extensions_custom.conf?

I’m a novice Asterisk user running FREEPBX 12.0.74 with Asterisk 13.7.2.

I’m trying to insert code into the dial plan to email details of every incoming call. I’ve put this code in the from-pstn-custom context in extensions_custom.conf and it’s working fine but I can’t work out how to return after it’s been executed.

As far as I can see, in the default case where [from-pstn-custom] doesn’t exist, the call flow drops through [from-pstn] to the included [ext-did] and thence to ext-did-0001, which is the first context that does any real processing.

So I’ve terminated my custom code with the line:

same => n,Goto(ext-did0001,${EXTEN},1)

hoping that this will make the call continue as if my custom code wasn’t present, but it fails with:

Channel ‘SIP/Sipgate-00000004’ sent to invalid extension but no invalid handler: context,exten,priority=ext-did0001,[my DID],1

I think I’m misunderstanding something basic. Can some kind person show how I can return to the normal call flow?

Post the complete diaplan that you are using.

This is the custom dialplan in extensions_custom.conf:

; Send email on inbound call

[from-pstn-custom]
exten => [DID1],1,Set(DIDOWNER=DID1) ;update DID and DIDowners name
same => n,Set(TZ=Europe/London) ;update Timezone
same => n,Gosub(Notifymail,${EXTEN},1())
same => n,Goto(ext-did0001,${EXTEN},1)

exten => [DID2],1,Set(DIDOWNER=DID2) ;update DID and DIDowners name
same => n,Set(TZ=Europe/London) ;update Timezone
same => n,Gosub(Notifymail,${EXTEN},1())
same => n,Goto(ext-did0001,${EXTEN},1)

[Notifymail]
exten => _X.,1,NoOp(Notifymail)
same => n,Set(CALLTIME=${STRFTIME(${EPOCH},${TZ},%T)})
same => n,Set(CALLDATE=${STRFTIME(${EPOCH},${TZ},%A %d %B %Y)})
same => n,Set(CALLSD=${STRFTIME(${EPOCH},${TZ},%d/%m/%y)})
same => n,Set(CDR(userfield)=${CHANNEL(recvip)})
same => n,Set(CDR(accountcode)=${DIDOWNER})
same => n,Set(INIP=${CHANNEL(recvip)})
same => n,System(/usr/local/bin/mailcall “${DIDOWNER}” “${CALLSD}” “${CALLTIME}” “${EXTEN}” “${CALLERID(num)}” “${CALLERID(name)}” “${INIP}” &)
same => n,Return()

I don’t recommend you use from-pstn-custom. Every line that you put in that context will overwrite a line of existing FreePBX code. Set your trunks to a context of [from-pstn-ashdown] then create a new context like this:

[from-pstn-ashdown]
exten  => [DID1],1,Set(DIDOWNER=DID1) ;update DID and DIDowners name
same => n,Set(TZ=Europe/London) ;update Timezone
same => n,Gosub(Notifymail,${EXTEN},1())
same => n,Goto(from-pstn,${EXTEN},1)

exten => [DID2],1,Set(DIDOWNER=DID2) ;update DID and DIDowners name
same => n,Set(TZ=Europe/London) ;update Timezone
same => n,Gosub(Notifymail,${EXTEN},1())
same => n,Goto(from-pstn,${EXTEN},1)

exten => _X.,n,Goto(from-pstn,${EXTEN},1)

Thank you - that works perfectly. I really appreciate the advice.

I’m still unsure why my original code didn’t work - I need to do some more reading to fully understand the concepts.

Thanks again – that was very helpful.

1 Like