public function receiveMessage(PhabricatorBotMessage $message)
 {
     switch ($message->getCommand()) {
         case 'MESSAGE':
             $target = $message->getTarget();
             if (!$target->isPublic()) {
                 // Don't log private messages, although maybe we should for debugging?
                 break;
             }
             $target_name = $target->getName();
             $logs = array(array('channel' => $target_name, 'type' => 'mesg', 'epoch' => time(), 'author' => $message->getSender()->getName(), 'message' => $message->getBody(), 'serviceName' => $this->getServiceName(), 'serviceType' => $this->getServiceType()));
             $this->futures[] = $this->getConduit()->callMethod('chatlog.record', array('logs' => $logs));
             $prompts = array('/where is the (chat)?log\\?/i', '/where am i\\?/i', '/what year is (this|it)\\?/i');
             $tell = false;
             foreach ($prompts as $prompt) {
                 if (preg_match($prompt, $message->getBody())) {
                     $tell = true;
                     break;
                 }
             }
             if ($tell) {
                 $response = $this->getURI('/chatlog/channel/' . phutil_escape_uri($target_name) . '/');
                 $this->replyTo($message, $response);
             }
             break;
     }
 }
 public function replyTo(PhabricatorBotMessage $original_message, $body)
 {
     if ($original_message->getCommand() != 'MESSAGE') {
         throw new Exception('Handler is trying to reply to something which is not a message!');
     }
     $reply = id(new PhabricatorBotMessage())->setCommand('MESSAGE');
     if ($original_message->getTarget()->isPublic()) {
         // This is a public target, like a chatroom. Send the response to the
         // chatroom.
         $reply->setTarget($original_message->getTarget());
     } else {
         // This is a private target, like a private message. Send the response
         // back to the sender (presumably, we are the target).
         $reply->setTarget($original_message->getSender());
     }
     $reply->setBody($body);
     return $this->writeMessage($reply);
 }
 private function routeMessage(PhabricatorBotMessage $message)
 {
     $ignore = $this->getConfig('ignore');
     if ($ignore) {
         $sender = $message->getSender();
         if ($sender && in_array($sender->getName(), $ignore)) {
             return;
         }
     }
     if ($message->getCommand() == 'LOG') {
         $this->log('[LOG] ' . $message->getBody());
     }
     foreach ($this->handlers as $handler) {
         try {
             $handler->receiveMessage($message);
         } catch (Exception $ex) {
             phlog($ex);
         }
     }
 }