Example #1
0
 /**
  * Process all messages types
  * 
  * @return array
  */
 private function processAllMessages()
 {
     $processed = [];
     $receivers = $this->receivers();
     $messages = $this->manager->getMessages();
     foreach ($receivers as $receiver) {
         $this->presence($receiver);
         foreach ($messages as $index => $message) {
             $this->composition($receiver, $message);
             $id = $this->sendMessage($receiver, $message);
             $copy = new stdClass();
             $copy->id = $id;
             $copy->type = $message->type;
             $copy->sender = $this->account['number'];
             $copy->nickname = $this->account['nickname'];
             $copy->to = implode(', ', (array) $receiver);
             $copy->message = $message;
             if (isset($message->file) && !$message->hash) {
                 $copy->message->hash = $messages[$index]->hash = base64_encode(hash_file("sha256", $message->file, true));
             }
             foreach ($this->manager->getInjectedVars() as $key => $value) {
                 $copy->{$key} = $value;
             }
             if ($object = $this->walistener->getListener()) {
                 $copy->raw = json_encode($copy);
                 $object->fire('onSendCompleted', (array) $copy);
             }
             $processed[] = $copy;
         }
     }
     $this->broadcast = false;
     return $processed;
 }
Example #2
0
 /**
  * Sets the Whatsapi event listener
  *
  * @param  \Xaamin\Whatsapi\Contracts\ListenerInterface $listener
  * @return void
  */
 public function setListener(ListenerInterface $listener)
 {
     $this->walistener->setListener($listener);
 }
Example #3
0
 /**
  * Get WhatsProt instance for given number
  * 
  * @param  string $number 
  * @return \Registration
  */
 private function getRegistrationClient($number)
 {
     $registration = new Registration($number, $this->debug);
     $this->listener->registerRegistrationEvents($registration);
     return $registration;
 }