InternationalNumbers

From Openmoko

(Difference between revisions)
Jump to: navigation, search
m (Replacing '\[\[Openmoko\]\]' with 'Openmoko')
(catchg)
 
(One intermediate revision by one user not shown)
Line 14: Line 14:
  
 
== VoIP ==
 
== VoIP ==
VoIP also works best with international numbers.
+
[[VoIP]] also works best with international numbers.
  
 
== Number Transformation (Perl Code)==
 
== Number Transformation (Perl Code)==
Line 158: Line 158:
 
This is not much related to the rest of this issue, but a rather cool idea anyway. I want this.
 
This is not much related to the rest of this issue, but a rather cool idea anyway. I want this.
  
[[Category:Application Developer]]
+
[[Category:Middleware]]

Latest revision as of 08:20, 19 July 2009

I try to make comprehensive documentation on how to transform numbers in international form and how to use them.

Request For Comments!

In my opinion, Openmoko really needs to support this.

For two reasons. First because using non international numbers on a mobile network is plain stupid and can only be excused by ignorance or lazyness. Numbers just stop to work when you take your phone in another country. And second, because we like to match numbers, whatever form they are in.

Igorance is probably the biggest issue. People just use the numbering schema hey are used to and do not anticipate the problems they can get with this appoach.

Supporting a more sane approach directly in the phone absolutely helps to put and end to this.


Contents

[edit] VoIP

VoIP also works best with international numbers.

[edit] Number Transformation (Perl Code)

sub canonicalForm {
        my $number  = shift;
        # my dial plan. I added some examples for a German dial plan in the comments
        my $PAPrefix = publicAccessPrefix;  # No PBX. But usually 0
        my $IDPrefix = internationalPrefix; # 00
        my $LDPrefix = longDistancePrefix;  # 0
        my $Country = countryCode; # 49
        my $Area    = areaCode;    # 761
        my $PBX     = pbxCode;     # external number of your PBX
        $number =~ s/[^+0-9]*//g;    # strip white space etc.
        if ( $number =~ m/^[^+]/ ) {
                $number =~ s/^$PAPrefix$IDPrefix/+/;    # replace int. dialing code
                if ( $number =~ m/^[^+]/ ) {
                        $number =~ s/^$PAPrefix$LDPrefix/+$Country/;   # long distance number
                        if ( $number =~ m/^[^+]/ ) {
                                $number =~ s/^$PAPrefix/+$Country$Area/;    # local number
                                if ( $number =~ m/^[^+]/ ) {
                                        $number =~ s/^(.*)/+$Country$Area$PBX$1/;    # else cononicalize
                                }
                        }
                }
        }
        return $number;
}

This is a perl method we use in our company for that purpose.

Please note that publicAccessPrefix and pbxCode are superflous for our purpose. Because we are not behind some PBX.

This code is free.

[edit] Assumptions

For this to work, we need to know the users dialling habits when not using international form. This is usually called a Dial Plan.

How a Dial Plan works depends on the users location and or provider.

[edit] Known problems

Joachim Breitner notes: In Argentina, Buenos Aires, you usually dial 15-xxxx-xxxx for mobile phones in the area, not including the area prefix. Worse yet, to call from abroad (or if you just want to use the fully qualified number), that number would become +54 9 11 xxxx xxxx, with 54 being the country code, 11 being the area, and 9 being some strange "this is a voice call to a mobile phone" selector. If you send an SMS, you omit the 9.

Other fucked up dial plans might exist too. They probably need some special workaround.

[edit] How to find out the users Dial Plan

Because the dial plan depends on the position or provider. We could probably make some automagic match.

[edit] Automagic

We could probably ask the network or SIM about our country or Number. Please submit ideas...

Some crude location based approach might work too. But this has the problem that even when my location (country) changes, the numbering schema in my head does not change. And all my existing numbers i entered in local form relate to another dial plan. So switching dial rules depending wherever i go does not make sense.

[edit] Ask the user

If automagic fails or is not conclusive. We could just ask the user about his dialling habits.

Two solutions.

  • Create a control panel where the user can enter his dial plan.

Benefit from using a dial plan to normalize numbers only applies when the user actually entered something there.

  • Ask the user on the first non international form number he puts into his address book.

The user might be anoyed or not able to answer this question right away. So we should give him a way to enter these information later. (previous approch)

[edit] What to do with this?

[edit] Number matching against address book

When a call comes in. Try to match it against our telephone book.

Just transform every number before matching.

