Wednesday, October 3, 2012

Custom Destinations in Asterisk

Custom Destination feature in asterisk is a very useful functionality where we can have lot of options to make the asterisk to work in different environments. Upon using this functionality we can use a single inbound number to access all internal conference bridges, route the call to one asterisk box to another one through the trunks etc. We will describe these one by one,

  • Accessing internal conference bridges using single inbound number.

In our example, we already have a working asterisk pbx with lot of conference bridges working inside the office through VoIP phones.

We are going to make accessing all these conference bridges from the local mobile/land phones through a single inbound number. So will start as mentioned below,

1) Install "Custom Destination module" through FreePBX admin interface.
2) Create a new custom destination "conferences,s,1" with whatever description you like (ie "ConferenceIVR")
3) Add to /etc/asterisk/extensions_custom.conf the following script


[conferences]
include => ext-meetme; in [ext-meetme] contest are stored all the conferences created in FreePBX
exten => s,1,Answer
exten => s,n,Wait(1)
exten => s,n,Playback(enter-conf-call-number); Insert you welcome message
exten => s,n,Goto(w,1)
exten => w,1,Wait(1)
exten => w,n,Playback(beep)
exten => w,n(begin),Set(TIMEOUT(digit)=3)
exten => w,n,Set(TIMEOUT(response)=10)
exten => w,n,WaitExten(,)
exten => w,n,Playback(invalid)
exten => w,n,Goto(w,1)

This script asks for the conference number to join to and enters the context managing the conferences.
If the conference doesn't exists, it loops and ask again for a valid conference number.


4) Reload the Asterisk
5) Create a new Inbound Route and route it to the Custom Destination    "ConferencesIVR"
6)  Now try from local/mobile phones using the inbound number, you will be asked the conference call number to be joined and the PIN for the same.
7) Enjoy !!!


  • Pass one DID from one asterisk to another.
I have two asterisk boxes (box A & box B) in two different countries and both are inter connected through SIP trunk and able to communicate between the extensions registered on both the boxes. In one of my requirement, I have to route my company's support calls coming to one location to be routed to the support team located in the other country after the end of Office hours on first country.

What I did to achieve this are,
  • Set up a DID on box A and it's destination set to the registered extension on box A. For example, +918xxxxx1010 which rings to the local extension 1010, which finally I need to route to extension 2020 on the box B through my SIP trunk.
  • Create a custom destination on Box A as, 
custom-did-to-BoxB,${EXTEN},1
  • Then I have to go and add the following line in the /etc/asterisk/extensions_custom.conf file,  
[custom-did-to-BoxB]
exten => _X.,1,Dial(SIP/2020@IP-Of- the- BoxB,30,r)

If you are using IAX trunk the above line should look like,
[custom-did-to-BoxB]exten => _X.,1,Dial(IAX2/IP-of-the-BoxB/$2020,30,r)
  • Go to the extension 1010 on Box A and select custom destination and set the value as  custom-did-to-BoxB which we created above.
  • Reload asterisk to get it effect.
Now if you call to the local number +918xxxxx1010 and let the phone ring completely, it will route the call to the exension 2020 which is actually registered on BoxB which is in another country.

1 comment:

  1. On the first example "Accessing internal conference bridges using single inbound number"

    I currently am running Asterisk 13.23.1

    I realize this is a very old post. I am trying to use this code for my Conference IVR and it works but does not handle dialing an incorrect conference bridge correctly.

    I have conference rooms 2663 and 2664. If you dial either of those you get transferred to the conference and prompted to enter the Pin.

    If you do nothing the system plays the default invalid message and prompts you to enter it again.

    If you dial 2665 the system drops the call. My expectation is since that is not a valid number the system should send the caller to the invalid greeting and prompt them to dial again.

    Ideally we would allow them to do this X number of times then hangup.

    ReplyDelete