Query Superfecta From PHP

Hi Everyone,

We have built a great web tool that gives us a view into the multiple queues that we have and the different callers showing CID of incoming and outgoing calls per person.

One feature I would like to add to this is the ability to pull a CID Name when someone is calling out either using Superfecta or PhoneBook module. This way I, as a user, can see who they are calling in real time. I am currently connected up to the mysql server/databases and the CLI. That means I can pretty much pull anything I need, but I cannot figure out how to pull from the Superfecta or the PhoneBook. Anyone have any ideas?

My thought would be to take the outgoing CID and query either the Superfecta or the PhoneBook to pull back a CID Name if available.

The Asterisk Phonebook is not stored in MySQL, it is stored in asterisk, and the name can be parsed from the CLI output using:

asterisk -x "database show cidname <<number>>"

As for Superfecta, if you are caching lookups to the superfecta cache, you could query the cache in mysql using a query:

 select * from superfectacache where number like '%<<number>>%';

Finally, you can can use the third party module in conjunction with Superfecta to display the outbound callerid name on compatible endpoints:

1 Like

You are the man. I am going to give this a shot now. I will provide my feedback once complete.

1 Like

Thank you so much for the information. Below is how we ended up executing on this. We decided to use the ‘get’ command instead of the ‘show’ command within the CLI.

exec("asterisk -rx 'database get cidname " . ltrim($phone_number, "1") . "'", $arr_phonebook_data, $return_var_3);
					// Not in the phonebook, set as not available
					if($arr_phonebook_data[0] == "Database entry not found."){
						$caller_id_name = "Not Available";
					// found in phonebook, pull in CNAM
						$arr_phonebook = explode(": ", $arr_phonebook_data[0]);
						$caller_id_name = $arr_phonebook[1];

Hopefully others find this valuable. So easy to make, no point it using a third party module.

We also setup our system to cache all CID/CNAM results in our phonebook. This allows our database to keep growing so that we do not see “Not Available” as often.

1 Like