Identify Caller

For every call, we send lots of information about the caller, example caller ID, Caller name, Number dialed etc. Let's use some of that information.

Identify Caller by Name

Now that you have successfully written your first Voice API, we will modify the code to make is more personalized we will include caller name in greeting.

For example: “Hello Bob”

<?php
 
       // contacts array will List everyone your contacts
            $contacts = array(    
              "9495797676"=>"John",
              "9495776878"=>"Lily",
              "3102168544"=>"Bob",
              "8587771234"=>"Wendy"
              "6058393817"=>"Amanda"
              );
        // if the caller is known, then greet them by name
        // otherwise, just identify them as another caller
        if(!$name = $contacts[$_REQUEST['From']])
                $name = "there";
 
        // now greet the caller
        header("content-type: text/xml");
        echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
        <Say>Hello <?php echo $name ?>.</Say>
</Response>

In the code above we started off by creating an array $contact. In this array we have listed all the known contacts with their phone number and name. When the call comes in from parameter will be triggered and look in the $contact array to see if we have the phone number in our contacts. If the phone number is located in the contacts then the code will greet the caller with name (like Hello Bob) else it will treat the caller unknown and respond “Hello There”.

Key word used = Say Say Reads the text and convert’s that to audio and play to the caller.

Wohooo!!!! You successfully completed the step and identified your caller by name!!!

Sounds good, now let's. Let's collect users response and so you can transfer call to the right person.

Last updated