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
exten => 2000,2,Set(DB(LastCallFrom/${EXTEN})=${CALLERID(num)})
exten => 2000,3,Set(DB(LastCallTime/${EXTEN})=${STRFTIME(${EPOCH},,%s)})
exten => 2000,4,Dial(SIP/200,30,toj)
exten => 2001,1,Answer
exten => 2001,2,Set(DB(LastCallFrom/${EXTEN})=${CALLERID(num)})
exten => 2001,3,Set(DB(LastCallTime/${EXTEN})=${STRFTIME(${EPOCH},,%s)})
exten => 2001,4,Dial(IAX2/201,30,toj)
The playback code is fairly straight forward:
exten => 1471,1,Answer
exten => 1471,2,Set(last=${DB(LastCallFrom/${CALLERID(num)})})
exten => 1471,3,Playback(last-num-to-call)
exten => 1471,4,SayNumber(${last})
exten => 1471,5,Playback(on)
exten => 1471,6,Set(dtime=${DB(LastCallTime/${CALLERID(num)})})
exten => 1471,7,SayUnixTime(${dtime})
exten => 1471,8,Wait(2)
exten => 1471,9,Hangup
Items to note:
- Correct use of the
Macro
command would improve this a lot, so by creating something likeDialCID
and using that in place ofDial
would make it trivial to use for all extensions - I have not tested this with
Witheld
orBlocked
numbers and would expect that theSayNumber
line would just say"Zero"
, so adding some conditional testing in there would make things nicer (test for zero CID) - I have not tested this for the case when no call has been received before for an extension: I would assume it’s another
"Zero"
response, but again, more conditionals in the1471
section would make that nicer (test for zero date) - I find the date pronunciation quite offensive, as I am not currently in the year
"two thousand seven"
but"two thousand and seven"
– there are options toSayUnixTime
that I have yet to investigate - I haven’t implemented the
"Press 1 to return this call"
voice prompt that BT have
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.