isdata-customer-sdk 0.1.65 → 0.1.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -30942,10 +30942,28 @@ class ChatClientMgr {
30942
30942
  }
30943
30943
  }
30944
30944
  async initChatAIs() {
30945
- this.chatAIClient = await this.handler.getChatClient({
30946
- appSKID: this.appSKID,
30947
- onReady: this.onChatAIReady.bind(this)
30948
- });
30945
+ if (window.imClient) {
30946
+ this.chatAIClient = window.imClient;
30947
+ } else {
30948
+ let classDatas = await this.handler.getChatClientClasses();
30949
+ const {
30950
+ TencentCloudChat,
30951
+ TIMUploadPlugin
30952
+ } = classDatas;
30953
+ window.imClient = TencentCloudChat.create({
30954
+ SDKAppID: this.appSKID,
30955
+ // 替换为你的 SDKAppID
30956
+ storage: {
30957
+ enable: true // 启用存储(可选,根据需求)
30958
+ }
30959
+ });
30960
+ window.imClient.registerPlugin({
30961
+ "tim-upload-plugin": TIMUploadPlugin
30962
+ });
30963
+ window.imClient.on(TencentCloudChat.EVENT.SDK_READY, this.onChatAIReady.bind(this));
30964
+ window.imClient.charAIs = {};
30965
+ this.chatAIClient = window.imClient;
30966
+ }
30949
30967
  if (!this.chatAIClient.charAIs) {
30950
30968
  this.chatAIClient.charAIs = {};
30951
30969
  }
@@ -30957,19 +30975,7 @@ class ChatClientMgr {
30957
30975
  robot.chatID = robotKey;
30958
30976
  let userSig = await this.handler.getPortalUserSig(robotKey, this.imType, this.groupID);
30959
30977
  if (!userSig) {
30960
- let sigIDObject = await this.handler.genTestUserSig({
30961
- SDKAppID: this.appSKID,
30962
- userID: robotKey
30963
- });
30964
- userSig = sigIDObject.userSig;
30965
- if (userSig) {
30966
- await this.chatAIClient.login({
30967
- userID: robotKey,
30968
- userSig: userSig
30969
- });
30970
- await this.chatAIClient.logout();
30971
- await this.handler.addIMMapping(robotKey, this.imType, userSig, this.groupID);
30972
- }
30978
+ userSig = await this.generateUserSigAndUpdate(robotKey);
30973
30979
  }
30974
30980
  robot.userSig = userSig;
30975
30981
  this.chatAIClient.charAIs[robotKey] = {
@@ -30980,6 +30986,22 @@ class ChatClientMgr {
30980
30986
  });
30981
30987
  }
30982
30988
  }
30989
+ async generateUserSigAndUpdate(robotKey) {
30990
+ let sigIDObject = await this.handler.genTestUserSig({
30991
+ SDKAppID: this.appSKID,
30992
+ userID: robotKey
30993
+ });
30994
+ let userSig = sigIDObject.userSig;
30995
+ if (userSig) {
30996
+ await this.chatAIClient.login({
30997
+ userID: robotKey,
30998
+ userSig: userSig
30999
+ });
31000
+ await this.chatAIClient.logout();
31001
+ await this.handler.addIMMapping(robotKey, this.imType, userSig, this.groupID);
31002
+ }
31003
+ return userSig;
31004
+ }
30983
31005
  onChatAIReady(event) {
30984
31006
  let robotID = this.chatAIClient.lastRobotID;
30985
31007
  let robotInfo = this.getAIRobotInfoByID(robotID);
@@ -31018,10 +31040,30 @@ class ChatClientMgr {
31018
31040
  if (this.chatAIClient.lastRobotID) {
31019
31041
  await this.chatAIClient.logout();
31020
31042
  }
31021
- await this.chatAIClient.login({
31022
- userID: robotID,
31023
- userSig: robotInfo.userSig
31024
- });
31043
+ try {
31044
+ await this.chatAIClient.login({
31045
+ userID: robotID,
31046
+ userSig: robotInfo.userSig
31047
+ });
31048
+ } catch (err) {
31049
+ console.log(`[AI chat]${robotInfo.name}登录失败`, err);
31050
+ let code = err.code;
31051
+ if (code == 70001) {
31052
+ console.log(`[AI chat]${robotInfo.name}UserSig过期,重新生成userSig`);
31053
+ let newUserSig = await this.generateUserSigAndUpdate(robotID);
31054
+ try {
31055
+ await this.chatAIClient.login({
31056
+ userID: robotID,
31057
+ userSig: newUserSig
31058
+ });
31059
+ this.sendMessageToChatServer(robotID, messageOption);
31060
+ return;
31061
+ } catch (err) {
31062
+ console.log(`[AI chat]${robotInfo.name}重新登录失败`, err);
31063
+ return;
31064
+ }
31065
+ }
31066
+ }
31025
31067
  }
31026
31068
  this.chatAIClient.lastRobotID = robotID;
31027
31069
  if (this.chatAIClient && this.chatAIClient.isReady()) {