Exemplo n.º 1
0
 public function index()
 {
     if (isset($_REQUEST['url'])) {
         if (self::OUTBOUND_LOG_URLS) {
             $outbound = new Outbound($_REQUEST);
             $outbound->gate = @$_SERVER['HTTP_REFERER'];
             $outbound->save();
         }
         $this->redirect_to($_REQUEST['url']);
     }
     $this->redirect_to(array('controller' => 'home'));
 }
Exemplo n.º 2
0
 public function postReply()
 {
     $inbound = Inbound::findOrFail(Input::get('inbound_id'));
     $text = trim(Input::get('text'));
     if ($text == "") {
         return array('error' => 'Text is empty');
     }
     $outbound = new Outbound();
     $outbound->from = $inbound->to;
     $outbound->to = $inbound->from;
     $outbound->text = Input::get('text');
     $outbound->type = $inbound->type;
     $outbound->save();
     return ['status' => 'success'];
 }
Exemplo n.º 3
0
 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();
 }
Exemplo n.º 4
0
 public static function boot()
 {
     parent::boot();
     static::created(function ($outbound_chunk) {
         $outbound_id = $outbound_chunk->outbound->id;
         // update status outbound
         if ($outbound_chunk->status_code > 0 && isset($status_string[(int) $outbound_chunk->status_code])) {
             $outbound = Outbound::find($outbound_id);
             $outbound->status = strtolower($status_string[(int) $outbound_chunk->status_code]);
             $outbound->save();
         }
     });
     static::updated(function ($outbound_chunk) {
         $outbound_id = $outbound_chunk->outbound->id;
         // update status outbound
         if ($outbound_chunk->dn_error_code >= 0) {
             $outbound = Outbound::find($outbound_id);
             $outbound->status = strtolower($outbound_chunk->dn_status);
             $outbound->save();
             Queue::getIron()->addSubscriber('dnCallback', array('url' => url('queue/receive')));
             Queue::push('OutboundChunk@dnCallback', $outbound_chunk->id, 'dnCallback');
         }
     });
 }
Exemplo n.º 5
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();
     }
 }
Exemplo n.º 6
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     return Outbound::orderBy('created_at', 'desc')->get();
 }