官术网_书友最值得收藏!

Building an emergency calling system

I'm a type-2, insulin-dependent diabetic. I also drive two hours every day—to my office and back. So, after I spent a week in the hospital last year, I decided to set up an In Case Of Emergency (ICE) system so that I could call one number and have it try multiple numbers at once.

Getting ready

The complete source code for this recipe can be found in the Chapter2/Recipe4 folder.

How to do it...

This emergency calling system will try a group of numbers at the same time; the first number to answer will get connected.

  1. Download the Twilio Helper Library from https://github.com/twilio/twilio-php/zipball/master and unzip it.
  2. Upload the Services/ folder to your website.
  3. Upload config.php to your website and make sure the following variables are set:
    <?php
      $accountsid = '';  //  YOUR TWILIO ACCOUNT SID
      $authtoken = '';  //    YOUR TWILIO AUTH TOKEN
      $fromNumber = '';  //  PHONE NUMBER CALLS WILL COME FROM
    ?>
  4. Create a file on your website called ice.php, with the following code:
    <?php
    session_start();
    include 'Services/Twilio.php';
    include("config.php");
    $client = new Services_Twilio($accountsid, $authtoken);
    $response = new Services_Twilio_Twiml();
    $timeout = 20;
    $phonenumbers = array(
      '1234567890',
      '1234567891'
    );
    $dial = $response->dial(NULL, array('callerId' => $fromNumber));
    foreach($phonenumbers as $number){
      $dial->number( $number );
    }
    header ("Content-Type:text/xml"); 
    print $response;
    ?>
  5. To have a number point to this script, upload ice.php somewhere and then point your Twilio phone number to it.
    How to do it...

    Insert the URL to this page in the Voice Request URL box. Then, any calls that you receive at this number will be processed via ice.php.

How it works...

In steps 1 and 2, we downloaded and installed the Twilio Helper Library for PHP. This library is at the heart of your Twilio-powered apps.

In step 3, we uploaded config.php that contains our authentication information to communicate with Twilio's API.

In step 4, we uploaded ice.php.

Finally, in step 5, we configured a phone number to direct all calls to ice.php.

We then set up the $phonenumbers array with the phone numbers in this recipe, which you should try.

When a user calls the phone number you assigned to ice.php, it tries all the numbers in the $phonenumber array at once and connects the call to the first one that answers.

You can store this number at a prominent location on your contacts list so that, in case of emergencies, you can quickly dial the number. I usually save the number to a contact named ICE and add it to favorites so that it is at the top of the list.

主站蜘蛛池模板: 团风县| 西丰县| 商水县| 奉贤区| 安徽省| 靖宇县| 抚宁县| 华坪县| 三亚市| 政和县| 竹北市| 广宁县| 宁波市| 德清县| 镇远县| 收藏| 荔波县| 乌什县| 西城区| 安泽县| 红安县| 华宁县| 平遥县| 柏乡县| 拉孜县| 道孚县| 修文县| 荔浦县| 兴业县| 云安县| 荥经县| 故城县| 孟连| 建德市| 沙湾县| 北流市| 巴彦淖尔市| 翁源县| 汤阴县| 板桥市| 江永县|