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:
Macro command would improve this a lot, so by creating something like DialCID and using that in place of Dial would make it trivial to use for all extensionsWitheld or Blocked numbers and would expect that the SayNumber line would just say "Zero", so adding some conditional testing in there would make things nicer (test for zero CID)"Zero" response, but again, more conditionals in the 1471 section would make that nicer (test for zero date)"two thousand seven" but "two thousand and seven" – there are options to SayUnixTime that I have yet to investigate"Press 1 to return this call" voice prompt that BT haveFeel 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.