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