Stripping the "+" char. off of dialed string

Discussion in 'General' started by protenus, Jan 19, 2009.

  1. protenus

    Joined:
    Feb 28, 2007
    Messages:
    44
    Likes Received:
    0
    We are using Elastix with Nokia SIP clients (e71, e90, etc.), and are facing a challenge to get things working correctly.

    When users dial from their phonebook, they are sending numbers in +NNNXXXXXXX format (including the "+").

    Stripping off the country code, adding a leading 0, etc is not a problem. but I can not seem to do anything to strip the "+" correctly...


    When i put
    Code:
    [+]|.
    in the route, it acually strips the "+" as well as the next three characters!

    Any advice on how to handle this?
     
  2. wiseoldowl

    Joined:
    Aug 19, 2008
    Messages:
    251
    Likes Received:
    0
    Try this and please let me know if it works - I haven't tested it but I think it will work. First, add a context to /etc/asterisk/extensions_custom.conf -

    Code:
    [custom-strip-plus]
    exten => _+.,1,Noop(Stripping + from start of number)
    exten => _+.,n,Goto(from-internal,${EXTEN:1},1)
    exten => _.,1,Goto(from-internal,${EXTEN},1)
    exten => h,1,Hangup()
    
    Now go into one of your extensions and change the context from from-internal to custom-strip-plus - Make a test call from that extension and see if it works. If it does, change the context in all your other extensions that are affected by this problem. If it doesn't, try changing the _+. to _+X. in the first two lines, and see if that makes any difference. If you need to add any digits, such as "011" or "00" to the start of the dialed number in place of the +, simply put them immediately before ${EXTEN:1} (between the comma and the $) in the second line. Either way, please let me know if it worked (and whether you had to change the pattern). If it doesn't work either way, we may need to add a line or two, but give this a try first.
     
  3. protenus

    Joined:
    Feb 28, 2007
    Messages:
    44
    Likes Received:
    0
    Thanks...

    Here is the way I ended up taking care of this....

    The code you sent worked perfectly....

    But to allow for dial rules in the trunks to work more universally, made the following change to strip the "+" and replace with 00 (standard international dial prefix..
    Then in the trunk normally used, added the following dial rule to look for 00385 (the local country code), and strip off the 00385 part and add the leading 0 required for in country dialing....
    (in Outgoing Dial Rules)
    Code:
    0+[0][0][3][8][5]|.
    
    Not sure if that is the most efficient manner to do that... but it works.

    So now if i dial +1(555)555-4444 here in croatia, it will put the correct international dial prefix and call...
    and if it is +385 (99) 555 5555 it will dial 099 555 5555 as it is supposed to...

    this rule also has the benifit that if someone dials a national number as international, the PBX will dial correctly.....


    Should I leave this in that custom context, or is there a way to apply that generically so that I dont have to treat nokia extensions specially?


    Thanks again,

    M
     
  4. danardf

    Joined:
    Dec 3, 2007
    Messages:
    8,069
    Likes Received:
    12
    It's very interesting.

    But, I don't understand very well the first line: (Stripping + from start of number) :huh:
    For exemple, what can I put into this line: (Stripping+33)? :blink:

    Noop, it's an asterisk information that not execute this line, no?
    So the first line is a comment, no? :huh:
     
  5. wiseoldowl

    Joined:
    Aug 19, 2008
    Messages:
    251
    Likes Received:
    0
  6. wiseoldowl

    Joined:
    Aug 19, 2008
    Messages:
    251
    Likes Received:
    0
    protenus: I'm glad you got it working, and thank you for sharing the code you used - I was hoping that I wasn't leading you down the wrong path. As for your question about whether you should leave that in the custom context, until and unless the FreePBX developers figure out a way to let you include a + in dial rules without it having a special meaning (it's been requested more than once), I don't know of any other way to do it. If you actually figure out any other way, I'd love to hear it. I know it's a pain to change the context manually for every affected extension, but I just don't know any other way to handle it. I'm sure that some other people (some of the ones that like to give advice in the IRC channel) would likely have told you that there's no way to do it at all.

    As for your trunk dial rule, I guess I don't get the point of the square brackets, they seem superfluous around a single digit. Why not just:
    0+00385|.

    I THINK you will find that will work just as well and not consume as much CPU time (not that you'd ever notice). Normally you only use square brackets if you are specifying a range of digits or a selection of digits (e.g. [1-49] would mean any of the digits 1,2,3,4,9).

    danardf: You are correct, the Noop is just a comment. It's there so that if you are watching the CLI to see how the call is progressing (assuming you have the debug level set high enough) it will actually tell you when it is about to strip the +. You can change the text to anything that is meaningful to you, or even omit the line entirely, but if you do that, you have to change the n in the next line to 1 (so instead of _+.,n, you'd have _+.,1,).
     
  7. danardf

    Joined:
    Dec 3, 2007
    Messages:
    8,069
    Likes Received:
    12
    Ok thanks.

    That's will be good if freepbx include this function! (add, delete, or replace digits from incoming calls) ;)
     
  8. danardf

    Joined:
    Dec 3, 2007
    Messages:
    8,069
    Likes Received:
    12
    hmmm .... Another question.

    Why put :
    • 00${EXTEN:1},1) and not
      00${EXTEN},1)

    What's the function of ":1" ?
     
  9. wiseoldowl

    Joined:
    Aug 19, 2008
    Messages:
    251
    Likes Received:
    0
    Re:Stripping the

    It's SOOOOO tempting to give a smartass answer here, but I won't... :p

    The whole point of this is to strip the plus sign, which happens to be the first character on the line. The :1 says to take only that part of the string beginning with the SECOND character on the line. If you used :2, it would use the string starting with the THIRD character, etc.

    Now, why does Asterisk seem to be off by one in its string position count? Because it starts counting with zero, not one. Ask a silly question... :S
     
  10. danardf

    Joined:
    Dec 3, 2007
    Messages:
    8,069
    Likes Received:
    12
    Re:Stripping the

    Ha ok! Now i see.

    Thanks for this information. ;)
     
  11. protenus

    Joined:
    Feb 28, 2007
    Messages:
    44
    Likes Received:
    0
    Yes the [3][8][5] is not needed... Must have had a minor brain fart or something....

    Thanks again for the help!
     
  12. harryhirsch

    Joined:
    Apr 10, 2009
    Messages:
    24
    Likes Received:
    0
    Re:Stripping the

    Hi,

    Is there a way to make it work for incoming calls, too ?

    My SIP Provider sends CID with countrycode, i.e +33xxxxxxxxx .
    But Elastix should add the correct nationa number to the Phonebook, means it should replace +33xxxxxxxxx with 0xxxxxxxxx .


    All Other numbers witch starts with + should be not modified, or + should be repalced by 00.

    Any Idee how can I do that ?
    Should I add something in the [cidlookup] area ?


    Thanks


    Harry
     
  13. Patrick_elx

    Joined:
    Dec 14, 2008
    Messages:
    1,120
    Likes Received:
    0
    Re:Stripping the

    if your provider is sending you a CLID that you need to change, you will have to create a context for your provider.

    In the trunk setup for this provider you probably put something like context=from-trunk, or from-pstn.

    You will have to replace it with something like context=from-mystupidprovider

    In extension_custom.conf you will add something like

    [from-mystupidprovider]
    exten => _+.,1,Noop(Stripping + from start of number and add 00)
    exten => _+.,n,Goto(from-trunk,00${EXTEN:1},1)
    exten => _.,1,Goto(from-trunk,${EXTEN},1)


    I haven't tested it as I don't have access to my pbx for a few weeks, but it should give you a good starting point.
     
  14. harryhirsch

    Joined:
    Apr 10, 2009
    Messages:
    24
    Likes Received:
    0
    Re:Stripping the

    Great !
    I will check it out and let you know.

    Because I want to use it with Dialfox Phonebook and/or Superfecta for Internet reverse lookup of the CID.

    So for each incoming CID without name, Dialfox/Superfecta will do an Internet Phonebook reverse lookup, i.e. at http://infobel.com/fr/france/Inverse.aspx?q= and add the NAME to the CID.

    If somebody needs the modified php pages with Infobel(Europe) for dialfox and Superfecta, just let me know.


    Bye


    Harry
     
  15. Patrick_elx

    Joined:
    Dec 14, 2008
    Messages:
    1,120
    Likes Received:
    0
    Re:Stripping the

    I think you need to present to superfecta source lookup a number without the international country code.

    You will then probably need to change the code for something like:
    [from-mystupidprovider]
    exten => _+33.,1,Noop(Stripping +33 from start of number and add 0)
    exten => _+33.,n,Goto(from-trunk,0${EXTEN:3},1)
    exten => _+.,1,Noop(Stripping + from start of number and add 00)
    exten => _+.,n,Goto(from-trunk,00${EXTEN:1},1)
    exten => _.,1,Goto(from-trunk,${EXTEN},1)


    Or just wait a few weeks when the new superfecta version will be released, there will be a way to do some strip/add on the numbers to be able to deal with different country codes and link them with the proper lookup source. You can already try the beta version to test it if you want.

    As I said previously, I'm away from my testing pbx and I can't test it right now, but I will definitely work on it when I'm back as I was the one asking for this upgrade.
     
  16. harryhirsch

    Joined:
    Apr 10, 2009
    Messages:
    24
    Likes Received:
    0
    Re:Stripping the

    Great news !

    Yes, I will test this beta version for sure.

    How can I get it ?

    Harry
     
  17. harryhirsch

    Joined:
    Apr 10, 2009
    Messages:
    24
    Likes Received:
    0
    Re:Stripping the

    Hi Patrick,


    I tried what you told me :
    - modified the Trunk context "from-trunk" to "from-mystupidprovider"
    In the "Incoming Settings" is nothing. Should I add this context here ?
    - added the lines in the extension_custom.conf

    But it seems that the incoming SIP call was treated directly by the context
    [from-sip-external] : http://forum.elastix.org/old_files/Asterisk_Trace.txt

    Any Idea where I can add these lines ?


    Bye

    Harry

    BTW, in the trace I can see only "33" instead of "+33".
     
  18. harryhirsch

    Joined:
    Apr 10, 2009
    Messages:
    24
    Likes Received:
    0
    Re:Stripping the

    Hi Patrick,

    I have downloaded and installed Superfecta2.2.0 and made some little modifications in the source-Infobel.php file.
    In reality, an incoming call can have 3 formats at my office:
    +33xxxxxxxxx (Source SIP call or international SIP)
    33xxxxxxxxx (SIP calls)
    0487688202 (PSTN calls)


    Thats why I modified France as default and I added also Germany and Spain which works perfectly now. Have a look in my attached file : http://forum.elastix.org/old_files/source_Infobel.zip
    Only Switzerland is missed, now ;-)
    I have a Internet phonebook for it: http://tel.search.ch?tel=
    Maybe somebody can add it in Superfecta.

    With this new Superfecta version, my stripping problem is fixed.
    Thanks a lot for your help and your good work for developing the Infobel file for Superfecta !


    But now I have another problem, related to the cidlookup :
    When I disable "CID Lookup Source" in my Inbound Routes, an incoming SIP call, which provides name and number, was shown with name and number on the display of the destination phone (Linksys SPA942).

    But when I enable "CID Lookup Source" in my Inbound Routes, the SIP call came in with name and number and Superfecta tried to identify the name of the CID.
    Not necessary in this case, because this Info was already delivered by the SIP Info.
    So Superfecta tried to find the name in the Internet phonebook, and at there was no entry, no name, only the number, was shown in display of the phone.


    Another problem, at the first incoming call from a PSTN line, no name nor the number was shown on the phone. But the PSTN line delivered the CID number.
    A complete entry, with name and number, was created in the superfecta database !
    But no name/number was shown on the display of my phone.

    When the same caller calls again, then name and number was shown correctly on the phone, as Superfecta has created this entry at the first call in its database.


    I dont know if its a problem of superfecta and/or freepbx.
    I will create a topic at FreePBX and Superfecta forum, too.

    IMO its a problem of the extentions.*.conf, while CIDlookup are too early done or the delivered SIP Infos were overwritten by CIDlookup.


    Some body have some hints to fix this problem ???
    Any help is welcome ;-)


    Bye


    Harry
     
  19. harryhirsch

    Joined:
    Apr 10, 2009
    Messages:
    24
    Likes Received:
    0
    Re:Stripping the

    Dear Patrick_elx,

    I think I have probably found the problem.
    It seems to be related to the source-Infobel.php.

    I poorly modified the source-CanPagesCa.php which works now with Infobel. http://forum.elastix.org/old_files/source_CanPagesCa.zip

    When I use Superfecta2.2 and replaced your source-Infobel.php by my modified
    source-CanPagesCa.php, it seem to be working quit well:

    Even with the first call in, I can see on the display of my phone i.e "Name=Toto" and the "33474589613".
    Also, I got an entry in the Superfecta database.

    This is not the case with your file.
    But your file is MUCH better the mine because of the stripping numbers, multiple phonebooks etc
    its very very useful !!!

    Let us fix this problem together !
    Maybe its only timing problem !?

    So if I can help you to fix this little problem,
    please do not hesitate to contact me asap :)

    Bye

    Harry
     

Share This Page