Skip to main content

Caller ID lookup from URL

Posted by jesperkjeldsen on Thu, 11/26/2009

In FreePBX there is an option to make Caller ID lookup from an URL. That would be really nice feature :-)

If someone has a script and can point me in the right direction I will try make it possible - I already have an URL I can look up Danish numbers so im just waiting ;-)

The URL is something like http://callerid.kjeldsen.it/phonenumer=12345678 and it then returns a name and no more - simple :-)

Regards
Jesper


Submitted by eeman on Mon, 11/30/2009 Permalink

I think he's looking for a means to do a CNAM lookup and populate CALLERID(name) without paying for the service from his carrier

Submitted by cbbs70a on Tue, 12/01/2009 Permalink

Gotcha. On a similiar note, I'm trying to get screen pop ups to work with VTiger. It seems that VTiger wants the URL to have a record number to search for, not a phone number. I do not have a solution for that yet. EEman, how exactly do the screen pop ups work? It's certainly nothing in the dial plan that I can see. Any insight at all would be greatly appreciated.
Frank

Submitted by eeman on Tue, 12/01/2009 Permalink

wait, is it STE or MTE? and is this the new vtiger?

the new vtiger makes an AMI connection that will do its own popup in vtiger, it will also let you call from the contact. IT only works with STE, those dash-tenant entries mess it up entirely.

Submitted by jesperkjeldsen on Wed, 12/02/2009 Permalink

Yes, I wanne do a CNAM lookup and populate CALLERID(name).
My carrier doesn't have that services so I am actually bying it somwhere else (XML lookup and output the name). So I pay for - just not at my carrier ;-)

Regards
Jesper

Submitted by eeman on Wed, 12/02/2009 Permalink

i have some AGI code that uses curl to do the lookup and then returns the value. It would require modification to parse data returned by your site as opposed to other sites i've written it for. It even cache's into mysql to curb expenses.

Submitted by jesperkjeldsen on Wed, 12/09/2009 Permalink

Hi Erik
You are welcome to send it to me if you want ;-)
You can reach me at jesper (the funny a) kjeldsen.it :-)

If I suceed to get it to work (at some time I will) - I will of course share it.

Regards
Jesper

Submitted by jesperkjeldsen on Wed, 12/30/2009 Permalink

I've been working on this for some days, but I just can't get over the last problem.
From extensions.conf I run the AGI script with one argument. If I put in a phone-numer directly it works, but now then I use variables.
What have I done wrong?

From extensions.conf:
[from-outside]
exten => _X.,1,Wait(1)
exten => _X.,2,AGI(kit-lookup1.agi|${CALLERID(num)})
exten => _X.,3,Set(CALLERID(name)=${lookupname})
exten => _X.,n,Set(__INCOMINGCLI=${CALLERID(num)})
exten => _X.,n,Goto(from-outside-redir,${EXTEN},1)

And the kit-lookup1.agi looks like this:
#!/bin/sh
name=`curl http://url-to-the-server/?phone=${1}`
echo "SET VARIABLE lookupname \"$name\""

I know I need a lot of security to ensure there isn't any "bad" chars and so on, but for testing I like to keep it as simple as possible ;-)

Submitted by jesperkjeldsen on Sun, 01/03/2010 Permalink

If I use exten => _X.,2,AGI(kit-lookup1.agi|96950000) I get the right "answer" (its our own phone number).
So $lookupname comes back to Asterisk, but its like ${CALLERID(num)} dosen't contain the number.

Sorry I forgot to say its Asterisk 1.4..

Regards
jesper

Submitted by jesperkjeldsen on Sun, 01/03/2010 Permalink

If I call from outside I get the callers number, so unless there more kinds of caller ids I must get it.

Regards
Jesper

Submitted by eeman on Mon, 01/04/2010 Permalink

not possible.. if you get caller's number.. then CALLERID(num) is set. That IS what you are seeing... your callerid on your phone comes from the same internal value that CALLERID(num) reads. what sort of line is this?

