CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Internationalization and Localization (Moderators: Michał Mach, mathieu) »
  • Need approach for adding country code to phone numbers for CiviSMS
Pages: [1]

Author Topic: Need approach for adding country code to phone numbers for CiviSMS  (Read 5277 times)

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Need approach for adding country code to phone numbers for CiviSMS
February 08, 2014, 04:27:08 am
When sending text/SMS messages from CiviCRM, some(most?) SMS gateways reject the message if the recipient phone number is lacking the international country code.   I created a very simple work-around for the ClickaTell extension for CiviCRM, but it only works for the US and Canada. ( http://issues.civicrm.org/jira/browse/CRM-14160   or  https://github.com/civicrm/civicrm-core/pull/2447)

Lobo requested that I make this solution more general to handle any country, and also store the extra data needed in the table "civicrm_country"    ( FYI: I found a table of all country phone codes at: http://countrycode.org/) 

What I am not sure about is the rule to use to determine if a phone number is lacking the country code or not. In the US/Canada, its easy as the code checks of the length of the numeric portion of the phone number. If the length is exactly 10, then it adds the country code. Otherwise the code does not alter the phone number.      Is there a standard phone number length for other countries?   How should the validation work?   

« Last Edit: February 08, 2014, 04:40:17 am by epg »
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Need approach for adding country code to phone numbers for CiviSMS
February 08, 2014, 05:12:36 am
This issue contains the civicrm_country table with the country code.

http://issues.civicrm.org/jira/browse/CRM-8002

As for defining if the country code is or isn't missing, what I'd suggest it to check if the number starts by +(country code) or 00(country code). eg if a number in Switzerland starts by +41 or 0041, you don't need to add the country code, otherwise, you do.

The other problem is the "national prefix". eg in belgium, you can call a brussels number with 02 234 567 or from abroad 0032 2 234 567. It's often written as 0032 (0)2 234 567. It might be something to fix at the data entry time and force the iso format "+32...".

I haven't found a proper database or api of the various formats of phone numbers in various countries. My experience is that each country has been quite creative and it makes it hard to have one rule that rules them all...

There is an extension to help clean up the phone numbers, but so far it's uk centric if I recall.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Need approach for adding country code to phone numbers for CiviSMS
February 08, 2014, 06:40:47 am
The SQL attached to the issue at http://issues.civicrm.org/jira/browse/CRM-8002     has errors for various Caribbean and Pacific islands.    For example of an incorrect update:   update civicrm_country set country_code ='1684' where iso_code ='AS'; 

This should be: update civicrm_country set country_code ='1' where iso_code ='AS';

This is because a phone number for American Somoa is formatted/dialed no differently than any other US or Canadian phone number.     

Example of a phone number for American Somoa:   1-684-xxx-yyyy
Example of a phone number for Chicago, US:          1-312-xxx-yyyy
Example of a phone number for New York, US:        1-212-xxx-yyyy

The three numbers after the 1 is what  most people call the area code.  All US/Canadian phone numbers require an area code to be dialed even within the country. (At least where I live, in the Chicago area). In some smaller towns, dialing the area code for local in-town numbers is not required if using a land line. The area code always required when calling from a  mobile/cell phone.   

I added a comment with the full list of SQL changes to your JIRA issue at http://issues.civicrm.org/jira/browse/CRM-8002

FYI: The phone/SMS companies will likely charge higher/different fees for calling/texting a number in a Caribbean island.  But this is outside the scope of CiviCRM.    For example I pay International calling fees when I call Canada from the US, even though the number I  dial is formatted exactly the same as my neighbor's phone number. This can often happen by accident where the caller has no idea they are calling a Canadian phone number and then gets a surprise on their next phone bill.
     
« Last Edit: February 08, 2014, 07:03:14 am by epg »
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Need approach for adding country code to phone numbers for CiviSMS
February 08, 2014, 07:02:18 am
About the idea "check if the number starts by +(country code) or 00(country code). eg if a number in Switzerland starts by +41 or 0041, you don't need to add the country code, otherwise, you do."

That would mean the code is assuming ALL phone numbers in the database belong to the same country. What if the database includes phone numbers that already have the country code for a country other than Switzerland?       Also isn't it possible for the area code (ie the part of the number after the country code) to happen to match a country code?

Thanks for suggesting the extension at: https://civicrm.org/extensions/uk-phone-number-validator  But it only works for the UK. My other concern is it requires human-intervention in the back-office. If I ask for a mobile phone number within an event registration, then I cannot text those participants until after someone else has cleaned up the phone numbers using the extension.
« Last Edit: February 08, 2014, 07:05:05 am by epg »
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Need approach for adding country code to phone numbers for CiviSMS
February 08, 2014, 11:15:01 am
I had another idea: Add a new column called "country_id" to the table "civicrm_phone".  This approach would be consistent with how physical addresses are stored in the "civicrm_address" table.     This could be defaulted to the default country for the installation, just like already happens when someone is adding a new address.

Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Need approach for adding country code to phone numbers for CiviSMS
February 08, 2014, 08:34:28 pm
might also want to see if integrating something like: https://code.google.com/p/libphonenumber/ is worth it

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Need approach for adding country code to phone numbers for CiviSMS
February 09, 2014, 02:03:44 am
Quote from: epg on February 08, 2014, 11:15:01 am
I had another idea: Add a new column called "country_id" to the table "civicrm_phone".

It's the right "technological" approach, but from a usability perspective, it's adding yet another field dropdown and probably too cumbersome.

Might be better to simply use the postal address and assume the country is the same for the phone?

-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Need approach for adding country code to phone numbers for CiviSMS
February 09, 2014, 02:15:55 pm
Concerning usability, I think gmail in general does a very good job so I looked at how gmail handles phone numbers. ( ie within the "Contacts" area within gmail)

In my gmail "Contacts" area, whenever I add/edit a phone number there is a very small country flag to the left of the phone number. The default for me is the US flag, but I can click the flag and choose any country I prefer.  The flag icon is about 3-5 pixels wide at the most, and I think most end-users would easily ignore it.

BTW: In many of my customer databases, the postal address for many contacts is empty even when they are tracking phone numbers.

Also the Google/Android  library that Lobo suggested looks quite useful for validating end-user input. But as far as I can tell, those functions expect to be told which country the phone number belongs to.
« Last Edit: February 09, 2014, 02:18:57 pm by epg »
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Need approach for adding country code to phone numbers for CiviSMS
February 16, 2014, 09:29:17 am
My planned approach to make my changes international is:

1) Populate the existing column  "civicrm_country.country_code"  with the appropriate International country code, as documented at: http://issues.civicrm.org/jira/browse/CRM-8002 

2) Add a new column called "country_id" to the existing table "civicrm_phone"  which will be populated with the country_id of the address of the default organization for the installation.     This is consistent with how the table "civicrm_address" is structured. It will allow my code to know which country the phone number belongs to so that I can validate it. This change will also allow future use of the library at:  https://code.google.com/p/libphonenumber/

