Update: Thanks to Steve for pointing out that SayNumber (line 5 of 1471 below) is a bad idea: it works just fine in limited testing on my LAN, but when given a normal UK 11-digit number it seems to have some trouble trying to pronounce 01234 567 890 as 1 billion, 234 million, 567 thousand 890…

Switching that command for SayDigits not only lets the function work, it also makes far, far more sense when listening to the result, too.

Ok, so I couldn’t leave it alone: here’s a macro’ed version with a modified 1471 readout that ought to trap illegal values. The only issue here is that I don’t currently have the FXO hardware and so I can’t say what the BT Unavailable, International and Withheld caller ID codes translate to in Asterisk.

All in the extensions.conf file, starting with the Macro definition:

exten => s,1,Set(DB(LastCallFrom/${MACRO_EXTEN})=${CALLERID(num)})
exten => s,2,Set(DB(LastCallTime/${MACRO_EXTEN})=${STRFTIME(${EPOCH},,%s)})
exten => s,3,Dial(${ARG1},30,toj)
exten => s,104,Voicemail(${MACRO_EXTEN})
exten => s,105,Hangup

And again, place these mappings in the correct context for your usage:

exten => 2000,1,Answer
exten => 2000,2,Macro(dialcli,SIP/2000)
exten => 2001,1,Answer
exten => 2001,2,Macro(dialcli,IAX2/2001)

Finally the new 1471 with a better date phrasing and some error checking:

exten => 1471,1,Answer
exten => 1471,2,Set(last=${DB(LastCallFrom/${CALLERID(num)})})
exten => 1471,3,Set(dtime=${DB(LastCallTime/${CALLERID(num)})})
exten => 1471,4,Playback(last-num-to-call)
exten => 1471,5,ExecIf($["${last}" != ""]|SayDigits|${last})
exten => 1471,6,ExecIf($["${last}" = ""]|Playback|unavailable)
exten => 1471,7,ExecIf($["${dtime}" != ""]|SayUnixTime|${dtime}||"Q IMp")
exten => 1471,8,Wait(2)
exten => 1471,9,Hangup

If anything, I suppose the lack of caller ID could be trapped at the start of the 1471 code and an “Unavailable” message could be played, but because this is on my own network I’m not that bothered about those cases as I will always want internal CID to be presented.

(Oops: an extra } crept in, so if you have taken a copy of this any time before the 23rd then do check your macro carefully)