exten => s,n,Set(DB(test/${CAllERID(NUMBER)})=${TimeStamp

Hey guys,

I am new to the forum. I am trying to read unix timestamp and assign it to a variable via Asterisk CMD but I can’t find anything on the web that suggests I can read unix time stamp wtih Asterisk CMD; How can I achive that?

I want to set the key name to be the caller ID and the value to be the unix time stamp (e.g. 20080301132020 which is 2008/03/01: 1 p.m. 20 min and 20 seconds)

Is that possible via Asterisk CMD at all?

Thanks

exten => s,n,Set(DB(test/${CAllERID(num)})=${EPOCH})

Not tested it but form memory should work

Ian

Ian,

That’s great Ian. Thanks. However, for some reason the key name doesn’t show up properly. I could be wrong but here is the outcome when I try to read the key apparently the key name which should be the callerid doesn’t show up. Here is my full script:

[custom-test]
exten => s,1,Answer()
exten => s,n,Playback(welcome)
exten => s,n,Set(DB(test/${CAllERID(num)})=${EPOCH})
exten => s,n,Set(COUNT=${DB(test/${CALLERID(number)})
exten => s,n,SayDigits(${COUNT}

Also, how about if I want to prefix alphabets to CallerID? Can I do this:
exten => s,n,Set(DB(test/${Caller+CAllERID(num)})=${EPOCH})

Try

[custom-test]
exten => s,1,Answer()
exten => s,n,Playback(welcome)
exten => s,n,Noop(${EPOCH})
exten => s,n,Set(DB(test/${CALLERID(num)})=${EPOCH})
exten => s,n,Set(COUNT=${DB(test/${CALLERID(num)})
exten => s,n,Noop(${COUNT})
exten => s,n,SayDigits(${COUNT}

Also, how about if I want to prefix alphabets to CallerID? Can I do this:
exten => s,n,Set(DB(test/CALLER${CALLERID(num)})=${EPOCH})

You need to be sure that you have the letters cAsE correct as Linux is CaSe sensitive

Ian

Noop just does the trick. Thanks again. Now I am trying to use the GotoIF function to play a (welcome) msg if it is varified that it’s been less than 5 mins (300 secs) since the caller last called. Else, the system will announce (goodbye). I have problem with bolean and IF function in voipinfo.org is not detailed enough.

exten => s,1,Answer()
exten => s,n,Set(readVarify=${DB(test/${CALLERID(num)})
exten => s,n,GotoIf($[${ISNULL(${readVarify})}]?:continue)
exten => s,n,Noop(${EPOCH}
exten => s,n,Set(DB(test/currentTime)=${EPOCH})

exten => s,n,GotoIf($[(${currentTime} - ${readVarify})] < 300:continue)
exten => s,n,Playback(goodbye)

exten => s,n(continue),NoOp()
exten => s,n,Playback(welcome)
exten => s,n,Noop(${EPOCH})
exten => s,n,Set(DB(test/${CALLERID(num)})=${EPOCH})
exten => s,n,Set(COUNT=${DB(test/${CALLERID(num)})
exten => s,n,Noop(${COUNT})
exten => s,n,SayDigits(${COUNT}

Hi

Gotoif and If compare 2 values, you need to do the Math first, using the Math function voip-info.org/wiki/index.php … +func+math
Then see if the returned value is greater than 300

Ian

Great. Thanks. I got that sorted out. But this last GotoIF is acting weired. Whether it returns 1 (false) or 0 (true) it still goes to ?continueTwo context. I have included the full script here. It should flow as follows:

1- Read current time.
2- Pull up the callerID and it’s value (last call EPOCH).
3- If it is null go ahead and save the current time/welcome and hangup.
4- If it is not Null then do the MATH and do a GotoIF.
- Based on the values returned, if the last call was more than a week ago then just hangup. If the call was less than a week (epoch < 604800) then go ahead with the welcome msg and hangup.

[custom-test]

exten => s,1,Noop(${EPOCH})
exten => s,n,Set(DB(test/currentTime)=${EPOCH})
exten => s,n,Set(currentTime=${DB(test/currentTime)})
exten => s,n,Noop(${currentTime})
exten => s,n,SayDigits(${currentTime})

exten => s,n,Answer()
exten => s,n,Noop()
exten => s,n,Set(readVarify=${DB(test/${CALLERID(num)})
exten => s,n,SayDigits(${readVarify})

exten => s,n,GotoIf($[${ISNULL(${readVarify})}]?continueTwo:continueOne)

exten => s,n(continueOne),Set(timeDiff=${MATH(${currentTime}-${readVarify},int)})
exten => s,n,GotoIf,($[${timeDiff} < 604800]?continueTwo:bye)
exten => s,n(bye),Playback(welcome)
exten => s,n,Hangup()

exten => s,n(continueTwo),Answer()
exten => s,n,Playback(welcome)
exten => s,n,Noop(${EPOCH})
exten => s,n,Set(DB(test/${CALLERID(num)})=${EPOCH})
exten => s,n,Set(COUNT=${DB(test/${CALLERID(num)})
exten => s,n,Noop(${COUNT})
exten => s,n,SayDigits(${COUNT})
exten => s,n,Hangup()

Hi Could you post the verbose output of a call pasing through so we can see where it jumps

Also post the output off show dialplan custom-test

and finally add some noops in the dialplan so we can see what the values are as it passes through, this will check your math is working

Ian

Here is what I got when I called from a new number. The picture shows three calls. First on is okey. Second one is okey too because it falls within 120 seconds. But the thrid call shouldn’t have gone to continueTwo.

Please click on the following link to see the snapshot:

a2billing2asterisk.googlepages.c … ;init:.jpg

Thanks,

Hi

Im guessing but I think this may be the problem

you need to make sure what you are compaing aginst is an interger. My guess is its not and thats the problem.

Ian

exten => s,n,GotoIf,($[${timeDiff} < 120]?continueTwo:bye)

In my trial, timeDiff for the last call = 640 seconds. So, that is shown all right. But the line above just doesn’t go to context “bye” EVEN THOUGH it returns 0 which is false for the condition. This is all integers. EPOCH is integer and so is 120. :cry: :cry: :cry: :angry: :angry: :angry: :open_mouth: :open_mouth: :open_mouth:

Thanks for the input once again.

Hm yep your right just looked throug it again.

Ok to prove whats going on I would add values instead of using variables.

fo for example add the line

exten => s,n,GotoIf,($[640 < 120]?continueTwo:bye)

and see what you get.

Ian

Great suggestion, I tried it and it works. If I get rid of the timeDiff variable and put a solid integer then it works fine. Result is still 0 and the phone hangsup as expected. I also tried this:

exten => s,n,GotoIf,($[{timeDiff} < 12]?continueTwo:bye) -No $ sign

Still it makes no difference. Is there anything I can to debug it further or get more print out?

Thanks

By the way, I also tried Noop (${timeDiff}) and it returns the right integer before the GotoIf statement. Also, the Noop ($[${timeDiff} < 120]) returns 0 which is right. But, it has already jumped to whatever is after the ? mark rather than :

I find this very odd.

I found the problem; it has to do with the comma after the GotoIf. After removing it, all works just fine.

Thanks again Ian.

OMG I haddnt even noticed it. Isnt it maddening, when the problem is just a tiny typo. :confused:

Ian

Script works fine but I need to add to it now. I have never encountered a problem like this even though I have done a great deal of programming. I guess it has to do with Asterisk. How does one tackle the problem of simultaneous calls coming in with this phrase:

exten => s,n,Set(DB(test/currentTime)=${EPOCH})

Every time a call comes in the variable currentTime will be over written and the first call’s script (which might not have already finished) will miss up big time if this variable is over-written. Is there any way to pick up a random variable? or any other trick to over come this?

Thanks

What is the purpose of the test/currenttime key? If the variable is supposed to follow the channel, just set it as a channel variable instead…

Well, the key sets the current time and then checks to see if the caller has called before or not. If they have called then checks to see if it has been 24 hours or not and based on that directs the call to a different place. Now, if the number has never contacted the system then it should input the Current Time Key. So, basically I need to get the time at the begining of the call and store it in a variable and get to it at a later time. What do you mean by channel variable?

Thanks for the feedback.

When you say later time, you mean in a subsequent call from the same callerid, or the current call? ianplain’s 2nd post in this thread has examples for both.