At this point in time, I am not planning to change the GUI for editing/adding phone numbers. I think when that is done, it should be as unobtrusive as possible, such as how Google "Contacts" works.
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

JoeMurray

  • Administrator
  • Ask me questions
  • *****
  • Posts: 578
  • Karma: 24
    • JMA Consulting
  • CiviCRM version: 4.4 and 4.5 (as of Nov 2014)
  • CMS version: Drupal, WordPress, Joomla
  • MySQL version: MySQL 5.5, 5.6, MariaDB 10.0 (as of Nov 2014)
Re: Need approach for adding country code to phone numbers for CiviSMS
May 03, 2014, 04:14:22 pm
Just wondering how this work is coming along, epg. I'm going to be supervising a GSoC student project to integrate VoIP functionality, and this work will obviously have benefit for that.

If this is all done, then I'm wondering if we could tweak a second layer of defaulting for the country. What do you think of this: If there is an address including a filled in country for the same location as the phone number for the contact (e.g. Home or Work), then use that country rather than the default country of the organization implementing CiviCRM.
Co-author of Using CiviCRM https://www.packtpub.com/using-civicrm/book

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Internationalization and Localization (Moderators: Michał Mach, mathieu) »
  • Need approach for adding country code to phone numbers for CiviSMS

This forum was archived on 2017-11-26.