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.common.js +87 -23
- package/dist/index.common.js.map +1 -1
- package/dist/index.umd.js +87 -23
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +3 -3
- package/dist/index.umd.min.js.map +1 -1
- package/package.json +1 -1
package/dist/index.common.js
CHANGED
|
@@ -30932,10 +30932,28 @@ class ChatClientMgr {
|
|
|
30932
30932
|
}
|
|
30933
30933
|
}
|
|
30934
30934
|
async initChatAIs() {
|
|
30935
|
-
|
|
30936
|
-
|
|
30937
|
-
|
|
30938
|
-
|
|
30935
|
+
if (window.imClient) {
|
|
30936
|
+
this.chatAIClient = window.imClient;
|
|
30937
|
+
} else {
|
|
30938
|
+
let classDatas = await this.handler.getChatClientClasses();
|
|
30939
|
+
const {
|
|
30940
|
+
TencentCloudChat,
|
|
30941
|
+
TIMUploadPlugin
|
|
30942
|
+
} = classDatas;
|
|
30943
|
+
window.imClient = TencentCloudChat.create({
|
|
30944
|
+
SDKAppID: this.appSKID,
|
|
30945
|
+
// 替换为你的 SDKAppID
|
|
30946
|
+
storage: {
|
|
30947
|
+
enable: true // 启用存储(可选,根据需求)
|
|
30948
|
+
}
|
|
30949
|
+
});
|
|
30950
|
+
window.imClient.registerPlugin({
|
|
30951
|
+
"tim-upload-plugin": TIMUploadPlugin
|
|
30952
|
+
});
|
|
30953
|
+
window.imClient.on(TencentCloudChat.EVENT.SDK_READY, this.onChatAIReady.bind(this));
|
|
30954
|
+
window.imClient.charAIs = {};
|
|
30955
|
+
this.chatAIClient = window.imClient;
|
|
30956
|
+
}
|
|
30939
30957
|
if (!this.chatAIClient.charAIs) {
|
|
30940
30958
|
this.chatAIClient.charAIs = {};
|
|
30941
30959
|
}
|
|
@@ -30947,19 +30965,7 @@ class ChatClientMgr {
|
|
|
30947
30965
|
robot.chatID = robotKey;
|
|
30948
30966
|
let userSig = await this.handler.getPortalUserSig(robotKey, this.imType, this.groupID);
|
|
30949
30967
|
if (!userSig) {
|
|
30950
|
-
|
|
30951
|
-
SDKAppID: this.appSKID,
|
|
30952
|
-
userID: robotKey
|
|
30953
|
-
});
|
|
30954
|
-
userSig = sigIDObject.userSig;
|
|
30955
|
-
if (userSig) {
|
|
30956
|
-
await this.chatAIClient.login({
|
|
30957
|
-
userID: robotKey,
|
|
30958
|
-
userSig: userSig
|
|
30959
|
-
});
|
|
30960
|
-
await this.chatAIClient.logout();
|
|
30961
|
-
await this.handler.addIMMapping(robotKey, this.imType, userSig, this.groupID);
|
|
30962
|
-
}
|
|
30968
|
+
userSig = await this.generateUserSigAndAdd(robotKey);
|
|
30963
30969
|
}
|
|
30964
30970
|
robot.userSig = userSig;
|
|
30965
30971
|
this.chatAIClient.charAIs[robotKey] = {
|
|
@@ -30970,6 +30976,44 @@ class ChatClientMgr {
|
|
|
30970
30976
|
});
|
|
30971
30977
|
}
|
|
30972
30978
|
}
|
|
30979
|
+
async generateUserSigAndUpdate(robotKey) {
|
|
30980
|
+
let sigIDObject = await this.handler.genTestUserSig({
|
|
30981
|
+
SDKAppID: this.appSKID,
|
|
30982
|
+
userID: robotKey
|
|
30983
|
+
});
|
|
30984
|
+
let userSig = sigIDObject.userSig;
|
|
30985
|
+
if (userSig) {
|
|
30986
|
+
await this.chatAIClient.login({
|
|
30987
|
+
userID: robotKey,
|
|
30988
|
+
userSig: userSig
|
|
30989
|
+
});
|
|
30990
|
+
await this.chatAIClient.logout();
|
|
30991
|
+
let data = {
|
|
30992
|
+
userID: robotKey,
|
|
30993
|
+
userSig: userSig,
|
|
30994
|
+
im_type: this.imType,
|
|
30995
|
+
group_id: this.groupID
|
|
30996
|
+
};
|
|
30997
|
+
await this.handler.updateIMMapping(data);
|
|
30998
|
+
}
|
|
30999
|
+
return userSig;
|
|
31000
|
+
}
|
|
31001
|
+
async generateUserSigAndAdd(robotKey) {
|
|
31002
|
+
let sigIDObject = await this.handler.genTestUserSig({
|
|
31003
|
+
SDKAppID: this.appSKID,
|
|
31004
|
+
userID: robotKey
|
|
31005
|
+
});
|
|
31006
|
+
let userSig = sigIDObject.userSig;
|
|
31007
|
+
if (userSig) {
|
|
31008
|
+
await this.chatAIClient.login({
|
|
31009
|
+
userID: robotKey,
|
|
31010
|
+
userSig: userSig
|
|
31011
|
+
});
|
|
31012
|
+
await this.chatAIClient.logout();
|
|
31013
|
+
await this.handler.addIMMapping(robotKey, this.imType, userSig, this.groupID);
|
|
31014
|
+
}
|
|
31015
|
+
return userSig;
|
|
31016
|
+
}
|
|
30973
31017
|
onChatAIReady(event) {
|
|
30974
31018
|
let robotID = this.chatAIClient.lastRobotID;
|
|
30975
31019
|
let robotInfo = this.getAIRobotInfoByID(robotID);
|
|
@@ -31008,10 +31052,30 @@ class ChatClientMgr {
|
|
|
31008
31052
|
if (this.chatAIClient.lastRobotID) {
|
|
31009
31053
|
await this.chatAIClient.logout();
|
|
31010
31054
|
}
|
|
31011
|
-
|
|
31012
|
-
|
|
31013
|
-
|
|
31014
|
-
|
|
31055
|
+
try {
|
|
31056
|
+
await this.chatAIClient.login({
|
|
31057
|
+
userID: robotID,
|
|
31058
|
+
userSig: robotInfo.userSig
|
|
31059
|
+
});
|
|
31060
|
+
} catch (err) {
|
|
31061
|
+
console.log(`[AI chat]${robotInfo.name}登录失败`, err);
|
|
31062
|
+
let code = err.code;
|
|
31063
|
+
if (code == 70001) {
|
|
31064
|
+
console.log(`[AI chat]${robotInfo.name}UserSig过期,重新生成userSig`);
|
|
31065
|
+
let newUserSig = await this.generateUserSigAndUpdate(robotID);
|
|
31066
|
+
try {
|
|
31067
|
+
await this.chatAIClient.login({
|
|
31068
|
+
userID: robotID,
|
|
31069
|
+
userSig: newUserSig
|
|
31070
|
+
});
|
|
31071
|
+
this.sendMessageToChatServer(robotID, messageOption);
|
|
31072
|
+
return;
|
|
31073
|
+
} catch (err) {
|
|
31074
|
+
console.log(`[AI chat]${robotInfo.name}重新登录失败`, err);
|
|
31075
|
+
return;
|
|
31076
|
+
}
|
|
31077
|
+
}
|
|
31078
|
+
}
|
|
31015
31079
|
}
|
|
31016
31080
|
this.chatAIClient.lastRobotID = robotID;
|
|
31017
31081
|
if (this.chatAIClient && this.chatAIClient.isReady()) {
|
|
@@ -31081,8 +31145,8 @@ const getIMHanlder = customerHanlder => {
|
|
|
31081
31145
|
genTestUserSig: async data => {
|
|
31082
31146
|
// return genTestUserSig(data);
|
|
31083
31147
|
},
|
|
31084
|
-
|
|
31085
|
-
return
|
|
31148
|
+
getChatClientClasses: async () => {
|
|
31149
|
+
return [];
|
|
31086
31150
|
},
|
|
31087
31151
|
getAIRobotInfos: async (user_id, groupID) => {
|
|
31088
31152
|
return getAIRobotInfos(user_id, groupID);
|