arzynik 05de3b4c38 partial #3788
requires new twilio library
2014-09-25 14:36:04 -07:00

64 lines
1.3 KiB
PHP

<?
class Crunchbutton_Message_Call extends Crunchbutton_Message {
public static function send($from, $to = null, $url = null, $callback = null) {
if (is_array($from)) {
$to = $from['to'];
$url = $from['url'];
$callback = $from['callback'];
$from = $from['from'];
}
if (!$to || !$url) {
return false;
}
$env = c::getEnv();
if (!$from || $from == 'customer') {
$from = c::config()->twilio->{$env}->outgoingCustomer;
} elseif ($from == 'driver') {
$from = c::config()->twilio->{$env}->outgoingDriver;
} elseif ($from == 'restaurant') {
$from = c::config()->twilio->{$env}->outgoingRestaurant;
}
$from = self::formatNumber($from);
$to = self::formatNumber($to);
if ($callback) {
$callback = ['StatusCallback' => 'http://'.c::config()->host_callback.$callback];
}
if (!$from || !$to) {
return false;
}
try {
Log::debug([
'action' => 'calling',
'to' => $to,
'from' => $from,
'msg' => $url,
'callback' => $callback,
'type' => 'call'
]);
$call = c::twilio()->account->calls->create($fro, $to, $url, $callback);
} catch (Exception $e) {
Log::error([
'action' => 'call failed',
'to' => $to,
'from' => $from,
'msg' => $url,
'callback' => $callback,
'type' => 'call'
]);
}
return $call;
}
}