示例#1
0
 /**
  * @args {"description": "Delay: Clean offline client and helpdesk every minute"}
  */
 public function perform()
 {
     $accounts = Account::findAll([]);
     foreach ($accounts as $account) {
         $accountId = $account->_id;
         $setting = HelpDeskSetting::findOne(['accountId' => $accountId]);
         if (!empty($setting)) {
             $maxWaitTime = $setting->maxWaitTime;
             // Close timeout conversation
             $chatConversations = ChatConversation::findAll(['accountId' => $accountId, 'status' => ChatConversation::STATUS_OPEN, 'lastChatTime' => ['$lt' => TimeUtil::msTime(time() - $maxWaitTime * 60)]]);
             foreach ($chatConversations as $chatConversation) {
                 HelpDesk::disconnect($chatConversation->_id, ['type' => 'brake']);
             }
             // Delete timeout pending client
             $pendingClients = PendingClient::findAll(['accountId' => $accountId, 'lastPingTime' => ['$lt' => TimeUtil::msTime(time() - PendingClient::PING_THRESHOLD)]]);
             foreach ($pendingClients as $pendingClient) {
                 $pendingClient->delete();
             }
             // Clean offline helpdesk
             $cache = Yii::$app->cache;
             $onlineHelpDesks = $cache->get(HelpDesk::CACHE_PREFIX_HELPDESK_PING . $accountId);
             if (!empty($onlineHelpDesks)) {
                 foreach ($onlineHelpDesks as $deskId => $lastPingTime) {
                     if ($lastPingTime < TimeUtil::msTime(time() - HelpDesk::PING_THRESHOLD)) {
                         HelpDesk::leave($deskId, $accountId, ['type' => 'droping']);
                     }
                 }
             }
         }
     }
 }
示例#2
0
 public static function isHelpDeskSet($channelId, $accountId)
 {
     $accountId = new \MongoId($accountId);
     $setting = HelpDeskSetting::findOne(['accountId' => $accountId, 'channels.id' => $channelId]);
     if (!empty($setting)) {
         return true;
     }
     return false;
 }
示例#3
0
 /**
  * Create menu
  *
  * <b>Request Type</b>: POST<br/><br/>
  * <b>Request Endpoint</b>:http://{server-domain}/api/channel/menus<br/><br/>
  * <b>Response Content-type</b>: application/json<br/><br/>
  * <b>Summary</b>: This api is used to create/update menu.
  * <br/><br/>
  *
  * <b>Request Params</b>:<br/>
  *     channelId: string<br/>
  *     menu.name: string<br/>
  *     menu.keycode: string<br/>
  *     menu.type: string, VIEW or CLICK<br/>
  *     menu.subMenus.name: string<br/>
  *     menu.subMenus.type: string<br/>
  *     menu.subMenus.msgType: TEXT or NEWS<br/>
  *     menu.subMenus.content: string, if TEXT<br/>
  *     menu.subMenus.content.articles: array, if NEWS<br/>
  *     <br/><br/>
  *
  * <br/><br/>
  *
  * <b>Request Example</b>:<br/>
  * <pre>
  * {
  *  "channelId": "5473ffe7db7c7c2f0bee5c71",
  *  "menu": [
  *      {
  *          ...
  *      },
  *      {
  *          "name": "去踢球",
  *          "type": "CLICK",
  *          "subMenus": [
  *              {
  *                  "name": "menu1-sub1",
  *                  "type": "VIEW",
  *                  "msgType": "TEXT",
  *                  "content": "hello world"
  *              },
  *              {
  *                  "name": "menu1-sub2",
  *                  "type": "VIEW",
  *                  "msgType": "URL",
  *                  "content": "http://www.baidu.com"
  *              },
  *              {
  *                  "name": "menu1-sub3",
  *                  "type": "VIEW",
  *                  "msgType": "NEWS",
  *                  "content": {
  *                      "articles": [
  *                          {
  *                              "title": "新闻",
  *                              "description": "APEC会议举行第三天",
  *                              "sourceUrl": "http://www.baidu.com",
  *                              "picUrl": "http://www.baidu.com/image.jpg"
  *                          },
  *                          {
  *                              "title": "新闻",
  *                              "description": "APEC会议举行第三天",
  *                              "sourceUrl": "http://www.baidu.com",
  *                              "picUrl": "http://www.baidu.com/image.jpg"
  *                          }
  *                      ]
  *                  }
  *              }
  *          ]
  *      },
  *      {
  *          ...
  *      }
  *  ]
  * }
  *
  * <b>Response Params:</b><br/>
  *     msg: string, if query fail, it contains the error message<br/>
  *     <br/><br/>
  *
  * <br/><br/>
  *
  * <b>Response Example</b>:<br/>
  * <pre>
  * {
  *   "message": "OK"
  * }
  * </pre>
  */
 public function actionCreate()
 {
     $menu = $this->getParams();
     $channelId = $this->getChannelId();
     $accountId = $this->getAccountId();
     unset($menu['channelId']);
     $actions = Yii::$app->channelMenu->getMenuActions($channelId, $accountId, true);
     $result = Yii::$app->weConnect->createMenu($channelId, $menu['menu'], $actions);
     if ($result) {
         $conditon = ['accountId' => $accountId, 'channels.id' => $channelId];
         $helpDeskSetting = HelpDeskSetting::findOne($conditon);
         if (!empty($helpDeskSetting)) {
             $isSet = Yii::$app->weConnect->isSetHelpDesk($menu['menu']);
             $channelResult = HelpDeskSetting::updateAll(['$set' => ['channels.$.isSet' => $isSet]], $conditon);
             if (!$channelResult) {
                 throw new ServerErrorHttpException('Set menu channel status fail.');
             }
         }
         return ['message' => 'OK'];
     } else {
         throw new ServerErrorHttpException('Create menu fail.');
     }
 }