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); } } }
/** * 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(); }
public function pollMessages() { $this->whatsprot->pollMessage(); $this->whatsprot->sendPing(); }