protected function execute(ConduitAPIRequest $request)
 {
     $revision = id(new DifferentialRevision())->load($request->getValue('revision_id'));
     if (!$revision) {
         throw new ConduitException('ERR_BAD_REVISION');
     }
     $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_CONDUIT, array());
     $editor = new DifferentialCommentEditor($revision, $request->getUser()->getPHID(), DifferentialAction::ACTION_COMMENT);
     $editor->setContentSource($content_source);
     $editor->setMessage($request->getValue('message'));
     $editor->save();
     return array('revisionid' => $revision->getID(), 'uri' => PhabricatorEnv::getURI('/D' . $revision->getID()));
 }
 public function handleAction($body)
 {
     // all commands start with a bang and separated from the body by a newline
     // to make sure that actual feedback text couldn't trigger an action.
     // unrecognized commands will be parsed as part of the comment.
     $command = DifferentialAction::ACTION_COMMENT;
     $supported_commands = $this->getSupportedCommands();
     $regex = "/\\A\n*!(" . implode('|', $supported_commands) . ")\n*/";
     $matches = array();
     if (preg_match($regex, $body, $matches)) {
         $command = $matches[1];
         $body = trim(str_replace('!' . $command, '', $body));
     }
     $actor = $this->getActor();
     if (!$actor) {
         throw new Exception('No actor is set for the reply action.');
     }
     switch ($command) {
         case 'unsubscribe':
             $this->unsubscribeUser($this->getMailReceiver(), $actor);
             // TODO: Send the user a confirmation email?
             return null;
     }
     try {
         $editor = new DifferentialCommentEditor($this->getMailReceiver(), $actor->getPHID(), $command);
         // NOTE: We have to be careful about this because Facebook's
         // implementation jumps straight into handleAction() and will not have
         // a PhabricatorMetaMTAReceivedMail object.
         if ($this->receivedMail) {
             $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_EMAIL, array('id' => $this->receivedMail->getID()));
             $editor->setContentSource($content_source);
             $editor->setParentMessageID($this->receivedMail->getMessageID());
         }
         $editor->setMessage($body);
         $comment = $editor->save();
         return $comment->getID();
     } catch (Exception $ex) {
         $exception_mail = new DifferentialExceptionMail($this->getMailReceiver(), $ex, $this->receivedMail->getRawTextBody());
         $exception_mail->setToPHIDs(array($this->getActor()->getPHID()));
         $exception_mail->send();
         throw $ex;
     }
 }