예제 #1
0
function generateResponse($to, $details)
{
    $twiml_response = new Services_Twilio_Twiml();
    $twiml_response->say("We are trying to connect you to our customer system.");
    if ($details['type'] == 'phone') {
        $twiml_response->dial($details['detail']['id'], array('callerId' => $to));
    } else {
        if ($details['type'] == 'sip') {
            $headers = '';
            if (isset($details['detail']['headers'])) {
                $headers = '?' . implode("&", array_map(function ($k, $v) {
                    return "{$k}={$v}";
                }, array_keys($details['detail']['headers']), $details['detail']['headers']));
            }
            $dial = $twiml_response->dial(NULL, array('callerId' => $to));
            $sip = $dial->sip();
            $sip->uri("{$details['detail']['id']}@{$details['detail']['domain']}{$headers}");
        }
    }
    $twiml_response->say("Thank you for calling us. Goodbye.");
    return (string) $twiml_response;
}
function connectCall()
{
    global $sugar_config;
    ob_flush();
    $callRecipient = $_REQUEST["callRecipient"];
    $module_name = $_REQUEST['module_name'];
    $record_id = $_REQUEST['record_id'];
    $response = new Services_Twilio_Twiml();
    $response->pause(5);
    $response->say('Now connecting you.');
    $action = $sugar_config['site_url'] . "/index.php?entryPoint=twilio&action=callComplete&to_pdf=true&module_name={$module_name}&record_id={$record_id}";
    $dialAttributes = array('record' => 'true', 'action' => $action);
    $response->dial($callRecipient, $dialAttributes);
    print $response;
}
예제 #3
0
 *
 * (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');
    }
    echo $twilioResponse;
}
예제 #4
0
<?php

include "config.php";
require 'Services/Twilio.php';
# Tell Twilio to expect some XML
header('Content-type: text/xml');
# Create response object.
$response = new Services_Twilio_Twiml();
# Dial into the Queue we placed the caller into to connect agent to
# first person in the Queue.
$dial = $response->dial();
$dial->queue($callqueue);
# Print TwiML
print $response;
예제 #5
0
<?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;
예제 #6
0
    if ($greeting != '') {
        if (!isset($_SESSION['caller_greeted'])) {
            $twilio->say($greeting, $attributes);
            $_SESSION['caller_greeted'] = True;
        }
    }
    if ($user !== null) {
        $time = "";
        if ($announceTime == strtolower("true") && $user['local_time']) {
            $time = sprintf(" The current time in their timezone is %s.", $user['local_time']->format('g:ia'));
        }
        $twilio->say(sprintf("The current on-call engineer is %s." . "%s Please hold while we connect you.", $user['first_name'], $time), $attributes);
        $dialvars = array('action' => "check_if_completed_by_human.php", 'timeout' => 25);
        if (strtolower($record) != 'false') {
            if (strtolower($record) == 'true') {
                $dialvars['record'] = "true";
            } else {
                $dialvars['record'] = $record;
            }
        }
        $dial = $twilio->dial(NULL, $dialvars);
        $dial->number($user['phone_number'], array('url' => "check_for_human.php"));
    } else {
        $twilio->redirect('voicemail.php');
    }
}
// send response
if (!headers_sent()) {
    header('Content-type: text/xml');
}
echo $twilio;
예제 #7
0
<?php

