Creating a HTTP CallerID Lookup Source for FreePBX

PBX in a Flash / FreePBX (and I’m sure most other PBX builds) allow for a Caller ID Lookup Source to be specified. This takes inbound caller IDs, passes them to a service which then returns a meaningful name.

Such a system can be implemented extremely quickly using the lightweight Python Flask framework.

The following snippet creates a basic application which will accept a number and return a string. You will need to add your own lookup logic, be it a database query or some other method. For our implementation we query a database which was populated with client data from our CRM.

from flask import request
from flask import Flask
app = Flask(__name__)

@app.route(''/'')
def index():

    num = request.args.get("number")

    if num == "anonymous":
        return("CallerID Blocked")

    #
    # cid = "your lookup logic goes here"
    # 

    return(cid)

if __name__ == "__main__":
    app.debug = True
    app.run(host="0.0.0.0")

Once the web app is running, configure a CallerID Lookup Source within the FreePBX interface (Admin > CallerID Lookup Sources) and attach the source to each Inbound Route (Connectivity > Inbound Routes). For the query, specify number=[NUMBER], this will format the query in a manner that is consistent with what our our app expects to receive.


If you enjoyed this post consider sharing it on , , , or , and .