/**
  * Get the detail information of the helpDesk setting
  *
  * <b>Request Type: </b>GET<br/>
  * <b>Request Endpoint: </b>http://{server-domain}/api/helpdesk/settings<br/>
  * <b>Content-type: </b>Application/json<br/>
  * <b>Summary: </b>This api is for get the detail information of the helpDesk setting.<br/>
  *
  * <b>Response Example: </b>
  * <pre>
  *     {
  *          "maxW*aitTim": 3,
  *          "maxClient": 5,
  *          "ondutyTime": "8:00",
  *          "offdutyTime": "18:00",
  *          "systemReplies": [
  *              {
  *                  "name": "wait_for_service",
  *                  "type": "waitting",
  *                  "replyText": "wait",
  *                  "isEnabled": true
  *              },
  *              {
  *                  "name": "close_service",
  *                  "type": "close",
  *                  "replyText": "close",
  *                  "isEnabled": true
  *              },
  *              {
  *                  "name": "non_working_time",
  *                  "type": "nonworking",
  *                  "replyText": "non working time",
  *                  "isEnabled": true
  *              },
  *              {
  *                  "name": "auto_brake",
  *                  "type": "brake",
  *                  "replyText": "brake",
  *                  "isEnabled": true
  *              },
  *              {
  *                  "name": "connect_success",
  *                  "type": "success",
  *                  "replyText": "success",
  *                  "isEnabled": true
  *              },
  *              {
  *                  "name": "desk_droping",
  *                  "type": "droping",
  *                  "replyText": "droping",
  *                  "isEnabled": true
  *              }
  *          ]
  *      }
  * </pre>
  */
 public function actionIndex()
 {
     $accountId = $this->getAccountId();
     if (!$accountId) {
         $accountId = $this->getQuery('cid');
     }
     if (empty($accountId)) {
         throw new BadRequestHttpException("AccountId is required");
     }
     return HelpDeskSetting::getInstance($accountId);
 }
 /**
  * Add a channel into help desk setting
  *
  * <b>Request Type: </b>PUT<br/>
  * <b>Request Endpoint: </b>http://{server-domain}/api/helpdesk/setting/add-channel<br/>
  * <b>Content-type: </b>Application/json<br/>
  * <b>Summary: </b>This api is for adding a channel into help desk setting.<br/>
  *
  * <b>Request Example: </b>
  * <pre>
  *     {
  *          "settingId": '52d791327ae252f9149547cb',
  *          "channelId": '52d791307ae252f9149547c9'
  *     }
  * </pre>
  */
 public function actionAddChannel()
 {
     $settingId = $this->getParams('settingId');
     $channelIdStr = $this->getParams('channelId');
     $accountId = $this->getAccountId();
     if (!empty($channelIdStr) && !empty($settingId)) {
         $channelIds = explode(',', $channelIdStr);
         $helpDeskSetting = HelpDeskSetting::getInstance($accountId);
         $customerServicesSessionExpire = intval($helpDeskSetting->maxWaitTime) * 60 * 1000;
         $channels = [];
         foreach ($channelIds as $channelId) {
             array_push($channels, ['id' => $channelId, 'isSet' => false]);
             $accessToken = Token::createForWechat($accountId);
             Yii::$app->weConnect->updateCustomerServiceSetting($channelId, $customerServicesSessionExpire, $accessToken->accessToken);
         }
         $settingId = new \MongoId($settingId);
         // Add a channel into help desk setting
         $result = HelpDeskSetting::updateAll(['$addToSet' => ['channels' => ['$each' => $channels]]], ['_id' => $settingId]);
         if ($result) {
             return $channels;
         }
         throw new ServerErrorHttpException('add channel fail');
     }
     throw new BadRequestHttpException('parameters missing');
 }
示例#3
0
 /**
  * Send reply message to WeConnect user by type
  * @param array $client
  * @param string $accountId
  * @param string $type
  */
 public static function sendSystemReplyByType($client, $accountId, $type, $content = null)
 {
     $needReplySourceArray = [ChatConversation::TYPE_WECHAT, ChatConversation::TYPE_WEIBO, ChatConversation::TYPE_ALIPAY];
     if (in_array($client['source'], $needReplySourceArray)) {
         $helpDeskSetting = HelpDeskSetting::getInstance($accountId);
         $defaultSystemReplies = $helpDeskSetting->systemReplies;
         if ($type !== HelpDeskSetting::REPLY_CUSTOM) {
             foreach ($defaultSystemReplies as $defaultSystemReply) {
                 if ($defaultSystemReply['type'] === $type) {
                     $content = $defaultSystemReply['isEnabled'] ? $defaultSystemReply['replyText'] : '';
                 }
             }
         }
         if (!empty($content)) {
             $message = ['msgType' => ChatMessage::MSG_TYPE_TEXT, 'content' => $content, 'createTime' => TimeUtil::msTime()];
             Yii::$app->weConnect->sendCustomerServiceMessage($client['openId'], $client['sourceChannel'], $message);
         } else {
             if ($content === null) {
                 throw new ServerErrorHttpException('Incorrect name for default helpdesk system reply');
             }
         }
     }
 }