[edit] Transform every number in international form when the user enters it

Transform every number after user put it in his phone book.

Only save internationalized numbers if possible.

This would condition the user to use international form and acknowledge its existence and significance. This should be done in some user visible way. So he sees what happens with his number.

This is my personal favorite because, well non intenrational numbers on mobile networks are stupid...

[edit] Convert back to local number

[edit] Code

sub dialNumber {
       my $number  = shift;
       my $PAPrefix = publicAccessPrefix;
       my $IDPrefix = internationalPrefix' };
       my $LDPrefix = longDistancePrefix' };
       my $Country = countryCode' };
       my $Area    = areaCode' };
       my $PBX     = pbxCode' };
       $number =~ s/[^+0-9]+//g;                                        # strip syntactical sugar.
       $number =~ s/^$PAPrefix$IDPrefix$Country$Area$PBX//;             # inhouse phone call
       $number =~ s/^$PAPrefix$IDPrefix$Country$Area/$PAPrefix/;        # local phone call
       $number =~ s/^$PAPrefix$LDPrefix$Area$PBX//;                     # inhouse phone call
       $number =~ s/^$PAPrefix$LDPrefix$Area/$PAPrefix/;                # local phone call
       $number =~ s/^$PAPrefix$IDPrefix$Country/$PAPrefix$LDPrefix/;    # long distance call
       $number =~ s/^$PAPrefix$PBX//;                                   # inhouse call
       $number =~ s/^[+]$Country$Area$PBX//;                            # inhouse phone call
       $number =~ s/^[+]$Country$Area/$PAPrefix/;                       # local phone call
       $number =~ s/^[+]$Country/$PAPrefix$LDPrefix/;                   # long distance call
       $number =~ s/^[+]/$PAPrefix$IDPrefix/;                           # international call
       return $number;
}

[edit] Usages

Converting numbers back makes certainly no sense at all for dialling them on GSM.

But two usages come to my mind.

[edit] Number formatting

We could present the user with a number in his local version. I really dislike this idea, because in my mind the only good number is a correct number. Good looking is secondary. But if someone likes this, go ahead...

[edit] Non GSM/VoIP Dialling

This is my favourite.

Imagine you have all your numbers stored in your phone, as most of us have. But you somehow have the need to dial a number from you address book via a land line/POTS phone. Maybe because it is just much cheaper to use the land line.

Answer. DTMF!

Just play the number as DTMF on the phone speaker and hold in on the mouth piece of the phone handset.

Problem. In this case you need to use the local dial plan. More important the local dial plan of this particular phone. So this is nothing that could work out of the box, but would work reasonable well if we present the user with the option to choose or change a special dial plan.

This is not much related to the rest of this issue, but a rather cool idea anyway. I want this.

Personal tools

I try to make comprehensive documentation on how to transform numbers in international form and how to use them.

Request For Comments!

In my opinion, Openmoko really needs to support this.

For two reasons. First because using non international numbers on a mobile network is plain stupid and can only be excused by ignorance or lazyness. Numbers just stop to work when you take your phone in another country. And second, because we like to match numbers, whatever form they are in.

Igorance is probably the biggest issue. People just use the numbering schema hey are used to and do not anticipate the problems they can get with this appoach.

Supporting a more sane approach directly in the phone absolutely helps to put and end to this.


VoIP

VoIP also works best with international numbers.

Number Transformation (Perl Code)

sub canonicalForm {
        my $number  = shift;
        # my dial plan. I added some examples for a German dial plan in the comments
        my $PAPrefix = publicAccessPrefix;  # No PBX. But usually 0
        my $IDPrefix = internationalPrefix; # 00
        my $LDPrefix = longDistancePrefix;  # 0
        my $Country = countryCode; # 49
        my $Area    = areaCode;    # 761
        my $PBX     = pbxCode;     # external number of your PBX
        $number =~ s/[^+0-9]*//g;    # strip white space etc.
        if ( $number =~ m/^[^+]/ ) {
                $number =~ s/^$PAPrefix$IDPrefix/+/;    # replace int. dialing code
                if ( $number =~ m/^[^+]/ ) {
                        $number =~ s/^$PAPrefix$LDPrefix/+$Country/;   # long distance number
                        if ( $number =~ m/^[^+]/ ) {
                                $number =~ s/^$PAPrefix/+$Country$Area/;    # local number
                                if ( $number =~ m/^[^+]/ ) {
                                        $number =~ s/^(.*)/+$Country$Area$PBX$1/;    # else cononicalize
                                }
                        }
                }
        }
        return $number;
}

