Setting up a company directory
A company directory is a very handy thing to have when you want a company phone number to be published and then have it contact other people in your company. It's also nice to make it searchable and that is what we are doing today.
This particular company directory has served me well at several companies I've worked with over the years and I'm especially pleased with its ability to convert names into their matching digits on a phone pad using this function:
This function works such that a name such as Stringer
(my last name), gets converted into 78746437
. Then, as the caller does a search, it will return an employee whose name matches the digits entered and will then connect the call.
The complete source code for this recipe can be found at Chapter1/Recipe6
.
We're going to build a basic, searchable company directory that will let callers either enter an extension or search by their last name.
Download the Twilio Helper Library (from https://github.com/twilio/twilio-php/zipball/master) and unzip it.
Upload the Services/
folder to your website.
Upload config.php
to your website and make sure the following variables are set:
Let's create the file called company-directory-map.php
, which sets up the map for the company directory:
This file handles the list of extensions, and also takes care of the functions that handle the searching. One of the steps it performs is to loop through each extension and convert the last name into digits corresponding with a phone pad.
Now, we'll create company-directory.php
to handle the logic for incoming calls:
All incoming calls will first come into this file and, from there, will either be redirected straight to an extension or start the lookup process based on the last name.
And finally, we create company-directory-lookup.php
that adds the ability to perform search operations:
This file handles our lookups; as a caller types digits into a phone dial pad, this script will loop through the extensions to find a name that matches the digits entered.
Finally, we need to have a number point to this script. Upload company-directory.php
somewhere and then point your Twilio phone number to it:
Insert the URL in the Voice Request URL field on this page. Then, any calls that you receive at this number will be processed via company-directory.php
.
In steps 1 and 2, we downloaded and installed the Twilio Helper Library for PHP.
In step 3, we uploaded config.php
that contains our authentication information to talk to Twilio's API.
In step 4, we set up the $directory
array in company-directory-map.php
, which is the core of this system; it handles the extension number for each employee as well as containing his/her phone number, first name, and last name.
When a caller chooses to search for an employee, the last name is converted into corresponding digits similar to what you see on a phone.
So for example, Stringer
becomes 78746437
; as the caller does a search, it will return an employee whose name matches and will then connect the call.
Finally, in step 7, we set up our phone number in Twilio to point to the location where company-directory.php
has been uploaded so that all calls to that phone number go straight to company-directory.php
.
You now have a nice, searchable company directory. I've been using this directory myself for the last two years at various companies and it works nicely.