Пример #1
0
 public function testPollRespondsToKeyWordMessage()
 {
     $slackTimestamp = SlackTimestamp::createFromDatetimeAndCounter(new \DateTime('-1 hour'), 0);
     $this->mockSince->expects(self::once())->method('getLastTime')->willReturn($slackTimestamp);
     $this->mockSlack->expects(self::once())->method('getMessages')->willReturn([new SlackMessage(Input::KEYWORD . ' does respond to', $slackTimestamp)]);
     $message = $this->input->poll();
     self::assertInstanceOf(InputMessage::class, $message);
     self::assertFalse($message->isEmpty());
     self::assertEquals(' does respond to', $message->toString());
 }
Пример #2
0
 /**
  * @return MessageInterface
  */
 public function poll()
 {
     $messages = $this->slack->getMessages($this->since->getLastTime());
     $returnValue = InputMessage::createFromNothing();
     foreach ($messages as $message) {
         if ($returnValue->isEmpty() === true && \strtolower(\substr($message->toString(), 0, \strlen(self::KEYWORD))) == self::KEYWORD) {
             $this->logger->info(self::class . ": " . $message->toString());
             $returnValue = InputMessage::createFromString(\substr($message->toString(), \strlen(self::KEYWORD)));
             $this->since->update($message->getTimestamp());
         }
     }
     if ($returnValue->isEmpty()) {
         $this->logger->info(self::class . ': No Message', ['messages' => $messages]);
         $this->since->update(SlackTimestamp::createNow());
     }
     return $returnValue;
 }
Пример #3
0
 /**
  * @param MessageInterface $message
  */
 public function handleMessage(MessageInterface $message)
 {
     if ($message->isEmpty() === false) {
         $this->slack->sendMessage(Message::createFromString('Repyling to: ' . $message->toString()));
     }
 }