Access custom vars in queue does not work?

I use Asterisk 1.4.29 an FreePBX 2.7.0.3.

I set some custom vars in extensions_custom.conf:

[from-pstn-custom]
exten => _X.,1,NoOp(Set custom vars)
exten => _X.,n,Set(_MY_CALLER=${CALLERID(num)}|_MY_CALLED=${EXTEN})

I can access these vars without problems in a ringgroup but not in a queue.

Why?

doing the above is likely to break FreePBX - you are going to ignore priorities 1 and 2 in most included dialplans by doing that which will result in very strange and hard to track down errors.

If you want to do something like this, create a new context, point your trunk to it instead from-pstn, and then after yo do your stuff, got priority 1 of from-pstn as if you had never been anywhere else…

Thanks for your answer :slight_smile:

Im glad, the above works for some months now without problems but i like to try your approach.

How do i create a custom context?
I did not find such option in the freepbx panel.

Or should i create it in extensions_custom.conf like:

[my-custom-context]
exten => _X.,1,NoOp(Set custom vars)
exten => _X.,n,Set(_MY_CALLER=${CALLERID(num)}|_MY_CALLED=${EXTEN})

If so, how do i use it?

I tried this now but it does not work.

[from-pstn-custom]
include => my-custom-context

[my-custom-context]
exten => _X.,1,NoOp(Set custom vars)
exten => _X.,n,Set(_MY_CALLER=${CALLERID(num)}|_MY_CALLED=${EXTEN})

Edit:

I got it work by using global variables in my first approach.

[from-pstn-custom]
exten => _X.,1,NoOp(Set custom vars)
exten => _X.,n,Set(__MY_CALLER=${CALLERID(num)}|__MY_CALLED=${EXTEN})

Could i get in problems using global vars when havin several concurrent calls?

not what I meant,

my-custom-cnotext should have a goto at the end:

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

then in your inbound trunk set:

context=my-custom-context

and get rid of that include

Ah. OK. Thanks. I got that.

I added it to extensions_custom.conf:

[from-custom]
exten => _X.,1,NoOp(Set custom vars)
exten => _X.,n,Set(_MY_CALLER=${CALLERID(num)}|_MY_CALLED=${EXTEN})
exten => _X.,n,Goto(from-pstn,1,${EXTEN})

The first part works.

My vars are loaded but than there seems to be a problem with the goto, because the call is canceled.

This is the log:

    -- Got SIP response 405 "Method Not Allowed" back from 192.168.0.186
    -- Executing [[email protected]:1] NoOp("SIP/ACCOUNT1-00002251", "Set custom vars") in new stack
    -- Executing [[email protected]from-custom:2] Set("SIP/ACCOUNT1-00002251", "_MY_CALLER=030123456789|_MY_CALLED=491805123456789") in new stack
    -- Executing [[email protected]:3] Goto("SIP/ACCOUNT1-00002251", "from-pstn|1|491805123456789") in new stack
    -- Goto (from-pstn,1,2147483647)
  == Auto fallthrough, channel 'SIP/ACCOUNT1-00002251' status is 'UNKNOWN'
    -- Executing [[email protected]:1] NoOp("SIP/ACCOUNT1-00002251", "Catch-All DID Match - Found h - You probably want a DID for this.") in new stack
    -- Executing [[email protected]:2] Goto("SIP/ACCOUNT1-00002251", "ext-did|s|1") in new stack
    -- Goto (ext-did,s,1)
    -- Executing [[email protected]:1] Set("SIP/ACCOUNT1-00002251", "__FROM_DID=s") in new stack
    -- Executing [[email protected]:2] Gosub("SIP/ACCOUNT1-00002251", "app-blacklist-check|s|1") in new stack
    -- Executing [[email protected]:1] LookupBlacklist("SIP/ACCOUNT1-00002251", "") in new stack
    -- Executing [[email protected]:2] GotoIf("SIP/ACCOUNT1-00002251", "0?blacklisted") in new stack
    -- Executing [[email protected]:3] Set("SIP/ACCOUNT1-00002251", "CALLED_BLACKLIST=1") in new stack
    -- Executing [[email protected]:4] Return("SIP/ACCOUNT1-00002251", "") in new stack
    -- Executing [[email protected]:3] ExecIf("SIP/ACCOUNT1-00002251", "0 |Set|CALLERID(name)=030123456789") in new stack
    -- Executing [[email protected]:4] Set("SIP/ACCOUNT1-00002251", "__CALLINGPRES_SV=allowed_not_screened") in new stack
    -- Executing [[email protected]:5] SetCallerPres("SIP/ACCOUNT1-00002251", "allowed_not_screened") in new stack
    -- Executing [[email protected]:6] Goto("SIP/ACCOUNT1-00002251", "from-did-direct|2003|1") in new stack
    -- Goto (from-did-direct,2003,1)
    -- Executing [[email protected]:1] Macro("SIP/ACCOUNT1-00002251", "exten-vm|novm|2003") in new stack
    -- Executing [[email protected]:1] Macro("SIP/ACCOUNT1-00002251", "user-callerid|") in new stack
    -- Executing [[email protected]:1] Set("SIP/ACCOUNT1-00002251", "AMPUSER=030123456789") in new stack
    -- Executing [[email protected]:2] Goto("SIP/ACCOUNT1-00002251", "|return|1") in new stack
    -- Goto (from-did-direct,return,1)

The problem seems to be, that exten is changed to 2147483647 (i dont know this number) in goto?

the number is 2 ^ 31 - 1 which suggests some sort of overflow in a 32 bit register.

Your dial plan says:

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

which is being interpreted as Goto(context,extension,priority)

so you are sending this to priority “491805123456789” which, being larger than the 32 register, it seems that asterisk is handling the error for you by simply cutting it to the largest value of 2147483647… obviously not what you intended.

try rewriting the Goto command

Thanks a lot again! :slight_smile:

I now have te setup i wanted using global vars. I hope this doen not lead in problems.

P.S.: I copy/pasted from your post :wink: