示例#1
0
 public function sendMessages()
 {
     $messages = $this->repository->getUnsentMessages(Credentials::PROTOCOL_WHATSAPP, $this->whatsprot->getPhoneNumber());
     foreach ($messages as $message) {
         switch ($message['type']) {
             case 'text':
                 $msgID = $this->whatsprot->sendMessage($message['to'], htmlentities($message['body']));
                 break;
             default:
                 $msgID = null;
                 break;
         }
         if (empty($msgID)) {
             $this->logger->log("could not send message #" . $message['id']);
         } else {
             $this->logger->log("message #" . $message['id'] . " delivered");
             $this->repository->markMessageSent($message['id'], $msgID);
         }
     }
 }
示例#2
0
 /**
  * Client constructor.
  * @param Credential $credential
  * @param Pdo $pdo
  * @param Logger $logger
  */
 public function __construct(Credential $credential, Pdo $pdo, Logger $logger)
 {
     $whatsprot = new WhatsProt($credential->username, $credential->nickname);
     $repository = new Messages($pdo);
     $this->receiver = new Receiver($whatsprot, $repository, $logger);
     $this->transmitter = new Transmitter($whatsprot, $repository, $logger);
     $this->receiver->registerCallbacks();
     $this->transmitter->registerCallbacks();
     $logger->log("connect to Whatsapp as {$credential->username}");
     $whatsprot->connect();
     $whatsprot->loginWithPassword($credential->password);
     $whatsprot->sendGetClientConfig();
     $whatsprot->sendGetServerProperties();
     $whatsprot->sendGetGroups();
     $whatsprot->sendGetBroadcastLists();
 }
示例#3
0
 public function pollMessages()
 {
     $this->whatsprot->pollMessage();
     $this->whatsprot->sendPing();
 }