In less than five days, I'm going to South-East Asia to spend a month relaxing, trekking, inhaling pollution and fighting cockroaches the size of my fist in Bangkok and Kuala Lumpur. It's going to be wonderful.
My problem is that it is very expensive to call to and from most of the countries in the area. The tariff for a call between a Telenor fixed-line in Norway and my prepaid mobile in Thailand is an outrageous €1.41 (NOK 11.38) per minute. The worldwide telecom tariffs are not based on distance, but destination bandwidth, de-facto monopolies, local regulations, corruption and several other complicated factors. In this case, Telenor really helps out with their typically inflated tariffs. For comparison, the Dutch telecom KPN charges "only" €1.08 (NOK 8.69) for the same call. Nevertheless, the tariffs are unacceptable, and Skype is really not an option, as it's not as flexible and portable as a mobile phone.
This is where broadband telephony like Voice over Internet Protocol (VoIP) comes to the rescue. Thanks to VoIP, there is a market for call termination over internet trunks where prices are slashed to the bone due to the globalized marketplace that internet provides. Now everyone can take international calls at wholesale prices and perhaps become their own little telecom company. By shopping around, I have found VoIP providers that will terminate a call between Norway and Thailand for only €0.0066 (NOK 0.053) per minute, or 0.46% of the Telenor tariff, and even 50% less than the Telenor domestic tariff. I'm laughing all the way to the bank.
So what do I really want to do with all this? Well, I really want two things:
- Forwarding: People should be able to call my Thai mobile just by calling my home phone number at local rates
- Callback: My home phone should be able to call my Thai mobile when I want it to, providing me with a Norwegian dialtone
On Linux, everything is possible, as you already know, of course. With the free and open source telephone system application Asterisk, it becomes somewhat easier to make telecom applications, and in this article I'll explain how I configured this to suit my needs.
Domestic trunks
My main, Norwegian telecom provider, Phonzo, provides me with a normal phone number as well as reasonable domestic and international rates without the need of monthly fees, bills in the mail or any hassle like that. The account is pre-paid and I just top-up the account with my credit card whenever I need to. (In the three years I've had such a pre-paid account, I've only paid about €37 (NOK 300) in traffic charges.) I configure the trunk and set up the route like this:
sip.conf
register => phonenumber:secretpassword@sip.phonzo.no
;
[phonzo]
type=peer
secret=secretpassword
insecure=very
username=phonenumber
fromuser=phonenumber
host=sip.phonzo.no
port=5060
context=thaimenu
nat=yes
This registers my PBX to Phonzo, defines the incoming context (where should calls from this provider be routed, in this case to "thaimenu" which actually is configured as an IVR (interactive voice response) menu system, explained later) as well as other connection details.
extensions.conf
exten => _0.,1,Dial(SIP/${EXTEN:1}@phonzo,,T)
The extensions part defines a default route to Phonzo for all outbound calls that start with 0 (to dial out from my home phone system).
International trunks
I could use Phonzo for international calls as well, because their prices seem to be amongst the lowest I've found with Norwegian providers. For example, a call to Thailand is around €0.06 (NOK 0.40) per minute, but it is still a lot more expensive than what I've found at the excellent UK provider Localphone, at €0.0066 (NOK 0.053) per minute. In addition to the low tariffs, they also give me a UK DID (direct inward dial), which means that I now also have a UK phone number free of charge, where people in UK can call me at domestic rates. In addition to all this, I also get access to local POP (point of presence) numbers in many countries around the world, making it possible for even more people to call me at domestic rates, and for me to call anywhere through my Localphone account. Very flexible.
I configure Localphone in Asterisk like this:
sip.conf
register => userid:secretpassword@localphone.com
;
[localphone]
type = friend
insecure = very
nat = yes
canreinvite = no
authuser = phonenumber
username = username
fromuser = phonenumber
fromdomain = localphone.com
secret = secretpassword
host = localphone.com
dtmfmode = rfc2833
context = thaimenu
disallow = all
allow = ulaw
allow = alaw
permit = 77.75.25.0/255.255.255.0
This registers my PBX to localphone so that it will route incoming calls, and it also defines what context incoming calls should use. I also want incoming calls from my UK phone number to reach the thaimenu context.
extensions.conf
exten => _00066.,1,Dial(SIP/${EXTEN:1}@localphone,,T)
This defines the default route for all calls with a Thai country code to be routed through Localphone.
IVR menu system
Now that I've set up the trunks and routes, I can call anywhere in the world at rock bottom prices, and people can call me on either my Norwegian or UK phone number. But I wanted a manageable and reliable way for people to be forwarded to my Thai mobile phone, so I needed to set up a menu system. People should be able to hear a message that they could be transferred to my Thai mobile if they wished to talk to me, or to leave me a voicemail. This was easy enough.
First, I recorded a message "bosse-thai-meny.gsm" and put it in /var/lib/asterisk/sounds. Then I configured the following:
extensions.conf
[thaimenu]
exten => s,1,Answer
exten => s,n,Background(bosse-thai-meny)
exten => s,n,Set(TIMEOUT(digit)=3)
exten => s,n,WaitExten(10)
exten => 1,1,Playback(pls-hold-while-try)
exten => 1,n,Dial(Local/201@default,,T)
exten => 1,n,Goto(t,1)
exten => 2,1,Playback(pls-hold-while-try)
exten => 2,n,Dial(Local/100@default,,T)
exten => 2,n,Goto(t,1)
exten => 3,1,Playback(pls-hold-while-try)
exten => 3,n,Voicemail(100@default,u)
exten => 3,n,Goto(t,1)
exten => t,1,Playback(vm-goodbye)
exten => t,2,Hangup
All inbound calls will be routed to the "thaimenu" context, as mentioned earlier. The soundfile "bosse-thai-meny" contains the instructions the caller needs to continue. If they press 1, they will be transferred to internal extension 201, which I have configured as an alias for my Thai mobile phone. If they press 2, they will be transferred to extension 100, which is my home phone. If they press 3, the call will be given to the voicemail-application with my extension and context as parameters. If they fail to do anything within 10 seconds after the soundfile is finished, the system will hang up the call after a friendly "goodbye".
Callback
So now I have a system for in- and outbound calls, with a menu system giving anyone the possibility of calling me for the price of a local call when I'm traveling in Asia, or leaving me a voicemail. Very nice, but I also need to be able to use this system to make calls the other way, without using expensive minutes on my prepaid Thai mobile account. How I'll do this is still a bit uncertain, as it depends on whether or not CID (Caller ID) is visible when I call Norway from my Thai mobile.
Primarily, I'll implement this with no need of caller-ID identification. When I call my number from my Thai mobile, I'll get the IVR like everyone else. I can then select a "secret" menu option in order to get the system to call me back and provide me with a dialtone.
First of all, I'll configure the IVR. I'll add the following to the [thaimenu] context in extensions.conf:
exten => 9,1,authenticate(1111)
exten => 9,n,system(cp /var/spool/asterisk/thaimob.call /var/spool/asterisk/outgoing/)
exten => 9,n,Hangup
This will create a new option 9 in the IVR menu. It is protected with PIN 1111, and all it's going to do is to copy a .call-file into the Asterisk's outgoing spool, which contains the following:
Channel: Local/201
MaxRetries: 2
RetryTime: 60
WaitTime: 30
Context: callback-auth
Extension: s
Priority: 1
This will call extension 201 (the shortcut to my Thai mobile), and as soon as I answer, it will put me through to the [callback] context, where I have configured the asterisk application DISA (Direct Inward Switch Application) that can be put on an extension for direct dial, IVR menu access, or in this case as a callback destination. I'll put the following context in extensions.conf:
[callback-auth]
exten => s,1,answer()
exten => s,2,background(welcome)
exten => s,3,authenticate(1111)
exten => s,4,DISA(no-password,default)
So when I call my IVR from Thailand, choose option 9, and enter the correct PIN, the system will hang up and call me back. When I answer the phone, it will provide me with a dialtone that I can use to call anywhere.
If it turns out that caller-ID is visible, I can put this into the top of the [thaimenu] context in extensions.conf:
exten => s/006687654321,1,Wait(2)
exten => s/006687654321,n,system(cp /var/spool/asterisk/thaimob.call /var/spool/asterisk/outgoing/)
exten => s/006687654321,n,Hangup
This will hang up the call without any charges on my end, and immediately call me back with a dialtone.
Comments
Hei,
Ser at du har klart å sette opp Asterisk mot Phonzo.
Jeg har prøvd å sette opp en asterisk test plattform mot Phonzo uten hell. Jeg klarte å motta samtaler (hvor samtalen varte kun i 10 sekunder), men etter en del modifisering mistet jeg dette også :-) Nå klarer jeg ikke å motta samtaler heller :-|
Lurte på om du fortsatt har et system som fungerer og om du hadde lyst til å dele oppsettet ditt med meg?
Takk på forhånd!
After realizing that the quality of the TeleVoIP connection was a bit shaggy, I noticed that there was a big rumor storm around the 'net regarding this company. Seems like they haven't been paying their bills and now are on the edge of bankruptcy, so I looked around for another provider where I don't have to pay for anything other than traffic.
I found one in Phonzo, and the rumors about this provider seem to be mostly positive, so I've changed to them. I updated the article to reflect this change.
Post new comment