/**
  * 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');
 }