Friday, January 4, 2013

Blocking International Calls to Specific Countries in Lync

A question that often comes up in my travels is that Lync administrators want an easy way to allow users to dial internationally but exclude specific countries for some reason.

This is very easy to accomplish once you understand the ins and outs of regular expressions, and assuming you follow all my best practices regarding number normalization, and Enterprise Voice setup.  To summarize, every number a user enters in Lync should be normalized to E.164 standards, which starts with a + followed by the country code, then the area/city code and finally the local subscriber number.  A Canadian example (country code 1) would be +14165551111.  A UK example (country code 44) would be +442033334444.  If you use the Lync Dialing Rule Optimizer to create your Enterprise Voice configuration, you'll be all set.

When all numbers are normalized to E.164, and you already have separate usages and routes for local, national and international calls, it makes it very easy to design regular expressions that meet any specific criteria required by your business.

Say your company is based in North America, and is required to block international calls to Iran (98) and North Korea (850).  The Lync Dialing Rule Optimizer routing rule for international calls is this:
^\+[2-9]\d{6,14}$

This rule allows any number that doesn't start with a 0 or 1 to be routed out. Only North American countries (US/Canada and some Caribbean countries) use the country code 1.  All other country codes start with the digits 2-9.  So essentially, this rule allows calls to any international destination.

To block calls to Iran and North Korea, modify the rule to look like this (new stuff highlighted in yellow):
^\+(?!98|850)[2-9]\d{6,14}$

This will allow any number starting with 2-9, but excludes numbers that start with 98 or 850 as required.

If you're not in North America and used the Lync Dialing Rule Optimizer to create your Enterprise Voice setup, your international rule looks a little different, because we want to make sure that North American numbers are formatted correctly (as highlighted in blue), while making sure that it does not try to route national numbers as international (using UK +44 as an example, shown in green):
^\+((1[2-9]\d\d[2-9]\d{6})|(?(?!(44))([2-9]\d{6,14})))$

To block calls to Iran and North Korea using this example, modify the rule as follows (new stuff highlighted in yellow again):
^\+((1[2-9]\d\d[2-9]\d{6})|(?(?!(44|98|850))([2-9]\d{6,14})))$

Now, anybody who tries to dial a number in Iran or North Korea will be met with a notice that the call couldn't be completed.

This method is pretty granular as you could create separate routes to block countries selectively or for a specific group of users.  If you want to just block those numbers globally, you can use Unassigned Numbers to provide an announcement to users that those numbers are not allowed to be dialled. The only downside to that method is that you need to know in advance how long phone numbers are in the country you want to block.

Happy Enterprise Voicing everyone!



8 comments:

  1. I think, but I am not sure, that

    ^\+(?!98|850)[2-9]\d{6,14}$

    should be

    ^\+(?!(98|850))[2-9]\d{6,14}$

    You have already added those extra brackets in the other example patterns.

    ReplyDelete
  2. I am implementing your dial plans for Teams. For international calling, I want to create a block list for a long list of countries (124) we never want to call. It is too long to fit into a single rule, so I can't just expand the International rule. Do you have advice on how to do this?

    ReplyDelete
    Replies
    1. Below is sample regex that contains every valid country code in the world. With a bit of work, you should be able to modify it to only include the countries you want to allow dialing to:

      ^\+(1|7|2[07]|3[0-46]|39\d|4[013-9]|5[1-8]|6[0-6]|8[1246]|9[0-58]|2[1235689]\d|24[013-9]|242\d|3[578]\d|42|5[09]\d|6[789]\d|8[035789]\d|9[679]\d)(?:0)?(\d{6,14})(;ext=\d+)?$

      Delete
    2. Thanks for this! I had been having the thought since I wrote my post, and now further since seeing your reply, that rather than implementing a block list, it may be easier to make an allow list. For example, allowing the Microsoft "Zone A" countries only. Also, I will need to combine that with your NA Premium rate filtering [(1(?!(900|976)] to become the new International rules.

      Delete
    3. How does this look for a Microsoft "Zone A" international dialing list, with NA Premium numbers blocked? I did positive tests for all countries on RegEx101.com, and negative tests against a couple dozen countries and all passed.

      ^\+(1(?!(900|976))|7|27|3[0-469]|4[013-9]|5[25]|6[01456]|8[126]|91|35[12389]|372|38[56]|42[01]|852|886)(?:0)?(\d{6,14})(;ext=\d+)?$

      I may extend that list slightly yet, for example, Costa Rica, where Microsoft itself has support people, is not on the Zone A list.

      Delete
    4. Yep, that looks good! I don't know which specific countries are in Zone A, but I think you've got a good handle on it.

      Delete
    5. I just realized that does not capture clamping the NANPA countries. Here is a version that clamps the NANPA countries and Premium numbers, except for Canada, the US and Puerto Rico. I am not sure if this will fit in Microsoft Teams though - it may be too long.

      ^\+(1(?!(24[26]|26[48]|284|34[05]|441|473|649|664|67[01]|684|721|758|767|784|8[024]9|868|869|876|900|976))|7|27|3[0-469]|4[013-9]|5[25]|6[01456]|8[126]|91|35[12389]|372|38[56]|42[01]|852|886)(?:0)?(\d{6,14})(;ext=\d+)?$

      And here is a version with Costa Rica and Israel added:
      ^\+(1(?!(24[26]|26[48]|284|34[05]|441|473|649|664|67[01]|684|721|758|767|784|8[024]9|868|869|876|900|976))|7|27|3[0-469]|4[013-9]|5[25]|6[01456]|8[126]|91|35[12389]|372|38[56]|42[01]|506|852|886|972)(?:0)?(\d{6,14})(;ext=\d+)?$

      Delete
    6. Here are my final versions of this. I wrote my own NANPA filtering previously rather than using yours, and I missed a country or two as a result:

      # Microsoft Zone A countries only allowed for International Dialing
      ^\+(1(?!(24[26]|26[48]|284|34[05]|441|473|649|664|721|[67]58|767|784|8[024]9|86[89]|876|900|976))|7|27|3[0-469]|4[013-9]|5[25]|6[01456]|8[126]|91|35[12389]|372|38[56]|42[01]|852|886)(?:0)?(\d{6,14})(;ext=\d+)?$

      # Microsoft Zone A countries only plus:
      # Costa Rica (506)
      # Israel (972)
      ^\+(1(?!(24[26]|26[48]|284|34[05]|441|473|649|664|721|[67]58|767|784|8[024]9|86[89]|876|900|976))|7|27|3[0-469]|4[013-9]|5[25]|6[01456]|8[126]|91|35[12389]|372|38[56]|42[01]|506|852|886|972)(?:0)?(\d{6,14})(;ext=\d+)?$

      # Microsoft Zone A countries only plus:
      # Costa Rica (506) & Israel (972)
      # And less:
      # Russia (7), Romania (40), Poland (48), Malaysia (60), Bulgaria (359), Estonia (372), Slovenia (386)
      ^\+(1(?!(24[26]|26[48]|284|34[05]|441|473|649|664|721|[67]58|767|784|8[024]9|86[89]|876|900|976))|27|3[0-469]|4[13-79]|5[25]|6[1456]|8[126]|91|35[1238]|385|42[01]|506|852|886|972)(?:0)?(\d{6,14})(;ext=\d+)?$

      Delete