/**
  * Get last message
  *
  * <b>Request Type: </b>GET<br/>
  * <b>Request Endpoint: </b>http://{server-domain}/api/chat/conversation/last-message?deskId={deskId}&clientOpenId={clientId}
  * <b>Summary: </b> This api is for get last message.<br/>
  *
  * <b>Request Parameters: </b><br/>
  *     accesstoken: string<br/>
  *     deskId: string, id of the desk.<br/>
  *     clientOpenId: string, the openId of the client.<br/>
  *     reply: string, 'desk' or 'client'<br/>
  *
  * <b>Response Example: </b><br/>
  *  {
  *      "id": "54d463f7e9c2fb21298b456e",
  *      "content": {
  *          "msgType": "TEXT",
  *          "body": "sssssd"
  *      },
  *      "isReply": true,
  *      "conversationId": "54d463b9e9c2fb452c8b4570",
  *      "sentTime": 1425277485000
  *  }
  */
 public function actionLastMessage()
 {
     $deskId = $this->getQuery('deskId');
     $clientOpenId = $this->getQuery('clientOpenId');
     $reply = $this->getQuery('reply');
     if ($reply == 'desk') {
         $isReply = true;
     } else {
         if ($reply == 'client') {
             $isReply = false;
         } else {
             $isReply = null;
         }
     }
     if (empty($deskId) || empty($clientOpenId)) {
         throw new BadRequestHttpException('Missing required fields');
     }
     $accountId = $this->getAccountId();
     $deskId = new \MongoId($deskId);
     $conversations = ChatConversation::getHistory($deskId, $clientOpenId, $accountId, 0, 1);
     if (empty($conversations) || empty($conversations[0])) {
         return null;
     } else {
         $conversation = $conversations[0];
         $message = ChatMessage::getLastMessage($conversation->_id, $isReply);
         $result = ['id' => (string) $message['_id'], 'conversationId' => (string) $message['conversationId'], 'content' => $message['content'], 'isReply' => $message['isReply'], 'sentTime' => $message['sentTime']];
         return $result;
     }
 }