require "Services/Twilio.php";
$response = new Services_Twilio_Twiml();
$out_tel_to = "転送先電話番号";
$sound_url_s1 = "一段目に水をはって火にかける。フラワーウォータの出来上がり!.mp3";
if (empty($_POST["Digits"])) {
    $gather = $response->gather(array('numDigits' => 1, 'timeout' => 30));
    $gather->say("Twilioへようこそ。モロッコのお母さんのレシピが知りたい方は1を。電話の転送は2を。社会人3年目の方は3を。電話の終了は4をおしてください。", array('language' => 'ja-jp'));
} elseif ($_POST["Digits"] == "1") {
    $response->play($sound_url, array("loop" => 1));
    $gather = $response->gather(array('numDigits' => 1, 'timeout' => 30));
} elseif ($_POST["Digits"] == "2") {
    $response->dial($out_tel_to);
    $gather = $response->gather(array('numDigits' => 1, 'timeout' => 30));
} elseif ($_POST["Digits"] == "3") {
    $response->say("社会人3年目の方、楽しいデモへようこそ。", array('language' => 'ja-jp'));
} elseif ($_POST["Digits"] == "4") {
    $response->say("楽しいデモのご利用ありがとうございました。", array('language' => 'ja-jp'));
}
print $response;
include 'Services/Twilio.php';
include 'config.php';
include 'company-directory-map.php';
$error = false;
if (isset($_REQUEST['Digits'])) {
    $digits = $_REQUEST['Digits'];
} else {
    $digits = '';
}
if (strlen($digits)) {
    $result = getPhoneNumberByDigits($digits);
    if ($result != false) {
        $number = getPhoneNumberByExtension($result['extension']);
        $r = new Services_Twilio_Twiml();
        $r->say($result['name'] . "'s extension is " . $result['extension'] . " Connecting you now");
        $r->dial($number);
        header("Content-Type:text/xml");
        print $r;
        exit;
    } else {
        $error = true;
    }
}
$r = new Services_Twilio_Twiml();
if ($error) {
    $r->say("No match found for {$digits}");
}
$g = $r->gather();
$g->say("Enter the first several digits of the last name of the party you wish to reach, followed by the pound sign");
$r->say("I did not receive a response from you");
$r->redirect("company-directory.php");
 function testGeneration()
 {
     $r = new Services_Twilio_Twiml();
     $r->say('hello');
     $r->dial()->number('123', array('sendDigits' => '456'));
     $r->gather(array('timeout' => 15));
     $doc = simplexml_load_string($r);
     $this->assertEquals('Response', $doc->getName());
     $this->assertEquals('hello', (string) $doc->Say);
     $this->assertEquals('456', (string) $doc->Dial->Number['sendDigits']);
     $this->assertEquals('123', (string) $doc->Dial->Number);
     $this->assertEquals('15', (string) $doc->Gather['timeout']);
 }
예제 #10
0
         $resp->say($config['step2_client_sorry_text']);
     } else {
         $resp->play('get_audio.php?f=step2_client_sorry_file');
     }
     $resp->redirect('call_handler.php');
 } else {
     if ($config['step2_client_mode'] == 'text') {
         $say = convertText($config['step2_client_text'], 'client', $cid);
         $resp->say($say);
     } else {
         $resp->play('get_audio.php?f=step2_client_file');
     }
     ob_start();
     foreach ($numbers as $key => $number) {
         print_r($number);
         $resp->dial($number['number'], array('timeout' => $number['timeout']));
     }
     $out = ob_get_clean();
     $fp = fopen('/tmp/twilio.out', 'a');
     fwrite($fp, $out);
     // Send data to node.js to pass along to WHMCS admins
     $data = array('type' => 'client', 'clientid' => $cid);
     sendData($data, $config['server_port']);
     // Just in case no one answers, forward to VM
     if ($config['voicemail_mode'] == 'text') {
         $message = urlencode($config['voicemail_text']);
     } else {
         $message = $whmcsurl . '/modules/addons/twilio/calls/get_audio.php?f=voicemail_file';
     }
     $resp->redirect('http://twimlets.com/voicemail?Email=' . $config['voicemail_email'] . '&Message=' . $message);
 }
예제 #11
0
파일: index.php 프로젝트: jmt9452/phoneduty
// (helps raise awareness you might be getting somebody out of bed)
$announceTime = getenv('PHONEDUTY_ANNOUNCE_TIME');
if (isset($_POST['CallSid'])) {
    session_id($_POST['CallSid']);
}
session_start();
$_SESSION['engineer_accepted_call'] = false;
$pagerduty = new \Vend\Phoneduty\Pagerduty($APItoken, $serviceAPItoken, $domain);
$userID = $pagerduty->getOncallUserForSchedule($scheduleID);
$user = $pagerduty->getUserDetails($userID);
$twilio = new Services_Twilio_Twiml();
$attributes = array('voice' => 'alice', 'language' => 'en-GB');
if ($greeting != '') {
    $twilio->say(sprintf("%s", $greeting), $attributes);
}
if ($user !== null) {
    $time = "";
    if (($announceTime == 'true' || $announceTime == 'True') && $user['local_time']) {
        $time = sprintf(" The current time in their timezone is %s.", $user['local_time']->format('g:ia'));
    }
    $twilio->say(sprintf("The current on-call engineer is %s." . "%s Please hold while we connect you.", $user['first_name'], $time), $attributes);
    $dial = $twilio->dial(NULL, array('action' => "check_if_completed_by_human.php", 'timeout' => 25));
    $dial->number($user['phone_number'], array('url' => "check_for_human.php"));
} else {
    $twilio->redirect('voicemail.php');
}
// send response
if (!headers_sent()) {
    header('Content-type: text/xml');
}
echo $twilio;
<?php

