Losing DID when including custom context

Hello,

I use “core show channels concise” to get from it the 8th field, which is the DID i need to display in real time on a webpage.

But i also need to get the tag from the From SIP INVITE header to get it stored in CDR database. For that, as i work with freepbx that does not allow to edit extensions.conf, i added this in /etc/asterisk/extensions_custom.conf file :

[from-pstn-custom]
exten => _X.,1,NOOP("CDR Entered [from-trunk-custom]")
exten => _X.,n,Set(fromstr=${SIP_HEADER(From)})
exten => _X.,n,Set(longtag=${CUT(fromstr,\;,2)})
exten => _X.,n,Set(tagok=${CUT(longtag,\=,2)})
exten => _X.,n,Set(CDR(tag)=${tagok})

It works well, i do have the tag i need in the CDRs. But now, since i added this from-pstn-custom context, i have a problem with “core show channels concise” : the 8th field (DID) is now replaced by the extension that is ringing, or by the extension that picked up the call.

It seems to be because of these inclusions, in extensions.conf :

[from-pstn]
include => from-pstn-custom     ; create this context in extensions_custom.conf to include customizations
include => ext-did 
include => ext-did-post-custom 
include => from-did-direct
include => ext-did-catchall     ; THIS MUST COME AFTER ext-did

Maybe everything that is after the inclusion of from-pstn-custom could have not been executed, that would explain that some vars are not set, whereas they should.
I tried a Goto from-pstn at the end of from-pstn-custom, to be sure the other lines of from-pstn will be executed, but it causes an infinite loop. Also tried to put the 4 includes following the inclusion of from-pstn-custom, directly at the end of from-pstn-custom, doesnt work.

Would you have any idea of how to get this right ? Or maybe a whole other way to get these two vars (DID in real time, Tag in CDRs), as i can get on or the other but not both. Would be better to avoid AMI as the current project already runs with calls to the CLI.

This is under Asterisk 11.25.1 with FreePBX 13.0.190.19, Debian Linux 3.16.0-4-amd64

Thank you

I presume you mean the user part of the request URI. That becomes the initial extension. CDRs log the final extension. You will need to make your dialplan save ${EXTEN} before Goto or Gosub changes it.

Thanks David for your answer;

By DID, i mean the 01xxxxxxxx value inside the To header of the sip INVITE message: To: <sip:01xxxxxxxx@62.x.x.x>

I have no problem getting this value by parsing the result of the CLI command core show channels concise :

Local/10@from-queue-0000001b;1!from-queue!997!1!Ringing!AppQueue!(Outgoing Line)!01xxxxxxxx!!!3!0!(None)!1502831943.113

The problem is that in this last output, 01xxxxxxxx value is replaced by the final extension (10) when i include a custom context. Then, this is what core show channels concise shows :

Local/10@from-queue-00000020;1!from-queue!997!1!Ringing!AppQueue!(Outgoing Line)!10!!!3!5!(None)!1502832531.134

I dont have the DID anymore, but the final extension. My guess was that the few includes following the include => from-pstn-custom could not be loaded, for some reason

The goal here would be to have the right DID value (01xxxxxxxx) even when i include a custom context

The user in the To is not used for the CDR. As I said, the value in the CDR the value of ${EXTEN} when the CDR is output, and the initial value of that is the user of part of the request URI.

If you want the initial extension, you will need to copy it into the user field,or a custom field. If you really want the To user, you will have to get the heaeder and parse it.