Office Code (IAX) Configuration
This page provides details on how to connect your Asterisk PBX to PhoneNet when you have an IAX API routed Office Code.
These instructions should be adapted to your environment.
We are still working on the guide for FreePBX and this will be added soon.
The following files will need to be modified.
iax.conf
In this file you will need to define a user. This is used to receive calls from PhoneNet and route them to the correct context. Replace the secret with the value you selected when submitting your request:
[from-phonenet]
type=user
username=from-phonenet
secret=<x>
auth=md5
encryption=yes
context=from-phonenet
extensions.conf
In your extensions.conf file under the [globals] stanza (or globals_custom.conf on FreePBX) you will need to add the following line with the PhoneNet key you have been assigned.
phonenetkey=<value>
You will also need to add the following stanzas either in extensions.conf (Asterisk) or extensions_custom.conf (FreePBX). You may also choose to put this in a separate PhoneNet specific file and include that file in your extensions.conf.
The following stanza is used for routing calls to PhoneNet. It will perform the API lookup and route the call to the destination that is returned. PhoneNet also provides intercept services for common errors such as invalid numbers or office codes which are handled automatically as part of this dialplan.
[to-phonenet]
exten => _X!,1,NoOp("Routing to PhoneNet")
; We lookup the route from PhoneNet
same => n,Set(lookup=${CURL(https://api.phonenet.net/v1/route/${phonenetkey}/${FILTER(0-9,${CALLERID(num)})}/${FILTER(0-9,${EXTEN})})})
; If we got an AIS response, use the automatic intercept service
same => n,GotoIf($["${lookup}"=="ais"]?ais)
; If it's a local call, send to our internal context
same => n,GotoIf($["${lookup}"=="local"]?local:remote)
; Dial the remote host and go to AIS if we received an unexpected error.
same => n(remote),Dial(${lookup})
same => n,GotoIf($["${HANGUPCAUSE}" != "16"]?ais:hangup)
; If the call failed go to AIS for centralised intercepts
same => n(ais),Set(__CAUSECODE=${HANGUPCAUSE})
same => n,Dial(${CURL(https://api.phonenet.net/v1/route/${phonenetkey}/${FILTER(0-9,${CALLERID(num)})}/${FILTER(0-9,${EXTEN})}/ais)})
same => n(hangup),Exec($["${HANGUPCAUSE}" != "0"]?Hangup(${HANGUPCAUSE}):Hangup())
; Local calls should go to your inbound context
same => n(local),Goto(from-phonenet,${EXTEN},1)
You may also need a context to set the caller ID correctly for calls to PhoneNet. The following example is for 4 digit local numbers with an office code of 100:
[phonenet-route]
; Change 4 digit numbers to 100XXXX.
exten => _X!/_XXXX,1,Set(CALLERID(num)=100${CALLERID(num)})
; Catch all for numbers not matching the above. You might want to reject instead.
exten => _X!,1,NoOp("Unmatched Caller ID")
; Route to PhoneNet
exten => _X!,2,Goto(to-phonenet,${EXTEN},1)
Then in your local dialplan you will need to route calls to the above. For example let’s say you wanted to have a prefix of 95 to call PhoneNet, so you would add the following to your from-internal or other context (eg: from-internal-custom on FreePBX):
exten => _95NXX,1,Goto(phonenet-route,${EXTEN:2},1)
exten => _9511XX,1,Goto(phonenet-route,${EXTEN:2},1)
exten => _95NXXXXXX,1,Goto(phonenet-route,${EXTEN:2},1)
You will also need a stanza to receive calls from PhoneNet. This should contain your local exchanges.
The following example would route calls received to 791XXXX to a local 4 digit extension:
[from-phonenet]
exten => _791XXXX,1,NoOp("PhoneNet Inbound for ${EXTEN}")
same => n,Goto(from-internal,${EXTEN:3},1)
If you have issues getting connected you may log a support request or ask for help in the #phonenet-help channel in our Discord server.