Asterisk *69 with 1.4.x

By eric

Many phone users just take for granted the service provided by the Telco called *69 (pronouced “Star six nine”). Since Asterisk is a telephony platform, it doesn’t just come with *69 built in. So if you want it, you have to implement it. To save you some time, I have implemented it with a few tweaks. This setup works, but YMMV (your mileage may vary).

The concept of the operation here is as follows: When a call comes in, we grab the caller id number and store it in the Asterisk DB. When a user makes an outgoing call to *69, we then get that last phone number that called in from the AstDB and dial it using our standard Dial() function. I will get deeper into each phase as I go through the process.

Just to make this all a little clearer, I will say that the context for making outgoing calls is outbound and the context for internal calls is internal.

1. The first thing to do is to modify the actions a call takes when it comes to the phone. Assuming the first line of your dialplan for the phone was:

1
exten => _1[0]XX,1,Dial(SIP/${EXTEN},21)

This would take the call and send it to which ever SIP peer matched (be it 1000, 1001, etc). To ensure that only non-internal calls get saved to our AstDB, I have added a statement to avoid calls coming from the internal context. This is our new step 1. If the call comes from the internal context, goto step 3.

1
exten => _1[0]XX,1,GotoIf($["${CONTEXT}" = "internal"]?3)

If not, continue on to our step 2. Here we are going to make use of the DB(family/key) function. (Note: For those who had trouble with this function (like me), the family is like a table and they key is like a column name). I set the family name to LastCIDNum and the key to be the receiving caller’s extension. The value was set to the callerid number. This was done as follows:

1
exten => _1[0]XX,2,Set(DB(LastCIDNum/${EXTEN})=${CALLERID(number)})

I then move the original Dial back to step 3. Our final internal product looks something like this:

1
2
3
4
5
6
7
exten => _1[0]XX,1,GotoIf($["${CONTEXT}" = "internal"]?3)
exten => _1[0]XX,2,Set(DB(LastCIDNum/${EXTEN})=${CALLERID(number)})
exten => _1[0]XX,3,Dial(SIP/${EXTEN},21)
exten => _1[0]XX,4,Voicemail(${EXTEN}@voicemail,u)
exten => _1[0]XX,5,Hangup()
exten => _1[0]XX,102,Voicemail(${EXTEN}@voicemail,b)
exten => _1[0]XX,103,Hangup()

2. The next step is handle the outbound context for when a *69 call is placed. Assuming you don’t have an outbound dialing macro, we will handle this similarly to way an outbound SIP call would be placed. First we set the outbound callerid information:

1
2
exten => *69,1,Set(CALLERID(number)=12345678901)
exten => *69,2,Set(CALLERID(name)=MyCompany)

Then we grab the last caller id information obtained. It would probably be a good idea to check if its there and if its not set to anonymous or something along those lines, but that is something that would be relatively easy to implement after the basics are up and running. To obtain the caller id information from the AstDB, I use the ${CHANNEL} variable to get the callers extension for the query. I use the substring variable syntax to pull the 4 digit extension out of the ${CHANNEL} variable. I then stick it in a temporary variable that I can lastcall.

1
exten => *69,3,Set(lastcall=${DB(LastCIDNum/${CHANNEL:4:4})})

Once we have that information, we can dial out almost as normal. The one issue is that for all US calls, it doesn’t receive the 1 in the callerid(num). So in the Dial function, I add a 1 for domestic calls.

1
exten => *69,4,DIAL(SIP/yourprovider/1${lastcall},60,tr)

(Note: The record in the CDR gets added as the outbound dialed number, not *69.)
Our final product for the outbound context should look something like this:

1
2
3
4
5
6
7
8
exten =>exten => *69,1,Set(CALLERID(number)=12345678901)
exten => *69,2,Set(CALLERID(name)=MyCompany)
exten => *69,3,Set(lastcall=${DB(LastCIDNum/${CHANNEL:4:4})})
exten => *69,4,DIAL(SIP/paetec/1${lastcall},60,tr)
exten => *69,5,GotoIf(${DIALSTATUS} = CHANUNAVAIL,7)
exten => *69,6,GotoIf(${DIALSTATUS} = CONGESTION,7)
exten => *69,7,Hangup
exten => *69,101,Congestion

In order to see if your DB() calls are working properly, you can run the command database show from the Asterisk console. It will find all the keys entered in the family “LastCIDNum”. If these are all (or mostly) external phone numbers, then you have likely done this setup correctly.

Follow My Travels

Buy My Book

Archives

  • 2020
  • 2019
  • 2017
  • 2014
  • 2013
  • 2012
  • 2011
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006

New Posts By Email

writing