Ejemplo n.º 1
0
// Use either Gearman or non-asynchronous fallback
if ($config['OPTS']['USE_GEARMAN']) {
    $gmc = new GearmanClient();
    $gmc->addServers($config['OPTS']['GEARMAN_SERVERS']);
    // If attachments, spawn background download, else spawn background email
    if ($req['NUMMEDIA'] > 0) {
        $email_body .= "\n\nAttachments:\n\n{ATTACHMENTS}";
        $res = $gmc->doBackground('fetch_media', json_encode(array('SID' => $recipientSID, 'MEDIA' => $req, 'MAIL' => array('TO' => $email_to, 'SUBJECT' => $email_subject, 'BODY' => $email_body))));
    } else {
        $res = $gmc->doBackground('send_email', json_encode(array('TO' => $email_to, 'SUBJECT' => $email_subject, 'BODY' => $email_body)));
    }
} else {
    // MMS attachments
    $attachments = '';
    if ($req['NUMMEDIA'] > 0) {
        $attachments = "\n\nAttachments:\n";
        foreach ($req as $k => $v) {
            if (substr($k, 0, 8) == 'MEDIAURL') {
                $purl = parse_url($v);
                $url = unparse_url($purl, $config['ACCOUNTS'][$recipientSID]['APISID'], $config['ACCOUNTS'][$recipientSID]['APISECRET']);
                $attachments .= "* {$url}\n";
            }
        }
    }
    $email_body .= $attachments;
    // Email recipient
    send_email($email_to, $config['OPTS']['EMAIL_FROM'], $email_subject, $email_body);
}
// Done processing, send blank response
print_TwiML();
Ejemplo n.º 2
0
<?php

define('CELLIO', true);
define('LIBPATH', realpath(dirname(__FILE__) . '/..') . '/lib');
require_once LIBPATH . '/init.php';
// Variables, assemble!
$time = gmdate('r');
$req = array_change_key_case($_REQUEST, CASE_UPPER);
$recipientSID = $req['ACCOUNTSID'];
$callnum_recv = $req['TO'];
$callnum_from = $req['FROM'];
$geo = gen_geo_output($req, 'pre');
$email_to = $config['ACCOUNTS'][$recipientSID]['EMAIL'];
$email_subject = 'Twilio Call From ' . $callnum_from;
$email_body = "Call received to {$callnum_recv}\n\nTime: {$time}\n\nFrom: {$callnum_from}{$geo}";
// Use either Gearman or non-asynchronous fallback
if ($config['OPTS']['USE_GEARMAN']) {
    $gmc = new GearmanClient();
    $gmc->addServers($config['OPTS']['GEARMAN_SERVERS']);
    $res = $gmc->doBackground('send_email', json_encode(array('TO' => $email_to, 'SUBJECT' => $email_subject, 'BODY' => $email_body)));
} else {
    send_email($email_to, $config['OPTS']['EMAIL_FROM'], $email_subject, $email_body);
}
// Craft voicemail request
$twiml = array(array('name' => 'Say', 'value' => $config['ACCOUNTS'][$recipientSID]['VOICEMAIL_PROMPT']), array('name' => 'Record', 'attributes' => array('action' => $config['OPTS']['URL'] . '/voicemail.php', 'timeout' => $config['OPTS']['VOICEMAIL_TIMEOUT'], 'maxLength' => $config['OPTS']['VOICEMAIL_LEN'], 'trim' => $config['OPTS']['VOICEMAIL_TRIM'], 'playBeep' => $config['OPTS']['VOICEMAIL_BEEP'])), array('name' => 'Say', 'value' => $config['OPTS']['VOICEMAIL_TIMEOUT_MSG']));
// Tell Twilio to capture a voicemail
print_TwiML($twiml);
Ejemplo n.º 3
0
<?php

define('CELLIO', true);
define('LIBPATH', realpath(dirname(__FILE__) . '/..') . '/lib');
require_once LIBPATH . '/init.php';
// Variables, assemble!
$time = gmdate('r');
$req = array_change_key_case($_REQUEST, CASE_UPPER);
$recipientSID = $req['ACCOUNTSID'];
$vmnum_recv = $req['TO'];
$vmnum_from = $req['FROM'];
$vm_url = $req['RECORDINGURL'] . '.mp3';
$vm_len = $req['RECORDINGDURATION'] . ' second' . ($req['RECORDINGDURATION'] == 1 ? '' : 's');
$geo = gen_geo_output($req, 'post');
$email_to = $config['ACCOUNTS'][$recipientSID]['EMAIL'];
$email_subject = 'Twilio Voicemail From ' . $vmnum_from;
$email_body = "Voicemail received to {$vmnum_recv}\n\nTime: {$time}\n\nFrom: {$vmnum_from}\n\n{$geo}Voicemail Length: {$vm_len}\n\nVoicemail URL:";
// Use either Gearman or non-asynchronous fallback
if ($config['OPTS']['USE_GEARMAN']) {
    $gmc = new GearmanClient();
    $gmc->addServers($config['OPTS']['GEARMAN_SERVERS']);
    $email_body .= "\n\n{ATTACHMENTS}";
    $res = $gmc->doBackground('fetch_media', json_encode(array('SID' => $recipientSID, 'MEDIA' => array('NUMMEDIA' => 1, 'MEDIAURL0' => $vm_url, 'MEDIACONTENTTYPE0' => 'audio/mpeg'), 'MAIL' => array('TO' => $email_to, 'SUBJECT' => $email_subject, 'BODY' => $email_body))));
} else {
    $purl = parse_url($vm_url);
    $url = unparse_url($purl, $config['ACCOUNTS'][$recipientSID]['APISID'], $config['ACCOUNTS'][$recipientSID]['APISECRET']);
    send_email($email_to, $config['OPTS']['EMAIL_FROM'], $email_subject, $email_body . " {$url}");
}
// Done processing, send hangup response
print_TwiML(array(array('name' => 'Hangup', 'value' => '')));