// Get the PHP helper library from twilio.com/docs/php/install
// this line loads the library
require '/path/to/twilio-php/Services/Twilio.php';
$response = new Services_Twilio_Twiml();
// get the phone number from the page request parameters, if given
if (isset($_REQUEST['To'])) {
    $number = htmlspecialchars($_REQUEST['To']);
    $response->dial(array('callerId' => '+15017250604'))->number($number);
} else {
    $response->say("Thanks for calling!");
}
echo $response;
<?php

// Get the PHP helper library from twilio.com/docs/php/install
// this line loads the library
require '/path/to/twilio-php/Services/Twilio.php';
$response = new Services_Twilio_Twiml();
$response = new Services_Twilio_Twiml();
// get the phone number from the page request parameters, if given
if (isset($_REQUEST['To'])) {
    $number = htmlspecialchars($_REQUEST['To']);
    $dial = $response->dial(array('callerId' => '+15017250604'));
    // wrap the phone number or client name in the appropriate TwiML verb
    // by checking if the number given has only digits and format symbols
    if (preg_match("/^[\\d\\+\\-\\(\\) ]+\$/", $number)) {
        $dial->number($number);
    } else {
        $dial->client($number);
    }
} else {
    $response->say("Thanks for calling!");
}
echo $response;
예제 #14
0
});
$app->route('/voice', function () use($app) {
    header("Content-type: text/xml");
    $fid = $_GET['id'];
    $from = preg_replace("/[^0-9]/", "", $_POST['From']);
    $pdo = Db::singleton();
    $sql = "SELECT * FROM numbers WHERE ID='{$fid}';";
    $res = $pdo->query($sql);
    $number = $res->fetch();
    $fromNumber = $number['number'];
    if ($user = get_user($number['user_id'])) {
        $_SESSION['uid'] = $user['ID'];
        $toNumber = $user['phone_number'];
        $name = $user['name'];
        $response = new Services_Twilio_Twiml();
        $response->dial($toNumber, array('timeout' => 5));
        $response->say("I'm sorry, {$name} is not available at this time. Please leave a message after the tone.");
        $response->record(array('transcribeCallback' => 'transcribe.php?uid=' . $user['ID'] . '&From=' . $from, 'transcribe' => 'true'));
        print $response;
        exit;
    }
});
$app->route('/transcribe', function () use($app) {
    header("Content-type: text/xml");
    $uid = $_GET['uid'];
    if ($user = get_user($uid)) {
        $filter = "!@#\$^&%*()+=-[]\\/{}|:<>?,.";
        $recording = preg_replace("/[{$filter}]/", "", $_POST['RecordingUrl']);
        $transcript = preg_replace("/[{$filter}]/", "", $_POST['TranscriptionText']);
        $from = preg_replace("/[^0-9]/", "", $_GET['From']);
        $subject = "You have a new voicemail transcription from " . $from;
<?php

require 'custom/include/Twilio/Services/Twilio.php';
global $sugar_config;
$callRecipient = $_REQUEST["callRecipient"];
$response = new Services_Twilio_Twiml();
$response->say('Now connecting you.');
$action = $sugar_config['site_url'] . "/index.php?entryPoint=twilio_callcomplete&callRecipient=4082186881";
$dialAttributes = array('record' => 'true', 'action' => $action);
$response->dial($callRecipient, $dialAttributes);
print $response;
        header("Location: company-directory-lookup?Digits=" . $digits);
        exit;
    }
} else {
    $digits = '';
}
if (strlen($digits)) {
    $first = false;
    $phone_number = getPhoneNumberByExtension($digits);
    if ($phone_number != null) {
        $r = new Services_Twilio_Twiml();
        $r->say("Thank you, dialing now");
        $r->dial($phone_number);
        header("Content-Type:text/xml");
        print $r;
        exit;
    }
}
$r = new Services_Twilio_Twiml();
$g = $r->gather();
if ($first) {
    $g->say("Thank you for calling Example Incorporated.");
} else {
    $g->say('I\'m sorry, we could not find the extension ' . $_REQUEST['Digits']);
}
$g->say(" If you know your party's extension, please enter the extension now, followed by the pound sign. To search the directory, press star. Otherwise, stay on the line for the receptionist.");
$r->say("Connecting you to the operator, please stay on the line.");
$r->dial($receptionist_phone_number);
header("Content-Type:text/xml");
print $r;
exit;