2007/11.21 @07:56 (blog, software, voip)

Asterisk 1471

Wanting to make my home Asterisk box a convergence point for VoIP and PSTN mans that I really wanted to have the “last number caller id” option that BT offer in the UK, but sadly the page on the Asterisk Wiki that mentions 1471 is no longer valid, so here’s my own implementation. It’s not 100% feature complete, but it does work in a comparable way to the PSTN version.

All the work is done in the extensions.conf file and you need to add an explicit store of the incoming CID and time before routing the call to the correct extension, so this could (obviously) be improved by using the Macro command, but that, as many of my past lecturers used to say, is left as an exercise for the reader.

In this case, two extensions 2000 and 2001 are shown as examples:

exten => 2000,1,Answer<br></br>
exten => 2000,2,Set(DB(LastCallFrom/${EXTEN})=${CALLERID(num)})<br></br>
exten => 2000,3,Set(DB(LastCallTime/${EXTEN})=${STRFTIME(${EPOCH},,%s)})<br></br>
exten => 2000,4,Dial(SIP/200,30,toj)<br></br>
 <br></br>
exten => 2001,1,Answer<br></br>
exten => 2001,2,Set(DB(LastCallFrom/${EXTEN})=${CALLERID(num)})<br></br>
exten => 2001,3,Set(DB(LastCallTime/${EXTEN})=${STRFTIME(${EPOCH},,%s)})<br></br>
exten => 2001,4,Dial(IAX2/201,30,toj)<br></br>

The playback code is fairly straight forward:

exten => 1471,1,Answer<br></br>
exten => 1471,2,Set(last=${DB(LastCallFrom/${CALLERID(num)})})<br></br>
exten => 1471,3,Playback(last-num-to-call)<br></br>
exten => 1471,4,SayNumber(${last})<br></br>
exten => 1471,5,Playback(on)<br></br>
exten => 1471,6,Set(dtime=${DB(LastCallTime/${CALLERID(num)})})<br></br>
exten => 1471,7,SayUnixTime(${dtime})<br></br>
exten => 1471,8,Wait(2)<br></br>
exten => 1471,9,Hangup

Items to note:

Feel free to correct these oversights in the comments – if things get optimised a lot I’ll post an update with the best/most feature complete version.