Hmm, this is turning into a regular saga now: so much so I’ve added a voip tag to these posts to help keep them together.

My original macro worked just fine when the incoming number and the dialled extension matched, but this is only true for my LAN and is not generally true when using external SIP providers as the incoming extension is very often the user id of the account. For this reason it’s very helpful to be able to pass in the destination extension number to the macro so that when the user calls 1471, the extension used to place that call will hear the correct caller id.

In this example, 123456 is the incoming extension from an external SIP provider, and 2000 is the actual extension on the LAN that the call is destined for:

exten => s,1,Set(DB(LastCallFrom/${ARG2})=${CALLERID(num)})
exten => s,2,Set(DB(LastCallTime/${ARG2})=${STRFTIME(${EPOCH},,%s)})
exten => s,3,Dial(${ARG1},30,toj)
exten => s,104,Voicemail(${ARG2})
exten => s,105,Hangup
[fromexternalsip] exten => 123456,1,Answer exten => 123456,2,Macro(dialcliexten,SIP/2000,2000)

Yes, this does cause some slight issues with groups: I haven’t got enough devices on my LAN to test that properly, but one idea I had was to store the caller id twice in the macro, with 0 being the group number (a synonym for the operator/group ring: change it if you like !):

exten => s,1,Set(DB(LastCallFrom/0)=${CALLERID(num)})
exten => s,2,Set(DB(LastCallFrom/${ARG2})=${CALLERID(num)})
exten => s,3,Set(DB(LastCallTime/0)=${STRFTIME(${EPOCH},,%s)})
exten => s,4,Set(DB(LastCallTime/${ARG2})=${STRFTIME(${EPOCH},,%s)})

and with 1471 then reading out two numbers. This slightly deviates from the BT norm, and might need some user education but it’s not enough to simply store the number and only read out the most recent timestamp when calling 1471 as it’s possible for a group call to come in whilst one extension is in use.

Recording a couple of new voice prompts to give a result such as:

“The last number to call this extension was 01234 567890, today at 12:04pm and the last number to call these premises was 09876 543210 at 12:07pm”

might be one solution.