コード例 #1
0
ファイル: Outbound.php プロジェクト: aa6my/nexmo-dashboard
 public function fire($job, $outbound_id)
 {
     $outbound = Outbound::findOrFail($outbound_id);
     $nexmo = new NexmoAccount(Cache::get('NEXMO_KEY', getenv('NEXMO_KEY')), Cache::get('NEXMO_SECRET', getenv('NEXMO_SECRET')));
     $response = $nexmo->sendMessage($outbound->from, $outbound->to, $outbound->text, array('status-report-req' => 1, 'client-ref' => $outbound_id));
     $isSent = true;
     if ($response['message-count'] > 0) {
         foreach ($response['messages'] as $message) {
             $outbound_chunk = new OutboundChunk();
             $outbound_chunk->outbound_id = $outbound_id;
             $outbound_chunk->message_id = $message['message-id'];
             $outbound_chunk->status_code = $message['status'];
             $outbound_chunk->price = $message['message-price'];
             $outbound_chunk->save();
             // update balance
             Pusherer::trigger('boom', 'update_balance', $message['remaining-balance']);
             if ($message['status'] > 0) {
                 $isSent = false;
             }
         }
     }
     // update status outbound
     if ($isSent) {
         $outbound->status = 'sent';
         $outbound->save();
     }
     $job->delete();
 }
コード例 #2
0
 public function dnCallback($job, $outbound_chunk_id)
 {
     $client = new Client();
     $outbound_chunk = OutboundChunk::find($outbound_chunk_id);
     $number = Number::where('number', $outbound_chunk->outbound->from)->first();
     if (filter_var($number->own_callback_url, FILTER_VALIDATE_URL) !== FALSE) {
         try {
             $client->post($number->own_callback_url, array('headers' => array('Content-Type' => 'application/x-www-form-urlencoded'), 'body' => array_merge($outbound_chunk->toArray(), $outbound_chunk->outbound->toArray(), array('callback_type' => 'dn'))));
         } catch (Exception $e) {
         }
     }
     $job->delete();
 }
コード例 #3
0
 protected function processMessages($wa)
 {
     $outbounds = Outbound::whatsapp($this->argument('number'))->queued()->get();
     foreach ($outbounds as $outbound) {
         $to = $outbound->to;
         // todo // add or update wa-contact
         // $wa->sendPresenceSubscription($to);
         $wa->sendMessageComposing($to);
         $wa->sendMessagePaused($to);
         $message_id = $wa->sendMessage($to, $outbound->text);
         $outbound_chunk = new OutboundChunk();
         $outbound_chunk->outbound_id = $outbound->id;
         $outbound_chunk->message_id = $message_id;
         $outbound_chunk->status_code = 0;
         $outbound_chunk->price = 0.0;
         $outbound_chunk->save();
         $outbound->status = 'sent';
         $outbound->save();
         $wa->pollMessage();
     }
 }
コード例 #4
0
ファイル: routes.php プロジェクト: aa6my/nexmo-dashboard
/* Callback Url */
Route::match(array('GET', 'POST'), 'callback/{item?}', function ($item = 'debug') {
    switch ($item) {
        case 'mo':
            if (!Input::has('msisdn') || !Input::has('to') || !Input::has('text')) {
                break;
            }
            $inbound = new Inbound();
            $inbound->from = Input::get('msisdn');
            $inbound->to = Input::get('to');
            $inbound->text = Input::get('text');
            $inbound->type = Input::get('type');
            $inbound->save();
            break;
        case 'dn':
            $outbound_chunk = OutboundChunk::where('message_id', '=', Input::get('messageId'))->first();
            if (!$outbound_chunk) {
                break;
            }
            $outbound_chunk->dn_status = Input::get('status');
            $outbound_chunk->dn_error_code = Input::get('err-code');
            $outbound_chunk->save();
            break;
        case 'voice':
            if (!Input::has('call-id')) {
                break;
            }
            $call = new CallLog();
            $call->call_id = Input::get('call-id');
            $call->to = Input::get('to');
            $call->status = Input::get('status');