Submitted by jesperkjeldsen on Mon, 03/08/2010 Permalink

I didn't went to bed, started working on this as the time right now is great for the restart of Asterisk every time I changes in extensions.conf :-)

I haven't changed a lot, but it works with this in extensions.conf:
[from-outside]
exten => _X.,1,Wait(1)
exten => _X.,n,Set(__INCOMINGCLI=${CALLERID(num)})
exten => _X.,n,AGI(kit-lookup1.agi|${CALLERID(num)})
exten => _X.,n,Set(CALLERID(name)=${lookupname})
exten => _X.,n,Goto(from-outside-redir,${EXTEN},1)

And the kit-lookup1.agi is still like this and placed in /var/lib/asterisk/agi-bin/:
#!/bin/sh
name=`curl http://url-to-the-server/?phone=${1}`
echo "SET VARIABLE lookupname \"$name\""

One question to that, in this way I will have to enabled it to all users (in this case it is an MTE) at one time. If I want to do it for a single tennant, isn't I right in that I will have to "enable" it in inbound.include og inbound_actions.include for every trunk?

Regards
Jesper

Submitted by phoetger on Thu, 06/09/2011 Permalink

I would like to get the lookup script as well...

phoetger AT nationsline dot com

Thank you

Submitted by jesperkjeldsen on Fri, 06/10/2011 Permalink

Hi phoetger
You can see the scripts in my post from 03/09/10 :-)

Regards
Jesper

Submitted by phoetger on Mon, 06/13/2011 Permalink

jesperkjeldsen,

did you figure out how to do the caching of the CNAM?

We got CNAM to work with our provider ($0.006 per query), but we would like to implement caching to reduce the costs.

If you have an example, that would be great.

Thanks

Submitted by jesperkjeldsen on Mon, 06/13/2011 Permalink

Hi again
To make a long story short, we had a programmer who did it in .NET but our phone-to-name provider change the structure so no I am working on a small PHP script that does the caching.
So in fact I make the lookup from Asterisk to an webserver that look up another webbased service :-)

When I have finshed I will try to remember to post the script here, but do not expext rocket-sciene :-)

Regards
Jesper

Submitted by mattdarnell on Thu, 06/16/2011 Permalink

phoetger,

Shouldn't be hard to put it in a mysql database. Asterisk could look to the database to see if there is an entry for that number before you do a lookup. The next level would keep track of when you did the lookup so you could expire old records - maybe every 12 months.

It would be interesting to see the database grow. I imagine it would level off fairly quickly.

-Matt

Submitted by eeman on Thu, 06/16/2011 Permalink

you need to expire them a lot more frequently than 12months. believe me, you'll regret it if you dont. legally you're not suppose to cache them at all. There are 3 CNAM databases, depending on your service your provider will have access to 1 or all 3. ATT is one of the database maintainers. ATT has a clause that you cannot cache their lookups. Setting the cache too long will get you caught. ATT will randomly run checks. If one of their customers places a call to you, and their database records a lookup, and then later that same number is called from their network and there is no lookup they flag it for investigation. Ive heard rumor of them doing tricks like changing the CNAM entry to see if the data changes after buying service at a place like vonage.

then there is the issue that these actually _do_ change from time to time and having a bad entry will cause your customers to complain. I would make your record expire every 30 days. Right now I am only caching for 6 days, but thats still cutting my costs down on frequent calls by 85%. If they arent calling any more frequently than once a month then why go as far as 12mos thats only a 0.015 savings right?

Submitted by poliver on Wed, 07/13/2011 Permalink

Erik,
Migrating off our homegrown asterisk service to thirdlane. Our lookup uses a pipe to pass the callerid num to an agi script. I understand this will not work in 1.6. I would love to take a look at your code to solve this problem, as well as review your implementation of record aging. (We are caching with astdb with no aging.) Moving to mysql for caching with the aging capability would be great.

I can be contacted at poliver@fortistelecom.net

Best regards...