isdata-customer-sdk 0.1.58 → 0.1.60
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.js → index.common.js} +287 -0
- package/dist/index.common.js.map +1 -0
- package/dist/index.umd.js +287 -0
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +4 -4
- package/dist/index.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/dist/index.js.map +0 -1
package/dist/index.umd.js
CHANGED
|
@@ -29561,6 +29561,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
29561
29561
|
|
|
29562
29562
|
// EXPORTS
|
|
29563
29563
|
__webpack_require__.d(__webpack_exports__, {
|
|
29564
|
+
ChatClientMgr: function() { return /* reexport */ ChatClientMgr; },
|
|
29564
29565
|
addEventAction: function() { return /* reexport */ addEventAction; },
|
|
29565
29566
|
addIMMapping: function() { return /* reexport */ addIMMapping; },
|
|
29566
29567
|
addObjectUsedTimes: function() { return /* reexport */ addObjectUsedTimes; },
|
|
@@ -29577,6 +29578,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
29577
29578
|
getChildrenOfficeInfosByID: function() { return /* reexport */ getChildrenOfficeInfosByID; },
|
|
29578
29579
|
getCurrentUserPortalPageID: function() { return /* reexport */ getCurrentUserPortalPageID; },
|
|
29579
29580
|
getGroupMappingsByAccount: function() { return /* reexport */ getGroupMappingsByAccount; },
|
|
29581
|
+
getIMHanlder: function() { return /* reexport */ getIMHanlder; },
|
|
29580
29582
|
getIntegrateAppInfoByID: function() { return /* reexport */ getIntegrateAppInfoByID; },
|
|
29581
29583
|
getKey: function() { return /* reexport */ getKey; },
|
|
29582
29584
|
getLoginPageNotices: function() { return /* reexport */ getLoginPageNotices; },
|
|
@@ -30829,12 +30831,297 @@ const sendWindowMessage = async (targetWindow, originKey, eventKey, data, callba
|
|
|
30829
30831
|
};
|
|
30830
30832
|
targetWindow.postMessage(postData, originKey);
|
|
30831
30833
|
};
|
|
30834
|
+
;// ./src/api/chat/ChatClientMgr.js
|
|
30835
|
+
|
|
30836
|
+
|
|
30837
|
+
|
|
30838
|
+
class ChatClientMgr {
|
|
30839
|
+
constructor(params, handler) {
|
|
30840
|
+
this.handler = handler;
|
|
30841
|
+
this.actionKey = params.actionKey;
|
|
30842
|
+
this.appSKID = params.appSKID;
|
|
30843
|
+
this.imType = params.imType;
|
|
30844
|
+
this.groupID = params.groupID;
|
|
30845
|
+
this.userID = params.userID;
|
|
30846
|
+
this.chatType = params.chatType || 0;
|
|
30847
|
+
this.singleChatID = params.singleChatID || "";
|
|
30848
|
+
this.chartOrigin = params.chartOrigin;
|
|
30849
|
+
this.charAIs = {};
|
|
30850
|
+
}
|
|
30851
|
+
makeKey(key) {
|
|
30852
|
+
return `${key}-${this.actionKey}`;
|
|
30853
|
+
}
|
|
30854
|
+
async init() {
|
|
30855
|
+
this.handler.addChatListener(this.makeKey(`sdata_get_access_token`), async data => {
|
|
30856
|
+
return await this.handler.getPortalAccessToken(data);
|
|
30857
|
+
});
|
|
30858
|
+
this.handler.addChatListener(this.makeKey(`sdata_get_portal_user_info`), async data => {
|
|
30859
|
+
return await this.handler.getPortalUserInfo(data);
|
|
30860
|
+
});
|
|
30861
|
+
this.handler.addChatListener(this.makeKey(`sdata_get_portal_user_sig`), async data => {
|
|
30862
|
+
let userID = data.userID;
|
|
30863
|
+
let platType = data.im_type;
|
|
30864
|
+
let groupID = data.group_id;
|
|
30865
|
+
return await this.handler.getPortalUserSig(userID, platType, groupID);
|
|
30866
|
+
});
|
|
30867
|
+
this.handler.addChatListener(this.makeKey(`sdata_add_im_mapping`), async data => {
|
|
30868
|
+
let userID = data.userID;
|
|
30869
|
+
let platType = data.im_type;
|
|
30870
|
+
let userSig = data.userSig;
|
|
30871
|
+
return await this.handler.addIMMapping(userID, platType, userSig, this.groupID);
|
|
30872
|
+
});
|
|
30873
|
+
this.handler.addChatListener(this.makeKey(`sdata_update_im_mapping`), async data => {
|
|
30874
|
+
return await this.handler.updateIMMapping(data);
|
|
30875
|
+
});
|
|
30876
|
+
this.handler.addChatListener(this.makeKey(`sdata_get_users_by_group_id`), async data => {
|
|
30877
|
+
return await this.handler.getAllUserInfosByGroupID(data);
|
|
30878
|
+
});
|
|
30879
|
+
this.handler.addChatListener(this.makeKey(`sdata_get_dpts_by_group_id`), async data => {
|
|
30880
|
+
return await this.handler.getChildrenOfficeInfosByID(data);
|
|
30881
|
+
});
|
|
30882
|
+
this.handler.addChatListener(this.makeKey(`sdata_get_project_dpts_by_user_group_id`), async data => {
|
|
30883
|
+
return await this.handler.getPojectDptsByUserAndGroupID(data);
|
|
30884
|
+
});
|
|
30885
|
+
this.handler.addChatListener(this.makeKey(`sdata_get_ai_robot_infos`), async data => {
|
|
30886
|
+
let groupID = data.groupID;
|
|
30887
|
+
let userID = data.userID;
|
|
30888
|
+
if (this.userID == userID && this.groupID == groupID) {
|
|
30889
|
+
return this.getAIRobotInfos();
|
|
30890
|
+
}
|
|
30891
|
+
return [];
|
|
30892
|
+
});
|
|
30893
|
+
this.handler.addChatListener(this.makeKey(`sdata_get_test_user_sig`), data => {
|
|
30894
|
+
let sdkAppID = data.SDKAppID;
|
|
30895
|
+
let userID = data.userID;
|
|
30896
|
+
let sigIDObject = this.handler.genTestUserSig({
|
|
30897
|
+
SDKAppID: sdkAppID,
|
|
30898
|
+
userID: userID
|
|
30899
|
+
});
|
|
30900
|
+
let sigID = sigIDObject.userSig;
|
|
30901
|
+
return sigID;
|
|
30902
|
+
});
|
|
30903
|
+
this.handler.addChatListener(this.makeKey(`sdata_send_message_to_chat_server`), async (data, event) => {
|
|
30904
|
+
let message = data.message;
|
|
30905
|
+
let robotID = message.from;
|
|
30906
|
+
let result = await this.sendMessageToChatServer(robotID, message);
|
|
30907
|
+
return result;
|
|
30908
|
+
});
|
|
30909
|
+
this.handler.addChatListener(this.makeKey(`sdata_close_frame_window`), async (data, event) => {
|
|
30910
|
+
return this.handler.closeWindow();
|
|
30911
|
+
});
|
|
30912
|
+
this.handler.addChatListener(this.makeKey(`sdata_alllife_event_regist`), async (data, event) => {
|
|
30913
|
+
this.appSKID = data.appid;
|
|
30914
|
+
this.imType = data.im_type;
|
|
30915
|
+
await this.initChatAIs();
|
|
30916
|
+
let charParams = {
|
|
30917
|
+
type: this.getChatTypeKey(this.chatType),
|
|
30918
|
+
singleChatID: this.singleChatID
|
|
30919
|
+
};
|
|
30920
|
+
console.log("charParams", charParams);
|
|
30921
|
+
this.handler.fireEventToChatWindow(event, this.chartOrigin, this.makeKey("sdata_alllife_initChat"), charParams, result => {
|
|
30922
|
+
if (result) {
|
|
30923
|
+
this.handler.onChatInitFinished();
|
|
30924
|
+
}
|
|
30925
|
+
});
|
|
30926
|
+
});
|
|
30927
|
+
}
|
|
30928
|
+
getChatTypeKey(type) {
|
|
30929
|
+
return type == 1 ? "IM_SINGLE_MODE" : "IM_MULTIPLE_MODE";
|
|
30930
|
+
}
|
|
30931
|
+
async initChatAIs() {
|
|
30932
|
+
this.chatAIClient = await this.handler.getChatClient({
|
|
30933
|
+
appSKID: this.appSKID,
|
|
30934
|
+
onReady: this.onChatAIReady.bind(this)
|
|
30935
|
+
});
|
|
30936
|
+
let robotInfos = await this.handler.getAIRobotInfos(this.userID, this.groupID);
|
|
30937
|
+
if (robotInfos && robotInfos.length > 0) {
|
|
30938
|
+
robotInfos.forEach(async robot => {
|
|
30939
|
+
let robotKey = robot.id;
|
|
30940
|
+
robot.chatID = robotKey;
|
|
30941
|
+
let userSig = await this.handler.getPortalUserSig(robotKey, this.imType, this.groupID);
|
|
30942
|
+
if (!userSig) {
|
|
30943
|
+
let sigIDObject = this.handler.genTestUserSig({
|
|
30944
|
+
SDKAppID: this.appSKID,
|
|
30945
|
+
userID: robotKey
|
|
30946
|
+
});
|
|
30947
|
+
userSig = sigIDObject.userSig;
|
|
30948
|
+
await this.handler.addIMMapping(robotKey, this.imType, userSig, this.groupID);
|
|
30949
|
+
}
|
|
30950
|
+
robot.userSig = userSig;
|
|
30951
|
+
this.charAIs[robotKey] = {
|
|
30952
|
+
robot: robot,
|
|
30953
|
+
messageCache: []
|
|
30954
|
+
};
|
|
30955
|
+
});
|
|
30956
|
+
}
|
|
30957
|
+
}
|
|
30958
|
+
onChatAIReady(event) {
|
|
30959
|
+
let robotID = this.lastRobotID;
|
|
30960
|
+
let robotInfo = this.getAIRobotInfoByID(robotID);
|
|
30961
|
+
console.log(`[AI chat] ${robotInfo.name}已经就绪:`, event);
|
|
30962
|
+
if (this.chatAIClient) {
|
|
30963
|
+
let messages = this.getAIRobotCacheMessagesByID(robotID);
|
|
30964
|
+
if (messages && messages.length > 0) {
|
|
30965
|
+
const newMessages = [...messages];
|
|
30966
|
+
messages.splice(0, messages.length);
|
|
30967
|
+
newMessages.forEach(message => {
|
|
30968
|
+
console.log(`[AI chat] ${robotInfo.name}发送缓存消息:`, message);
|
|
30969
|
+
this.sendMessageToChatServer(robotID, message);
|
|
30970
|
+
});
|
|
30971
|
+
}
|
|
30972
|
+
}
|
|
30973
|
+
}
|
|
30974
|
+
getAIRobotInfos() {
|
|
30975
|
+
let resultRobots = [];
|
|
30976
|
+
for (let key in this.charAIs) {
|
|
30977
|
+
resultRobots.push(this.charAIs[key].robot);
|
|
30978
|
+
}
|
|
30979
|
+
return resultRobots;
|
|
30980
|
+
}
|
|
30981
|
+
getAIRobotInfoByID(robotID) {
|
|
30982
|
+
return this.charAIs[robotID] ? this.charAIs[robotID].robot : null;
|
|
30983
|
+
}
|
|
30984
|
+
getAIRobotCacheMessagesByID(robotID) {
|
|
30985
|
+
return this.charAIs[robotID] ? this.charAIs[robotID].messageCache : [];
|
|
30986
|
+
}
|
|
30987
|
+
async sendMessageToChatServer(robotID, messageOption) {
|
|
30988
|
+
let robotInfo = this.getAIRobotInfoByID(robotID);
|
|
30989
|
+
if (this.lastRobotID != robotID) {
|
|
30990
|
+
console.log(`[AI chat]需要新机器人回答,切换到新机器人${robotInfo.name}`);
|
|
30991
|
+
if (this.lastRobotID) {
|
|
30992
|
+
await this.chatAIClient.logout();
|
|
30993
|
+
}
|
|
30994
|
+
await this.chatAIClient.login({
|
|
30995
|
+
userID: robotID,
|
|
30996
|
+
userSig: robotInfo.userSig
|
|
30997
|
+
});
|
|
30998
|
+
}
|
|
30999
|
+
this.lastRobotID = robotID;
|
|
31000
|
+
if (this.chatAIClient && this.chatAIClient.isReady()) {
|
|
31001
|
+
let new_message = await this.chatAIClient.createTextMessage(messageOption);
|
|
31002
|
+
this.chatAIClient.sendMessage(new_message).then(res => {
|
|
31003
|
+
console.log(`[AI chat]${robotInfo.name}发送信息成功`, res);
|
|
31004
|
+
}, err => {
|
|
31005
|
+
console.log(`[AI chat]${robotInfo.name}发送失败`, err);
|
|
31006
|
+
});
|
|
31007
|
+
} else {
|
|
31008
|
+
console.log(`[AI chat]${robotInfo.name}未就绪,缓存消息:`, messageOption);
|
|
31009
|
+
let messageCache = this.getAIRobotCacheMessagesByID(robotID);
|
|
31010
|
+
messageCache.push(messageOption);
|
|
31011
|
+
}
|
|
31012
|
+
}
|
|
31013
|
+
converToAIServerParams(message, robotInfo, param) {
|
|
31014
|
+
let prompt = "";
|
|
31015
|
+
let type = message.type;
|
|
31016
|
+
switch (type) {
|
|
31017
|
+
case "TIMTextElem":
|
|
31018
|
+
prompt = message.payload?.text || "";
|
|
31019
|
+
break;
|
|
31020
|
+
case "TIMImageElem":
|
|
31021
|
+
break;
|
|
31022
|
+
case "TIMSoundElem":
|
|
31023
|
+
break;
|
|
31024
|
+
case "TIMVideoFileElem":
|
|
31025
|
+
break;
|
|
31026
|
+
case "TIMFileElem":
|
|
31027
|
+
break;
|
|
31028
|
+
default:
|
|
31029
|
+
break;
|
|
31030
|
+
}
|
|
31031
|
+
let cloudCustomData = message.cloudCustomData || {};
|
|
31032
|
+
let conversation_id = cloudCustomData.conversation_id || "";
|
|
31033
|
+
let params = {
|
|
31034
|
+
prompt: prompt,
|
|
31035
|
+
params: param || {},
|
|
31036
|
+
robotKey: robotInfo.password,
|
|
31037
|
+
conversation_id: conversation_id || "",
|
|
31038
|
+
userID: message.from || ""
|
|
31039
|
+
};
|
|
31040
|
+
return params;
|
|
31041
|
+
}
|
|
31042
|
+
abort() {
|
|
31043
|
+
this.chatAIClient = null;
|
|
31044
|
+
}
|
|
31045
|
+
}
|
|
31046
|
+
;// ./src/api/chat.js
|
|
31047
|
+
|
|
31048
|
+
|
|
31049
|
+
|
|
31050
|
+
const getIMHanlder = customerHanlder => {
|
|
31051
|
+
let handler = {
|
|
31052
|
+
genTestUserSig: async data => {
|
|
31053
|
+
// return genTestUserSig(data);
|
|
31054
|
+
},
|
|
31055
|
+
getChatClient: async () => {
|
|
31056
|
+
return window.imClient;
|
|
31057
|
+
},
|
|
31058
|
+
getAIRobotInfos: async (user_id, groupID) => {
|
|
31059
|
+
return getAIRobotInfos(user_id, groupID);
|
|
31060
|
+
},
|
|
31061
|
+
getPortalUserSig: async (robotKey, platType, groupID) => {
|
|
31062
|
+
return getPortalUserSig(robotKey, platType, groupID);
|
|
31063
|
+
},
|
|
31064
|
+
addIMMapping: async (robotKey, platType, userSig, groupID) => {
|
|
31065
|
+
return addIMMapping(robotKey, platType, groupID, userSig);
|
|
31066
|
+
},
|
|
31067
|
+
updateIMMapping: async data => {
|
|
31068
|
+
let robotKey = data.userID;
|
|
31069
|
+
let platType = data.im_type;
|
|
31070
|
+
let groupID = data.group_id;
|
|
31071
|
+
let userSig = data.userSig;
|
|
31072
|
+
return updateIMMapping(robotKey, platType, groupID, userSig);
|
|
31073
|
+
},
|
|
31074
|
+
getPortalAccessToken: async data => {
|
|
31075
|
+
let appKey = data.appKey;
|
|
31076
|
+
let appSecret = data.appSecret;
|
|
31077
|
+
return getPortalAccessToken(appKey, appSecret);
|
|
31078
|
+
},
|
|
31079
|
+
getPortalUserInfo: async data => {
|
|
31080
|
+
let code = data.code;
|
|
31081
|
+
let access_token = data.access_token;
|
|
31082
|
+
return getPortalUserInfo(code, access_token);
|
|
31083
|
+
},
|
|
31084
|
+
getAllUserInfosByGroupID: async data => {
|
|
31085
|
+
let groupID = data.groupID;
|
|
31086
|
+
return getAllUserInfosByGroupID(groupID);
|
|
31087
|
+
},
|
|
31088
|
+
getChildrenOfficeInfosByID: async data => {
|
|
31089
|
+
let groupID = data.groupID;
|
|
31090
|
+
return getChildrenOfficeInfosByID(groupID);
|
|
31091
|
+
},
|
|
31092
|
+
getPojectDptsByUserAndGroupID: async data => {
|
|
31093
|
+
let groupID = data.groupID;
|
|
31094
|
+
let userID = data.userID;
|
|
31095
|
+
return getPojectDptsByUserAndGroupID(userID, groupID);
|
|
31096
|
+
},
|
|
31097
|
+
closeWindow: () => {
|
|
31098
|
+
// this.visable = false;
|
|
31099
|
+
return true;
|
|
31100
|
+
},
|
|
31101
|
+
addChatListener: async (listenerKey, handler) => {
|
|
31102
|
+
await addEventAction(listenerKey, handler);
|
|
31103
|
+
},
|
|
31104
|
+
fireEventToChatWindow: async (event, chart_origin, key, params, handler) => {
|
|
31105
|
+
await sendWindowMessage(event.source, chart_origin, key, params, handler);
|
|
31106
|
+
},
|
|
31107
|
+
onChatInitFinished: async () => {
|
|
31108
|
+
// this.chatInitFinish = true;
|
|
31109
|
+
}
|
|
31110
|
+
};
|
|
31111
|
+
handler = {
|
|
31112
|
+
...handler,
|
|
31113
|
+
...customerHanlder
|
|
31114
|
+
};
|
|
31115
|
+
return handler;
|
|
31116
|
+
};
|
|
31117
|
+
|
|
30832
31118
|
;// ./src/main.js
|
|
30833
31119
|
|
|
30834
31120
|
|
|
30835
31121
|
|
|
30836
31122
|
|
|
30837
31123
|
|
|
31124
|
+
|
|
30838
31125
|
;// ./node_modules/@vue/cli-service/lib/commands/build/entry-lib-no-default.js
|
|
30839
31126
|
|
|
30840
31127
|
|