isdata-customer-sdk 0.1.65 → 0.1.67

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.generateUserSigAndAdd(robotKey);
30973
30979
  }
30974
30980
  robot.userSig = userSig;
30975
30981
  this.chatAIClient.charAIs[robotKey] = {
@@ -30980,6 +30986,44 @@ 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
+ let data = {
31002
+ userID: robotKey,
31003
+ userSig: userSig,
31004
+ im_type: this.imType,
31005
+ group_id: this.groupID
31006
+ };
31007
+ await this.handler.updateIMMapping(data);
31008
+ }
31009
+ return userSig;
31010
+ }
31011
+ async generateUserSigAndAdd(robotKey) {
31012
+ let sigIDObject = await this.handler.genTestUserSig({
31013
+ SDKAppID: this.appSKID,
31014
+ userID: robotKey
31015
+ });
31016
+ let userSig = sigIDObject.userSig;
31017
+ if (userSig) {
31018
+ await this.chatAIClient.login({
31019
+ userID: robotKey,
31020
+ userSig: userSig
31021
+ });
31022
+ await this.chatAIClient.logout();
31023
+ await this.handler.addIMMapping(robotKey, this.imType, userSig, this.groupID);
31024
+ }
31025
+ return userSig;
31026
+ }
30983
31027
  onChatAIReady(event) {
30984
31028
  let robotID = this.chatAIClient.lastRobotID;
30985
31029
  let robotInfo = this.getAIRobotInfoByID(robotID);
@@ -31018,10 +31062,30 @@ class ChatClientMgr {
31018
31062
  if (this.chatAIClient.lastRobotID) {
31019
31063
  await this.chatAIClient.logout();
31020
31064
  }
31021
- await this.chatAIClient.login({
31022
- userID: robotID,
31023
- userSig: robotInfo.userSig
31024
- });
31065
+ try {
31066
+ await this.chatAIClient.login({
31067
+ userID: robotID,
31068
+ userSig: robotInfo.userSig
31069
+ });
31070
+ } catch (err) {
31071
+ console.log(`[AI chat]${robotInfo.name}登录失败`, err);
31072
+ let code = err.code;
31073
+ if (code == 70001) {
31074
+ console.log(`[AI chat]${robotInfo.name}UserSig过期,重新生成userSig`);
31075
+ let newUserSig = await this.generateUserSigAndUpdate(robotID);
31076
+ try {
31077
+ await this.chatAIClient.login({
31078
+ userID: robotID,
31079
+ userSig: newUserSig
31080
+ });
31081
+ this.sendMessageToChatServer(robotID, messageOption);
31082
+ return;
31083
+ } catch (err) {
31084
+ console.log(`[AI chat]${robotInfo.name}重新登录失败`, err);
31085
+ return;
31086
+ }
31087
+ }
31088
+ }
31025
31089
  }
31026
31090
  this.chatAIClient.lastRobotID = robotID;
31027
31091
  if (this.chatAIClient && this.chatAIClient.isReady()) {
@@ -31091,8 +31155,8 @@ const getIMHanlder = customerHanlder => {
31091
31155
  genTestUserSig: async data => {
31092
31156
  // return genTestUserSig(data);
31093
31157
  },
31094
- getChatClient: async () => {
31095
- return window.imClient;
31158
+ getChatClientClasses: async () => {
31159
+ return [];
31096
31160
  },
31097
31161
  getAIRobotInfos: async (user_id, groupID) => {
31098
31162
  return getAIRobotInfos(user_id, groupID);