PHP Scheduler Example

This example schedules a campaign that plays an uploaded sound file to a list of phone numbers at a specific future time.

The PHP Voice Broadcast Example uses the nusoap library for accessing the CallFire service, necessary if using PHP 4. The PHP 5 distribution now includes a SOAP extension, which this example uses.

<?php

function schedule_call($phoneNumber, $datetimeString, $soundFileId, $debug=false) {
  $CALLFIRE_API_KEY = "";
  $CALLER_ID = ""; // 10 digits

  $campaignWsdl = 'https://www.callfire.com/service/CampaignService?wsdl';
  $schedulerWsdl = 'https://www.callfire.com/service/SchedulerService?wsdl';

  $campaignClient = new SoapClient($campaignWsdl, array('trace' => true)); // trace means remember for __getLastRequest()
  $schedulerClient = new SoapClient($schedulerWsdl, array('trace' => true));

  $broadcast1 = array(
    'key' => $CALLFIRE_API_KEY,
    'callerid' => $CALLER_ID,
    'numbers' => array('string' => array($phoneNumber)), // you can put more than one number here
    'soundFileId' => $soundFileId // from sound uploading interface on CallFire site
  );

  try {
    $createBroadcastToNumbersResponse = $campaignClient->createBroadcastToNumbers1($broadcast1);
    $campaignId = $createBroadcastToNumbersResponse->out;
    if ($debug) {
      echo "campaign id: " . $campaignId . "<br/>";
    }

    $schedule = array(
      'key' => $CALLFIRE_API_KEY,
      'campid' => $campaignId,
      'startDateTimeString' => $datetimeString, // e.g. '2009-07-18 11:43:00'
      'stopDateTimeString' => '', // continue until finished
      'timezone' => 'EST' // see Scheduler page for a list of time zones
    );

    $scheduleCampaignWithDateStringsResponse = $schedulerClient->scheduleCampaignWithDateStrings($schedule);
    $scheduleId = $scheduleCampaignWithDateStringsResponse->out;
    if ($debug) {
      echo "schedule id: " . $scheduleId . "<br/>";
      echo htmlspecialchars($campaignClient->__getLastRequest()) . "<br/>";
    }
  } catch (SoapFault $e) {
    if ($debug) {
      echo $e . "<br/>";
    }
  }
}

?>