* to the on-call engineer as defined in PagerDuty
 *
 * Designed to be hosted on Heroku
 *
 * (c) 2014 Vend Ltd.
 *
 */
require __DIR__ . '/../vendor/autoload.php';
// Set these Heroku config variables
$scheduleID = getenv('PAGERDUTY_SCHEDULE_ID');
$APItoken = getenv('PAGERDUTY_API_TOKEN');
$domain = getenv('PAGERDUTY_DOMAIN');
// Should we announce the local time of the on-call person?
// (helps raise awareness you might be getting somebody out of bed)
$announceTime = getenv('PHONEDUTY_ANNOUNCE_TIME');
$pagerduty = new \Vend\Phoneduty\Pagerduty($APItoken, $domain);
$userID = $pagerduty->getOncallUserForSchedule($scheduleID);
if (null !== $userID) {
    $user = $pagerduty->getUserDetails($userID);
    $attributes = array('voice' => 'alice', 'language' => 'en-GB');
    $time = "";
    if ($announceTime && $user['local_time']) {
        $time = sprintf("The current time in their timezone is %s.", $user['local_time']->format('g:ia'));
    }
    $twilioResponse = new Services_Twilio_Twiml();
    $response = sprintf("The current on-call engineer is %s. %s " . "Please hold while we connect you.", $user['first_name'], $time);
    $twilioResponse->say($response, $attributes);
    $twilioResponse->dial($user['phone_number'], $attributes);
    // send response
    if (!headers_sent()) {
        header('Content-type: text/xml');
Exemple #2
0
<?php

require __DIR__ . '/../vendor/autoload.php';
// Set these Heroku config variables
$scheduleID = getenv('PAGERDUTY_SCHEDULE_ID');
$APItoken = getenv('PAGERDUTY_API_TOKEN');
$serviceAPItoken = getenv('PAGERDUTY_SERVICE_API_TOKEN');
$domain = getenv('PAGERDUTY_DOMAIN');
session_id($_POST['CallSid']);
session_start();
$pagerduty = new \Vend\Phoneduty\Pagerduty($APItoken, $serviceAPItoken, $domain);
$twilio = new Services_Twilio_Twiml();
$attributes = array('voice' => 'alice', 'language' => 'en-GB');
if (isset($_POST['RecordingUrl'])) {
    #create PD incident with link to recording
    $incident_data = array('service_key' => $serviceAPItoken, 'event_type' => 'trigger', 'description' => 'New voicemail for the on-call engineer', 'contexts' => [array('type' => 'link', 'text' => 'Listen to the message', 'href' => $_POST['RecordingUrl'] . '.mp3')], 'details' => array('duration' => $_POST['RecordingDuration'], 'from' => $_POST['From']));
    $pagerduty->triggerIncident($incident_data);
    $twilio->say("Your message has been sent. Thank you.", $attributes);
    session_unset();
    session_destroy();
} else {
    $twilio->say("The on-call engineer isn't available. " . "Please leave a message after the beep describing the issue. " . "Press any key or hang up when you are finished. ", $attributes);
    $twilio->record(array('action' => 'voicemail.php'));
}
$twilio->hangup();
// send response
if (!headers_sent()) {
    header('Content-type: text/xml');
}
echo $twilio;