Discussion:
[Asterisk-Users] passing variables to h extension
Simone Cittadini
2005-09-13 15:05:46 UTC
Permalink
Is there a way to pass variables/arguments to the h extension ?

for example :

[default]

exten => _1098933X.,1,NoOp(CARRIER TWT->TIM, EXTEN: ${EXTEN}},
SIPCALLID: ${SIPCALLID}, SIPDOMAIN: ${SIPDOMAIN})
exten => _1098933X.,2,SetVar(_PROVA="bla")
[lot of stuff, agi, goto, tricks and magic that happens]
exten => _1098933X.,10,Dial(${CHAN_DEST},,L(3600000:3599900)) <- don't
mind L, a quick hack for dtmf not working with sip
exten => _1098933X.,11,Hangup
exten => _1098933X.,12,Playback(no-credit)
exten => _1098933X.,13,Hangup


exten => h,1,NoOp(${PROVA})


When the calls hangup, no "bla" is printed on screen, I think it's fine,
since "the variable is automatically trashed when the channel is
hungup.", sigh ...

But I need to pass some variables from the calling extension to an AGI,
like :

exten => h,1,DeadAGI(update-credit.py|${CALLER}|${CALLED}|${CARRIER})

in order to decrement the amount of credit for each customer after every
call.

I've seen that in others prepaid systems built over asterisk the
updating of available credit is done in a cron job, have I to take it as
a sign that "real-time billing" is impossible ? Hope I haven't to ....
Tony Mountifield
2005-09-13 16:37:29 UTC
Permalink
Post by Simone Cittadini
Is there a way to pass variables/arguments to the h extension ?
[default]
exten => _1098933X.,1,NoOp(CARRIER TWT->TIM, EXTEN: ${EXTEN}},
SIPCALLID: ${SIPCALLID}, SIPDOMAIN: ${SIPDOMAIN})
exten => _1098933X.,2,SetVar(_PROVA="bla")
[lot of stuff, agi, goto, tricks and magic that happens]
exten => _1098933X.,10,Dial(${CHAN_DEST},,L(3600000:3599900)) <- don't
mind L, a quick hack for dtmf not working with sip
exten => _1098933X.,11,Hangup
exten => _1098933X.,12,Playback(no-credit)
exten => _1098933X.,13,Hangup
exten => h,1,NoOp(${PROVA})
When the calls hangup, no "bla" is printed on screen, I think it's fine,
since "the variable is automatically trashed when the channel is
hungup.", sigh ...
It works for me (using CVS HEAD, but I'm sure it's worked in the past for
me on Stable too). I think there must be some other reason it's not working
for you.

Just done a little test for it, as follows...

My extensions.conf:

[vartest]
exten => _X.,1,SetVar(FRED=hello)
exten => _X.,2,NoOp(FRED=${FRED})
exten => _X.,3,Playback(demo-congrats)
exten => _X.,4,Hangup

exten => h,1,NoOp(FRED=${FRED})

Console output:

-- Executing Goto("SIP/2002-238e", "vartest|8200|1") in new stack
-- Goto (vartest,8200,1)
-- Executing SetVar("SIP/2002-238e", "FRED=hello") in new stack
-- Executing NoOp("SIP/2002-238e", "FRED=hello") in new stack
-- Executing Playback("SIP/2002-238e", "demo-congrats") in new stack
-- Playing 'demo-congrats' (language 'en')
== Spawn extension (vartest, 8200, 3) exited non-zero on 'SIP/2002-238e'
-- Executing NoOp("SIP/2002-238e", "FRED=hello") in new stack

-- Executing Goto("SIP/2002-9d08", "vartest|8200|1") in new stack
-- Goto (vartest,8200,1)
-- Executing SetVar("SIP/2002-9d08", "FRED=hello") in new stack
-- Executing NoOp("SIP/2002-9d08", "FRED=hello") in new stack
-- Executing Playback("SIP/2002-9d08", "demo-congrats") in new stack
-- Playing 'demo-congrats' (language 'en')
-- Executing Hangup("SIP/2002-9d08", "") in new stack
== Spawn extension (vartest, 8200, 4) exited non-zero on 'SIP/2002-9d08'
-- Executing NoOp("SIP/2002-9d08", "FRED=hello") in new stack

On the first call, I hung up during the announcement. On the second,
I let the system hang up on me. The h extension showed the variable
value in both cases.

Cheers
Tony
--
Tony Mountifield
Work: ***@softins.co.uk - http://www.softins.co.uk
Play: ***@mountifield.org - http://tony.mountifield.org
Simone Cittadini
2005-09-14 09:00:00 UTC
Permalink
Post by Tony Mountifield
It works for me (using CVS HEAD, but I'm sure it's worked in the past for
me on Stable too). I think there must be some other reason it's not working
for you.
Just done a little test for it, as follows...
[vartest]
exten => _X.,1,SetVar(FRED=hello)
exten => _X.,2,NoOp(FRED=${FRED})
exten => _X.,3,Playback(demo-congrats)
exten => _X.,4,Hangup
exten => h,1,NoOp(FRED=${FRED})
Yes it always worked also for me, using 1.2-beta1, typing error in noops
used for debug was having me look in the wrong place to set the vars !
Sorry for the rtfm question then ....

anyway I now wonder even more why accounting is done via cron jobs in
php-agi apps you find around .... isn't that only a waste of resources,
since you have to tag in some way calls already accounted ?

Gary Reuter
2005-09-13 17:53:08 UTC
Permalink
I have something similar to do SMS voicemail notifications... I do not use
any underscores when I set the variable and it works fine in the 'h'
extension.
Post by Simone Cittadini
Is there a way to pass variables/arguments to the h extension ?
[default]
exten => _1098933X.,1,NoOp(CARRIER TWT->TIM, EXTEN: ${EXTEN}},
SIPCALLID: ${SIPCALLID}, SIPDOMAIN: ${SIPDOMAIN})
exten => _1098933X.,2,SetVar(_PROVA="bla")
[lot of stuff, agi, goto, tricks and magic that happens]
exten => _1098933X.,10,Dial(${CHAN_DEST},,L(3600000:3599900)) <- don't
mind L, a quick hack for dtmf not working with sip
exten => _1098933X.,11,Hangup
exten => _1098933X.,12,Playback(no-credit)
exten => _1098933X.,13,Hangup
exten => h,1,NoOp(${PROVA})
When the calls hangup, no "bla" is printed on screen, I think it's fine,
since "the variable is automatically trashed when the channel is
hungup.", sigh ...
But I need to pass some variables from the calling extension to an AGI,
exten => h,1,DeadAGI(update-credit.py|${CALLER}|${CALLED}|${CARRIER})
in order to decrement the amount of credit for each customer after every
call.
I've seen that in others prepaid systems built over asterisk the
updating of available credit is done in a cron job, have I to take it as
a sign that "real-time billing" is impossible ? Hope I haven't to ....
_______________________________________________
--Bandwidth and Colocation sponsored by Easynews.com <http://Easynews.com>--
Asterisk-Users mailing list
http://lists.digium.com/mailman/listinfo/asterisk-users
http://lists.digium.com/mailman/listinfo/asterisk-users
Continue reading on narkive:
Loading...