使用Twilio预约提醒

Twilio provides a Appointment Reminder using Ruby, I needs php script for Appointment Reminder. Any one know tried PHP script for Twilio Appointment Reminder

following are Ruby code from twilio

require "twilio-ruby"

class AppointmentreminderController < ApplicationController

  # your Twilio authentication credentials
  ACCOUNT_SID = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
  ACCOUNT_TOKEN = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'

  # base URL of this application
  BASE_URL = "http://www.yourserver.com:3000/appointmentreminder"

  # Outgoing Caller ID you have previously validated with Twilio
  CALLER_ID = 'NNNNNNNNNN'

  def index
  end

  # Use the Twilio REST API to initiate an outgoing call
  def makecall
    if !params['number']
      redirect_to :action => '.', 'msg' => 'Invalid phone number'
      return
    end

    # parameters sent to Twilio REST API
    data = {
      :from => CALLER_ID,
      :to => params['number'],
      :url => BASE_URL + '/reminder',
    }

    begin
      client = Twilio::REST::Client.new(ACCOUNT_SID, ACCOUNT_TOKEN)
      client.account.calls.create data
    rescue StandardError => bang
      redirect_to :action => '.', 'msg' => "Error #{bang}"
      return
    end

    redirect_to :action => '', 'msg' => "Calling #{params['number']}..."
  end

Update: There is now a PHP Tutorial

I am trying to accomplish the same thing. If you can not do it in php (I have submitted a ticket). I found a resource that says you can run RoR and php in an app simultaneously that is what I will more than likely end up doing.

i found this question because i had same problem. the solution is very simple.

you need two file. a php class that invoke twilio webservice and xml file where twilio reads the message that you wont.

the class is very simple. in constructor you need to create instance of twilio service that is download from twilio site

ther's a method called "call" that you need to invoke for create an automatic call. The method accept two parameter (number to call and message to read)

Note that message need to urlencodend for special charcater and number need international prefix. This is the class

class twilio_call {
    private $oClient; // Twilio Object
    private $szSid = ''; // your account sid from twilio profile
    private $szToken = ''; // your token from twilio profile

    private $szPhoneNumber = ''; // my twilio phone number from twilio profile(need a phone that can call)

    private $szApiVersion = '2010-04-01'; // last twilio api


    public function __construct() {
        /** @var Services_Twilio*/
        //This is twilio php api
        $this->oClient = new Services_Twilio($this->szSid, $this->szToken, $this->szApiVersion);
    }

    /**
     * @param $szToNumber number to call
     * @param $message message to read
     */
    public function call($szToNumber, $message) {
        //$szToNumber = "+xx xxxxxxx"; // Your number with international prefix
        $uri = 'http://yourserver.com/twilio-xml.php?message='.$message; //an xml contain text to scan
        $this->oClient->account->calls->create($this->szPhoneNumber, $szToNumber,
            $uri, array(
                'Method' => 'GET',
                'FallbackMethod' => 'GET',
                'StatusCallbackMethod' => 'GET',
                'Record' => 'false',
            ));
    }
} 

The xml file is very simple. Only tre tag need.

pause: take a pause of specified length play: execute an mp3 (or other media see twilio reference) to execute say: use alice voice and specific language to say a message string.

this is xml

<?php
    header("content-type: text/xml");
    echo "<?xml szApiVersion=\"1.0\" encoding=\"UTF-8\"?>
";
    if (isset($_GET['message']))
        $message = $_GET['message'];
?>
<Response>
   <Play>http://yourserver/file.mp3</Play>
   <Pause length="1"/>
   <Say voice="alice" language="en-US" loop="10"><?php echo $message ?></Say>
</Response>