In this guide we are going to look at how Setting up the Asterisk PJSIP with Megacall.
Information used in the example:
- 111111 - your sip-number from your personal account.
- Password - you sip-number password from the "SIP Connection" section of your personal account.
- 101 - the Asterisk extension connected to the softphone/IP phone.
Standard setup example
Outgoing calls from extension number 101 are routed to the trunk 111111. Incoming calls are received by registration and are routed to the extension 101.
Edit pjsip.conf
[udp-transport]
type=transport
protocol=udp
bind=0.0.0.0
[111111]
type=registration
transport=udp-transport
outbound_auth=111111_auth
server_uri=sip:sip.megacall.es
client_uri=sip:111111@sip.megacall.es
retry_interval=60
expiration=120
contact_user=111111
[111111_auth]
type=auth
auth_type=userpass
password=Password
username=111111
[111111]
type=aor
contact=sip:sip.megacall.es
[111111]
type=endpoint
transport=udp-transport
context=megacall-in
disallow=all
allow=alaw
allow=ulaw
outbound_auth=111111_auth
aors=111111
from_user=111111
direct_media=no
[111111]
type=identify
endpoint=111111
match=sip.megacall.es
Extension 101 to which the softphone/IP phone will be connected for receiving incoming and making outgoing calls.
[101]
type=endpoint
transport=udp-transport
context=megacall-out
disallow=all
allow=alaw
allow=ulaw
auth=101
aors=101
[101]
type=auth
auth_type=userpass
password=101
username=101
[101]
type=aor
max_contacts=10
Incoming and outgoing routing is set in the extensions.conf file
[megacall-in]
exten => 111111,1, Dial(PJSIP/101) ; all incoming calls from the trunk 111111 are routed to the extension 101
[megacall-out]
exten => _XXX,1,Dial(PJSIP/${EXTEN}) ; calls to 3-digit extension numbers of Asterisk
exten => _XXX.,1,Dial(PJSIP/${EXTEN}@111111) ; calls to numbers with 4 digits or more via trunk 111111
Standard setup is complete.
P-Asserted-Identity (for experienced users).
When making outgoing calls, you can use the SIP header P-Asserted-Identity to select the Caller ID from a list of connected numbers within the service.
The number from the P-Asserted-Identity header will be used as a priority. If the header is not provided or contains an incorrect/unconnected number, the default number will be used instead.
[megacall-out]
exten => _XXX.,1,Set(_SET_PAI=)
exten => _XXX.,n,Dial(PJSIP/${EXTEN}@111111,,b(add_header_pai^add^1))
[add_header_pai]
exten => add,1,Set(PJSIP_HEADER(add,P-Asserted-Identity)=${SET_PAI})
exten => add,n,Return()
If you have several active virtual phone numbers, you can "name" each number (for example manchester and London), and set the incoming routing based on this parameter. The virtual phone number "Name" can be set in the CALLERID(name) parameter.
In the following example, calls from the number named manchester are routed to the extension 101, and calls from the number named London are routed to the extension 102. All other calls will be declined by the Asterisk with a "Busy" tone.
[megacall-in]
exten => _X.,1,GotoIf($["${CALLERID(name)}" = "manchester"]?2:3)
exten => _X.,2,Dial(PJSIP/101)
exten => _X.,3,GotoIf($["${CALLERID(name)}" = "london"]?4:5)
exten => _X.,4,Dial(PJSIP/102)
exten => _X.,5,Busy
Your virtual phone number that received the call will be displayed in the CALLED_DID header. It is possible to configure incoming routing based on this parameter.
In the following example, calls from the number 442045770077 are routed to extension number 101, calls from the number 442037691880 are routed to extension 102. The Asterisk will decline all other calls with a "Busy" tone.
[megacall-in]
exten => _X.,1,GotoIf($["${PJSIP_HEADER(read,CALLED_DID)}" = "442045770077"]?2:3)
exten => _X.,2,Dial(PJSIP/101)
exten => _X.,3,GotoIf($["${PJSIP_HEADER(read,CALLED_DID)}" = "442037691880"]?4:5)
exten => _X.,4,Dial(PJSIP/102)
exten => _X.,5,Busy
The setup is complete.
Example №2 (SIP URI)
If the Asterisk is located on a "white" IP address (not behind a router, for example in a data centre), incoming calls can be received without registration by SIP URI scheme.
Information used in the example:
- 15555555555 - Your virtual phone number connected to Megacall.
- 2.20.190.41 - your Asterisk server IP address.
Go to your personal account, "Settings - Direct phone number" and route the calls from the virtual number to the external server (SIP URI) using this format 15555555555@2.20.190.41
Edit pjsip.conf
[15555555555]
type=aor
contact=sip:sip.megacall.es
[15555555555]
type=endpoint
transport=udp-transport
context=megacall-in
disallow=all
allow=alaw
allow=ulaw
aors=15555555555
direct_media=no
[15555555555]
type=identify
endpoint=15555555555
match=sip.megacall.es
match=sipurifr.megacall.es
match=sipde.megacall.es
match=sipuriny.megacall.es
Incoming route is in the extensions.conf file
[megacall-in]
exten => 15555555555,1, Dial(PJSIP/101)
The setup is complete.
Enabling encryption
1.In the file pjsip.conf add the following
[transport-z]
type=transport
protocol=tls
verify_server=no
bind=0.0.0.0:7065
method=tlsv1_2
2.In server_uri after the server address add :5061
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article