isdata-customer-sdk 0.1.64 → 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
@@ -29597,6 +29597,7 @@ __webpack_require__.d(__webpack_exports__, {
29597
29597
  getPortalUserInfo: function() { return /* reexport */ getPortalUserInfo; },
29598
29598
  getPortalUserMappingInfos: function() { return /* reexport */ getPortalUserMappingInfos; },
29599
29599
  getPortalUserSig: function() { return /* reexport */ getPortalUserSig; },
29600
+ getRobotInfoByID: function() { return /* reexport */ getRobotInfoByID; },
29600
29601
  getRoleIDsByUserAndGroupID: function() { return /* reexport */ getRoleIDsByUserAndGroupID; },
29601
29602
  getThirdAppPathByKey: function() { return /* reexport */ getThirdAppPathByKey; },
29602
29603
  getUrlParamValue: function() { return /* reexport */ getUrlParamValue; },
@@ -30845,6 +30846,7 @@ class ChatClientMgr {
30845
30846
  this.userID = params.userID;
30846
30847
  this.chatType = params.chatType || 0;
30847
30848
  this.singleChatID = params.singleChatID || "";
30849
+ this.customParams = params.customParams || {};
30848
30850
  this.chartOrigin = params.chartOrigin;
30849
30851
  console.log("ChatClientMgr init:", this.actionKey);
30850
30852
  // this.charAIs = {};
@@ -30916,7 +30918,8 @@ class ChatClientMgr {
30916
30918
  await this.initChatAIs();
30917
30919
  let charParams = {
30918
30920
  type: this.getChatTypeKey(this.chatType),
30919
- singleChatID: this.singleChatID
30921
+ singleChatID: this.singleChatID,
30922
+ customParams: this.customParams
30920
30923
  };
30921
30924
  console.log("charParams", charParams);
30922
30925
  this.handler.fireEventToChatWindow(event, this.chartOrigin, this.makeKey("sdata_alllife_initChat"), charParams, result => {
@@ -30939,10 +30942,28 @@ class ChatClientMgr {
30939
30942
  }
30940
30943
  }
30941
30944
  async initChatAIs() {
30942
- this.chatAIClient = await this.handler.getChatClient({
30943
- appSKID: this.appSKID,
30944
- onReady: this.onChatAIReady.bind(this)
30945
- });
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
+ }
30946
30967
  if (!this.chatAIClient.charAIs) {
30947
30968
  this.chatAIClient.charAIs = {};
30948
30969
  }
@@ -30954,19 +30975,7 @@ class ChatClientMgr {
30954
30975
  robot.chatID = robotKey;
30955
30976
  let userSig = await this.handler.getPortalUserSig(robotKey, this.imType, this.groupID);
30956
30977
  if (!userSig) {
30957
- let sigIDObject = await this.handler.genTestUserSig({
30958
- SDKAppID: this.appSKID,
30959
- userID: robotKey
30960
- });
30961
- userSig = sigIDObject.userSig;
30962
- if (userSig) {
30963
- await this.chatAIClient.login({
30964
- userID: robotKey,
30965
- userSig: userSig
30966
- });
30967
- await this.chatAIClient.logout();
30968
- await this.handler.addIMMapping(robotKey, this.imType, userSig, this.groupID);
30969
- }
30978
+ userSig = await this.generateUserSigAndUpdate(robotKey);
30970
30979
  }
30971
30980
  robot.userSig = userSig;
30972
30981
  this.chatAIClient.charAIs[robotKey] = {
@@ -30977,6 +30986,22 @@ class ChatClientMgr {
30977
30986
  });
30978
30987
  }
30979
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
+ }
30980
31005
  onChatAIReady(event) {
30981
31006
  let robotID = this.chatAIClient.lastRobotID;
30982
31007
  let robotInfo = this.getAIRobotInfoByID(robotID);
@@ -31015,10 +31040,30 @@ class ChatClientMgr {
31015
31040
  if (this.chatAIClient.lastRobotID) {
31016
31041
  await this.chatAIClient.logout();
31017
31042
  }
31018
- await this.chatAIClient.login({
31019
- userID: robotID,
31020
- userSig: robotInfo.userSig
31021
- });
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
+ }
31022
31067
  }
31023
31068
  this.chatAIClient.lastRobotID = robotID;
31024
31069
  if (this.chatAIClient && this.chatAIClient.isReady()) {
@@ -31071,6 +31116,18 @@ class ChatClientMgr {
31071
31116
 
31072
31117
 
31073
31118
 
31119
+
31120
+ const getRobotInfoByID = async (robotID, groupID) => {
31121
+ let queryData = {
31122
+ "param": {
31123
+ "id": robotID,
31124
+ "groupID": groupID
31125
+ }
31126
+ };
31127
+ let result = await request.post(`/dataservice/rest/orchestration/getRobotInfoByID`, queryData);
31128
+ let robotInfo = result.data.robotInfo;
31129
+ return robotInfo;
31130
+ };
31074
31131
  const getIMHanlder = customerHanlder => {
31075
31132
  let handler = {
31076
31133
  genTestUserSig: async data => {