This is a perl method we use in our company for that purpose.

Please note that publicAccessPrefix and pbxCode are superflous for our purpose. Because we are not behind some PBX.

This code is free.

Assumptions

For this to work, we need to know the users dialling habits when not using international form. This is usually called a Dial Plan.

How a Dial Plan works depends on the users location and or provider.

Known problems

Joachim Breitner notes: In Argentina, Buenos Aires, you usually dial 15-xxxx-xxxx for mobile phones in the area, not including the area prefix. Worse yet, to call from abroad (or if you just want to use the fully qualified number), that number would become +54 9 11 xxxx xxxx, with 54 being the country code, 11 being the area, and 9 being some strange "this is a voice call to a mobile phone" selector. If you send an SMS, you omit the 9.

Other fucked up dial plans might exist too. They probably need some special workaround.

How to find out the users Dial Plan

Because the dial plan depends on the position or provider. We could probably make some automagic match.

Automagic

We could probably ask the network or SIM about our country or Number. Please submit ideas...

Some crude location based approach might work too. But this has the problem that even when my location (country) changes, the numbering schema in my head does not change. And all my existing numbers i entered in local form relate to another dial plan. So switching dial rules depending wherever i go does not make sense.

Ask the user

If automagic fails or is not conclusive. We could just ask the user about his dialling habits.

Two solutions.

  • Create a control panel where the user can enter his dial plan.

Benefit from using a dial plan to normalize numbers only applies when the user actually entered something there.

  • Ask the user on the first non international form number he puts into his address book.

The user might be anoyed or not able to answer this question right away. So we should give him a way to enter these information later. (previous approch)

What to do with this?

Number matching against address book

When a call comes in. Try to match it against our telephone book.

Just transform every number before matching.

Transform every number in international form when the user enters it

Transform every number after user put it in his phone book.

Only save internationalized numbers if possible.

This would condition the user to use international form and acknowledge its existence and significance. This should be done in some user visible way. So he sees what happens with his number.

This is my personal favorite because, well non intenrational numbers on mobile networks are stupid...

Convert back to local number

Code

sub dialNumber {
       my $number  = shift;
       my $PAPrefix = publicAccessPrefix;
       my $IDPrefix = internationalPrefix' };
       my $LDPrefix = longDistancePrefix' };
       my $Country = countryCode' };
       my $Area    = areaCode' };
       my $PBX     = pbxCode' };
       $number =~ s/[^+0-9]+//g;                                        # strip syntactical sugar.
       $number =~ s/^$PAPrefix$IDPrefix$Country$Area$PBX//;             # inhouse phone call
       $number =~ s/^$PAPrefix$IDPrefix$Country$Area/$PAPrefix/;        # local phone call
       $number =~ s/^$PAPrefix$LDPrefix$Area$PBX//;                     # inhouse phone call
       $number =~ s/^$PAPrefix$LDPrefix$Area/$PAPrefix/;                # local phone call
       $number =~ s/^$PAPrefix$IDPrefix$Country/$PAPrefix$LDPrefix/;    # long distance call
       $number =~ s/^$PAPrefix$PBX//;                                   # inhouse call
       $number =~ s/^[+]$Country$Area$PBX//;                            # inhouse phone call
       $number =~ s/^[+]$Country$Area/$PAPrefix/;                       # local phone call
       $number =~ s/^[+]$Country/$PAPrefix$LDPrefix/;                   # long distance call
       $number =~ s/^[+]/$PAPrefix$IDPrefix/;                           # international call
       return $number;
}

Usages

Converting numbers back makes certainly no sense at all for dialling them on GSM.

But two usages come to my mind.

Number formatting

We could present the user with a number in his local version. I really dislike this idea, because in my mind the only good number is a correct number. Good looking is secondary. But if someone likes this, go ahead...

Non GSM/VoIP Dialling

This is my favourite.

Imagine you have all your numbers stored in your phone, as most of us have. But you somehow have the need to dial a number from you address book via a land line/POTS phone. Maybe because it is just much cheaper to use the land line.

Answer. DTMF!

Just play the number as DTMF on the phone speaker and hold in on the mouth piece of the phone handset.

Problem. In this case you need to use the local dial plan. More important the local dial plan of this particular phone. So this is nothing that could work out of the box, but would work reasonable well if we present the user with the option to choose or change a special dial plan.

This is not much related to the rest of this issue, but a rather cool idea anyway. I want this.