For work today I took a long-standing card to hook up our internal Asterisk phone system with some form of Caller ID database. You can make Asterisk use MySQL or fork a Python process using AGI, but I didn’t want any of this to be “in-band”.

In the past I’ve used simple Flask services to provide simplified JSON APIs so I can encapsulate logic in a language that I prefer, and not the scripting or configuration language I’m stuck using (like collectd’s or Asterisk’s).

The result is up on iWeb’s GitHub

The software will receive a POST from Asterisk with the source and destination number, and that POST is expected to return a name to display on the Caller ID as the only body. It also has a very simple Bootstrap GUI for updating the numbers, which shows incoming calls to the office, newest first:


The little bit of Asterisk scripting required is just this:

exten => _X.,1,Set(CALLERID(name)=${CURL("${EXTEN}",from=${CALLERID(num)})})

That part after the last comma is verbatim posted as the contents of the request, the from= is required to make it kind-of URL encoded.

None of this really stands up to security scrutiny on the WAN, so it’s all best kept on internal networks, but for a small network or a house, it should work pretty well.