Skip to content

Issue#708 Add PhoneNumber Regex for SMS/Voice and USSD #1806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 12, 2017
Merged

Conversation

croufay
Copy link
Contributor

@croufay croufay commented Feb 12, 2017

Issue#708 Add PhoneNumber Regex for SMS/Voice and Ussd

The code does a normal exact match and if that fails, it checks if there is a relevant Regex match

example regex

tested

^*77...33#$ = matches any number that starts with *77 and and the three dots matches any character and it must end with a # sign

^[12]2233#$ = matches any number that starts with 1 or 2 and ends with 2233#

^[]76[]88[456]#$ = matches any number that starts with 76884# or 76886# or 76886#

7777|8888 = matches 7777 or 8888

[45]234[23] = matches 42342, 42343, 52342 and 52343,

All tested with Voice, SMS or USSD where relevant.

@croufay
Copy link
Contributor Author

croufay commented Mar 8, 2017

I;m assigning to @maria-farooq

@maria-farooq
Copy link

Hi @croufay i reviewed other 2 PRs

This one i think should be reviewed by @gvagenas

Thanks
Maria

Copy link
Contributor

@gvagenas gvagenas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@croufay there are no test cases and no documentation. I could provide the test cases but I don't know what to test for.

} finally {
}//}
//check if there is a Regex match only if parameter is a String aka phone Number
if(!(parameter instanceof Sid)){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@croufay why you check if object parameter is not an instance of Sid? What is the point here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@croufay what is your comment on that?

}//}
//check if there is a Regex match only if parameter is a String aka phone Number
if(!(parameter instanceof Sid)){
inboundPhoneNumber = parameter.toString().replace("+1", "");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@croufay why you always remove the +1 sign? What if we have +1512*, what if we have +331554*?
The + sign should be removed after we check the DB and there is no match

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gvagenas, that shouldn't be a problem because the first part always checks for exact match. ex. +331554*, If there is no exact match, it does a regex match. You have to remove the + sign as it has a special meaning and it will cause the regex search to fail

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@croufay here you don't remove just the + sign but the +1 so I guess you have to fix that, right?
Also, you mentioned that the first part always checks for exact match. ex. +331554*, If there is no exact match, it does a regex match, I don't get that. From the code I can see that if the parameter contains * or # you try a REGEX search by first removing the +1, can you please point me to the part of the code you refer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove the

formatedPhone = phoneNumberUtil.format(phoneNumberUtil.parse(phone, "US"), PhoneNumberFormat.E164);
line that adds the +1 to all number that are not formated with internation access code.
@deruelle please confirm if you agree

//check if there is a Regex match only if parameter is a String aka phone Number
if(!(parameter instanceof Sid)){
inboundPhoneNumber = parameter.toString().replace("+1", "");
logger.warn(" Inbound phoneNumber : " + inboundPhoneNumber );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@croufay no need for WARN log here. Just make it INFO

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I can update this to INFO

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String phoneRegexPattern = null;
try {
List<IncomingPhoneNumber> listPhones = getAllIncomingPhoneNumbers();
for (IncomingPhoneNumber listPhone : listPhones){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@croufay I don't get the reason to go through all the stored numbers to build the Regex pattern. Can you elaborate? This doesn't seem to be an efficient way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gvagenas, that is true but I didn't want to mess with the exact match we already have in place. Another thing is that the exact match is done using predefined SQL that we have defined in the https://github.com/RestComm/Restcomm-Connect/blob/master/restcomm/restcomm.application/src/main/webapp/WEB-INF/sql/incoming-phone-numbers.xml

The other option would be the parse the Regex using mysql but that might be problematic if mysql or mariadb version changed as we have seen when we do DB upgrade.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@croufay can you please explain the steps of your implementation here, I think I am missing the reason and I don't understand it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@croufay we need a design document here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to avoid iterating over ALL IncomingPhoneNumbers we should add a new column at the IncomingPhoneNumbers table to flag REGEX true/false when we create a DID.
There must be a validation method to tell if the number is DID, USSD ShortCode or Regex

@croufay
Copy link
Contributor Author

croufay commented Apr 10, 2017

@gvagenas , the test case are similar to what we already do to match any numbers. We just need to add a few of the scenarios below

^*77...33#$ = matches any number that starts with *77 and and the three dots matches any character and it must end with a # sign

^[12]2233#$ = matches any number that starts with 1 or 2 and ends with 2233#

^[]76[]88[456]#$ = matches any number that starts with 76884# or 76886# or 76886#

7777|8888 = matches 7777 or 8888

[45]234[23] = matches 42342, 42343, 52342 and 52343,

All tested with Voice, SMS or USSD where relevant.

@gvagenas
Copy link
Contributor

@croufay please provide test cases for the REGEX rules we support here. You can copy CallLifeCycleTest or TestDialVerb* and the DB file it uses, to provide REGEX rules in DB instead of full numbers.

@gvagenas
Copy link
Contributor

Provide java regex validation at Admin UI and IncomingPhoneNumber REST API

@gvagenas
Copy link
Contributor

For the testsuite you should create a new test class similar to CallLifecycleTest, create a new DB based on restcomm.script_callLifecycleTest but instead of specific DID numbers, provide the regex patterns.
In the test class provide a simple test case similar to org.restcomm.connect.testsuite.telephony.CallLifecycleTest#testDialClientAlice but every time dial a number that should match the patterns provided in the DB

@gvagenas gvagenas modified the milestones: 8.2.0, George 8.2.0 Sprint 1 Apr 20, 2017
@gvagenas gvagenas removed this from the George 8.2.0 Sprint 1 milestone May 2, 2017
@gvagenas
Copy link
Contributor

gvagenas commented May 7, 2017

@croufay the PR is ready to merge, code is ok, tests are passing, all good.
We are missing documentation, when docs are ready we can merge to master

@croufay
Copy link
Contributor Author

croufay commented May 12, 2017

@gvagenas
Copy link
Contributor

Great, thanks @croufay , I will merge today

@gvagenas gvagenas merged commit 6363367 into master May 12, 2017
@jaimecasero jaimecasero deleted the issue#708 branch November 22, 2017 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants