Tim Nelson
2011-Jul-07 16:43 UTC
[asterisk-users] Stripping characters from ${CALLERID(num)} ?
Greetings- On occasion, I have calls coming into an Asterisk 1.2.x system where the ${CALLERID(num)} includes '-'. Ex: 123-456-7890 How can I strip the dashes from the number, leaving me with '1234567890'? I've tried the following which does not appear to be working: Dialplan: exten => _X.,n,Set(PROPERCID=System(echo ${CALLERID(num)} | sed s/\-//g)) exten => _X.,n,NoOp(Fixed proper CID is ${PROPERCID} Console Output: -- Executing [1111111111 at cidmangletest:4] Set("SIP/w.x.y.z-b4d55ce8", "PROPERCID=System(echo 123-456-7890 | sed s/\-//g)") -- Executing [1111111111 at cidmangletest:5] NoOp("SIP/w.x.y.z-b4d55ce8", "Fixed proper CID is System(echo 123-456-7890 | sed s/-//g)") Obviously, I'm trying to throw the CID through sed via System() to strip the dashes. Can anyone explain how to accomplish this? Or even better yet, how to strip the dashes directly in the dialplan without the use of System()? Thanks! --Tim
Steve Edwards
2011-Jul-07 17:47 UTC
[asterisk-users] Stripping characters from ${CALLERID(num)} ?
On Thu, 7 Jul 2011, Tim Nelson wrote:> On occasion, I have calls coming into an Asterisk 1.2.x system where the > ${CALLERID(num)} includes '-'. Ex: > > 123-456-7890 > > How can I strip the dashes from the number, leaving me with > '1234567890'?I would do this in an AGI written in C -- but that's just me... At the start of most of my client's dialplans I do something like: exten = _!.,1, verbose(1,[${EXTEN}@${CONTEXT}]) exten = _!.,n, set(ANI=${EXTEN}) exten = _!.,n, agi(block-ani,--verbose) The block-ani AGI does something like: ) Set the BLOCK channel variable to YES ) Read the ANI channel variable ) Strips leading '+' ) Strips leading '1' ) Strips anything non-numeric ) If the preceding steps changed anything, re-set the ANI channel variable ) Looks up the NPA to see if it should be blocked, return if true ) Looks up the NPA-NXX to see if it should be blocked, return if true ) Looks up the NPA-NXX-XXXX to see if it should be blocked, return if true ) Set the BLOCK channel variable to NO ) Return to the dialplan -- Thanks in advance, ------------------------------------------------------------------------- Steve Edwards sedwards at sedwards.com Voice: +1-760-468-3867 PST Newline Fax: +1-760-731-3000
Bryant Zimmerman
2011-Jul-07 20:13 UTC
[asterisk-users] Stripping characters from ${CALLERID(num)} ?
Here is a simple way to strip the '-' Here is a concept solution. I have not tested the code so there may be some syntax errors. It can work as I am doing stuff like this all the time. This example is using a check to only do the cut if there is more than one field. You may be able to just use step 3 from ctx and have what you want, but I am not sure if it will fall back gracefully if there is only 1 field. No AGI required. exten => mycode,n,Gosub(ctx,1) exten => ctx,1,Set(l_filedCNT=${FIELDQTY(CALLERID(num),-)}) exten => ctx,n,GotoIf($[${MATH(${l_filedCNT}>1)}=TRUE]?DoStrip:SkipStrip) exten => ctx,n(doStrip),Set CALLERID(num)=${CUST(CALLERID(num), -, 1-) exten => ctx,n(doSkip),NoOp(${CALLERID(num)}) Thanks zktech -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20110707/4e47a6d3/attachment.htm>
Bryant Zimmerman
2011-Jul-07 20:22 UTC
[asterisk-users] Stripping characters from ${CALLERID(num)} ?
---------------------------------------- From: "Bryant Zimmerman" <BryantZ at zktech.com> Sent: Thursday, July 07, 2011 4:14 PM To: "Asterisk Users Mailing List - Non-Commercial Discussion" <asterisk-users at lists.digium.com> Subject: Re: [asterisk-users] Stripping characters from ${CALLERID(num)} ? Here is a simple way to strip the '-' Here is a concept solution. I have not tested the code so there may be some syntax errors. It can work as I am doing stuff like this all the time. This example is using a check to only do the cut if there is more than one field. You may be able to just use step 3 from ctx and have what you want, but I am not sure if it will fall back gracefully if there is only 1 field. No AGI required. exten => mycode,n,Gosub(ctx,1) exten => ctx,1,Set(l_filedCNT=${FIELDQTY(CALLERID(num),-)}) exten => ctx,n,GotoIf($[${MATH(${l_filedCNT}>1)}=TRUE]?DoStrip:doSkip) exten => ctx,n(doStrip),Set (CALLERID(num)=${CUT(CALLERID(num), -, 1-)}) exten => ctx,n(doSkip),NoOp(${CALLERID(num)}) Thanks zktech Made a correct in the above to reflect the skip state doSkip vs SkpStrip and made syntax correct to the Set/CUT line. There may still be a few more syntax issues in there. zktech -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20110707/2a3eb3e6/attachment.htm>
Faisal Hanif
2011-Jul-08 04:53 UTC
[asterisk-users] Stripping characters from ${CALLERID(num)} ?
Use Filter command in dia-plan to get numeric only string, Set(MYNEWCLI=${FILTER(0123456789,${CALLERID(number)}) Regards, Faisal -----Original Message----- From: asterisk-users-bounces at lists.digium.com [mailto:asterisk-users-bounces at lists.digium.com] On Behalf Of Tim Nelson Sent: Thursday, July 07, 2011 9:44 PM To: Asterisk Users Mailing List - Non-Commercial Discussion Subject: [asterisk-users] Stripping characters from ${CALLERID(num)} ? Greetings- On occasion, I have calls coming into an Asterisk 1.2.x system where the ${CALLERID(num)} includes '-'. Ex: 123-456-7890 How can I strip the dashes from the number, leaving me with '1234567890'? I've tried the following which does not appear to be working: Dialplan: exten => _X.,n,Set(PROPERCID=System(echo ${CALLERID(num)} | sed s/\-//g)) exten => _X.,n,NoOp(Fixed proper CID is ${PROPERCID} Console Output: -- Executing [1111111111 at cidmangletest:4] Set("SIP/w.x.y.z-b4d55ce8", "PROPERCID=System(echo 123-456-7890 | sed s/\-//g)") -- Executing [1111111111 at cidmangletest:5] NoOp("SIP/w.x.y.z-b4d55ce8", "Fixed proper CID is System(echo 123-456-7890 | sed s/-//g)") Obviously, I'm trying to throw the CID through sed via System() to strip the dashes. Can anyone explain how to accomplish this? Or even better yet, how to strip the dashes directly in the dialplan without the use of System()? Thanks! --Tim -- _____________________________________________________________________ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- New to Asterisk? Join us for a live introductory webinar every Thurs: http://www.asterisk.org/hello asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users