Asterisk Setup Guide for my.megacall.es

Created by Rob Garcia, Modified on Mon, 26 May at 2:37 PM by Rob Garcia

Setting up the Asterisk with Megacall.

Information used in the example:
  • 111111 - Your sip-number from the personal account.
  • Password - Your sip password found in the "SIP Connection" section of your personal account.
  • 101 - The Asterisk extension to which a softphone/IP phone is connected for receiving incoming and making outgoing calls.

Standard setup example

Outgoing calls from the extension number 101 are routed to the trunk 111111. Incoming calls are received by registration and are routed to extension number 101.

Editing sip.conf


[general]
srvlookup=yes

[111111]
host=sip.megacall.es
insecure=invite,port
type=peer
fromdomain=sip.megacall.es
disallow=all
allow=alaw
allow=ulaw
dtmfmode=auto
secret=password
defaultuser=111111
trunkname=111111
fromuser=111111
callbackextension=111111
context=megacall-in
qualify=400
directmedia=no
nat=force_rport,comedia

[101]                                                  ;the Asterisk extension secret=password
host=dynamic
type=peer
context=megacall-out


Incoming and outgoing routing can be set up in the extensions.conf file 


[megacall-in]
exten => 111111,1, Dial(SIP/101)                       ; all incoming calls from trunk 111111 are routed to extension 101
[megacall-out]
exten => _XXX,1,Dial(SIP/${EXTEN})                     ; calls to 3-digit extension numbers of Asterisk
exten => _XXX.,1,Dial(SIP/${EXTEN}@111111)             ; calls to numbers with 4 digits or more using the trunk 111111

The 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,SIPAddHeader(P-Asserted-Identity: )
exten => _XXX.,n,Dial(SIP/${EXTEN}@111111)


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" is displayed in theCALLERID(name) parameter.

In the following example, calls from the number named manchester are routed to the extension number 101, and calls from the number named London are routed to the extension number 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(SIP/101)
exten => _X.,3,GotoIf($["${CALLERID(name)}" = "london"]?4:5)
exten => _X.,4,Dial(SIP/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 number 102 and all other calls will be declined by the Asterisk with a "Busy" tone.


[megacall-in]

exten => _X.,1,GotoIf($["${SIP_HEADER(CALLED_DID)}" = "442045770077"]?2:3)
exten => _X.,2,Dial(SIP/101)
exten => _X.,3,GotoIf($["${SIP_HEADER(CALLED_DID)}" = "442037691880"]?4:5)
exten => _X.,4,Dial(SIP/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 a 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 - Virtual phone numbers" and route the calls from the virtual number to the external server (SIP URI) using this format: 15555555555@2.20.190.41

Editing sip.conf

[megacall]
host=sipurifr.megacall.es
type=peer
insecure=port,invite
context=megacall-in
disallow=all
allow=alaw
allow=ulaw
dtmfmode = auto
directmedia=no
nat=force_rport,comedia

[megacall2]
host=sipde.megacall.es
type=peer
insecure=port,invite
context=megacall-in
disallow=all
allow=alaw
allow=ulaw
dtmfmode = auto
directmedia=no
nat=force_rport,comedia

[megacall3]
host=sipurifr.megacall.es
type=peer
insecure=port,invite
context=megacall-in
disallow=all
allow=alaw
allow=ulaw
dtmfmode = auto
directmedia=no
nat=force_rport,comedia


Incoming route is in the extensions.conf file 

[megacall-in]
exten => 15555555555,1, Dial(SIP/101)


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article