gm-mcp 1.1.0 → 1.1.2
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 +5 -1
- package/dist/services/lark.service.d.ts +36 -0
- package/dist/services/lark.service.js +29 -0
- package/dist/tools/lark-tool.js +14 -2
- package/package.json +1 -1
- package/src/index.ts +5 -1
- package/src/services/lark.service.ts +31 -0
- package/src/tools/lark-tool.ts +16 -2
package/dist/index.js
CHANGED
|
@@ -74,7 +74,11 @@ exports.server.tool("debt_collection_by_month", "The company's debt collection r
|
|
|
74
74
|
company_name: zod_1.default.string({ description: "Company name to get data" }),
|
|
75
75
|
}, (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
76
76
|
const { month, company_name } = args;
|
|
77
|
-
return (0, lark_tool_1.debtCollectionRateTool)({
|
|
77
|
+
return (0, lark_tool_1.debtCollectionRateTool)({
|
|
78
|
+
sendMessageToLark: (0, env_1.getEnv)().SEND_MESSAGE_TO_LARK,
|
|
79
|
+
monthDate: month,
|
|
80
|
+
companyName: company_name,
|
|
81
|
+
});
|
|
78
82
|
}));
|
|
79
83
|
function bootstap() {
|
|
80
84
|
(0, env_1.ensureEnvVariables)();
|
|
@@ -35,6 +35,42 @@ export declare function sendStatisticX3Message(data: {
|
|
|
35
35
|
upper_message_id?: string | undefined;
|
|
36
36
|
} | undefined;
|
|
37
37
|
}>;
|
|
38
|
+
export declare function sendReportOpsGroup(data: {
|
|
39
|
+
title: string;
|
|
40
|
+
message_content: string;
|
|
41
|
+
}): Promise<{
|
|
42
|
+
code?: number | undefined;
|
|
43
|
+
msg?: string | undefined;
|
|
44
|
+
data?: {
|
|
45
|
+
message_id?: string | undefined;
|
|
46
|
+
root_id?: string | undefined;
|
|
47
|
+
parent_id?: string | undefined;
|
|
48
|
+
thread_id?: string | undefined;
|
|
49
|
+
msg_type?: string | undefined;
|
|
50
|
+
create_time?: string | undefined;
|
|
51
|
+
update_time?: string | undefined;
|
|
52
|
+
deleted?: boolean | undefined;
|
|
53
|
+
updated?: boolean | undefined;
|
|
54
|
+
chat_id?: string | undefined;
|
|
55
|
+
sender?: {
|
|
56
|
+
id: string;
|
|
57
|
+
id_type: string;
|
|
58
|
+
sender_type: string;
|
|
59
|
+
tenant_key?: string | undefined;
|
|
60
|
+
} | undefined;
|
|
61
|
+
body?: {
|
|
62
|
+
content: string;
|
|
63
|
+
} | undefined;
|
|
64
|
+
mentions?: {
|
|
65
|
+
key: string;
|
|
66
|
+
id: string;
|
|
67
|
+
id_type: string;
|
|
68
|
+
name: string;
|
|
69
|
+
tenant_key?: string | undefined;
|
|
70
|
+
}[] | undefined;
|
|
71
|
+
upper_message_id?: string | undefined;
|
|
72
|
+
} | undefined;
|
|
73
|
+
}>;
|
|
38
74
|
export declare function sendLarkTextMessage(p: {
|
|
39
75
|
message_content: {
|
|
40
76
|
text: string;
|
|
@@ -47,6 +47,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
47
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
48
|
exports.getLarkTenantAccessToken = getLarkTenantAccessToken;
|
|
49
49
|
exports.sendStatisticX3Message = sendStatisticX3Message;
|
|
50
|
+
exports.sendReportOpsGroup = sendReportOpsGroup;
|
|
50
51
|
exports.sendLarkTextMessage = sendLarkTextMessage;
|
|
51
52
|
exports.sendMessageToX3Group = sendMessageToX3Group;
|
|
52
53
|
const axios_1 = __importDefault(require("axios"));
|
|
@@ -57,6 +58,7 @@ const env_1 = require("../env");
|
|
|
57
58
|
// group test_bot
|
|
58
59
|
// const LARK_X3_GROUP_ID = 'oc_bb4e5b8dd8ada38127c790fa368c02b9';
|
|
59
60
|
// Group dan choi front end
|
|
61
|
+
const DEBT_COLLECTION_CARD_ID = "ctp_AAXr3Fr7xcjr";
|
|
60
62
|
const larkClient = new lark.Client({
|
|
61
63
|
appId: (0, env_1.getEnv)().LARK_APP_ID,
|
|
62
64
|
appSecret: (0, env_1.getEnv)().LARK_APP_SECRET,
|
|
@@ -137,6 +139,33 @@ function sendStatisticX3Message(data) {
|
|
|
137
139
|
}, lark.withTenantToken(access_token));
|
|
138
140
|
});
|
|
139
141
|
}
|
|
142
|
+
function sendReportOpsGroup(data) {
|
|
143
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
+
const access_token = yield getLarkTenantAccessToken();
|
|
145
|
+
const { title, message_content } = data;
|
|
146
|
+
const messageContent = {
|
|
147
|
+
type: "template",
|
|
148
|
+
data: {
|
|
149
|
+
template_id: DEBT_COLLECTION_CARD_ID,
|
|
150
|
+
// template_id: 'ctp_AAdI5Sp48YUT',
|
|
151
|
+
template_variable: {
|
|
152
|
+
title,
|
|
153
|
+
message_content,
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
return larkClient.im.message.create({
|
|
158
|
+
params: {
|
|
159
|
+
receive_id_type: "chat_id",
|
|
160
|
+
},
|
|
161
|
+
data: {
|
|
162
|
+
receive_id: (0, env_1.getEnv)().LARK_X3_GROUP_ID,
|
|
163
|
+
msg_type: "interactive",
|
|
164
|
+
content: JSON.stringify(messageContent),
|
|
165
|
+
},
|
|
166
|
+
}, lark.withTenantToken(access_token));
|
|
167
|
+
});
|
|
168
|
+
}
|
|
140
169
|
function sendLarkTextMessage(p) {
|
|
141
170
|
return __awaiter(this, void 0, void 0, function* () {
|
|
142
171
|
const { message_content, receive_id } = p;
|
package/dist/tools/lark-tool.js
CHANGED
|
@@ -14,6 +14,10 @@ const helpers_1 = require("../helpers");
|
|
|
14
14
|
const search_like_1 = require("../helpers/search-like");
|
|
15
15
|
const report_columns_1 = require("../services/constants/report-columns");
|
|
16
16
|
const lark_base_service_1 = require("../services/lark-base.service");
|
|
17
|
+
const lark_service_1 = require("../services/lark.service");
|
|
18
|
+
const companyKey = "CÔNG TY";
|
|
19
|
+
const preiodKey = "KỲ LƯƠNG";
|
|
20
|
+
const debtCollectionRateKey = "TỈ LỆ THU NỢ";
|
|
17
21
|
function debtCollectionRateTool(options) {
|
|
18
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
23
|
const { sendMessageToLark, companyName, monthDate } = options;
|
|
@@ -38,10 +42,18 @@ function debtCollectionRateTool(options) {
|
|
|
38
42
|
const foundMonth = (0, search_like_1.searchLike)(month.toString(), companiesMatchName.map((item) => item.fields["KỲ LƯƠNG"]))[0];
|
|
39
43
|
console.log(foundMonth);
|
|
40
44
|
const finalCompnay = companiesMatchName.find((item) => item.fields["KỲ LƯƠNG"] === foundMonth);
|
|
41
|
-
return { content: [{ type: "text", text: JSON.stringify(finalCompnay) }] };
|
|
42
|
-
console.log(finalCompnay);
|
|
43
45
|
if (sendMessageToLark) {
|
|
46
|
+
yield (0, lark_service_1.sendReportOpsGroup)({
|
|
47
|
+
title: "Tỉ lệ thu nợ",
|
|
48
|
+
message_content: [
|
|
49
|
+
`Công ty: ${(finalCompnay === null || finalCompnay === void 0 ? void 0 : finalCompnay.fields[companyKey]) || "N/A"}`,
|
|
50
|
+
`Kỳ lương: ${(finalCompnay === null || finalCompnay === void 0 ? void 0 : finalCompnay.fields[preiodKey]) || "N/A"}`,
|
|
51
|
+
`Tỷ lệ thu nợ: ${Number(finalCompnay === null || finalCompnay === void 0 ? void 0 : finalCompnay.fields[debtCollectionRateKey]) * 100}%`,
|
|
52
|
+
].join("<hr>"),
|
|
53
|
+
});
|
|
44
54
|
}
|
|
55
|
+
return { content: [{ type: "text", text: JSON.stringify(finalCompnay) }] };
|
|
56
|
+
// console.log(finalCompnay);
|
|
45
57
|
}
|
|
46
58
|
catch (e) {
|
|
47
59
|
return { content: [{ type: "text", text: JSON.stringify(e) }] };
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -98,7 +98,11 @@ server.tool(
|
|
|
98
98
|
},
|
|
99
99
|
async (args) => {
|
|
100
100
|
const { month, company_name } = args;
|
|
101
|
-
return debtCollectionRateTool({
|
|
101
|
+
return debtCollectionRateTool({
|
|
102
|
+
sendMessageToLark: getEnv().SEND_MESSAGE_TO_LARK,
|
|
103
|
+
monthDate: month,
|
|
104
|
+
companyName: company_name,
|
|
105
|
+
});
|
|
102
106
|
}
|
|
103
107
|
);
|
|
104
108
|
|
|
@@ -7,6 +7,8 @@ import { getEnv } from "../env";
|
|
|
7
7
|
// const LARK_X3_GROUP_ID = 'oc_bb4e5b8dd8ada38127c790fa368c02b9';
|
|
8
8
|
// Group dan choi front end
|
|
9
9
|
|
|
10
|
+
const DEBT_COLLECTION_CARD_ID = "ctp_AAXr3Fr7xcjr";
|
|
11
|
+
|
|
10
12
|
const larkClient = new lark.Client({
|
|
11
13
|
appId: getEnv().LARK_APP_ID,
|
|
12
14
|
appSecret: getEnv().LARK_APP_SECRET,
|
|
@@ -96,6 +98,35 @@ export async function sendStatisticX3Message(data: { date: string; content: stri
|
|
|
96
98
|
);
|
|
97
99
|
}
|
|
98
100
|
|
|
101
|
+
export async function sendReportOpsGroup(data: { title: string; message_content: string }) {
|
|
102
|
+
const access_token = await getLarkTenantAccessToken();
|
|
103
|
+
const { title, message_content } = data;
|
|
104
|
+
const messageContent = {
|
|
105
|
+
type: "template",
|
|
106
|
+
data: {
|
|
107
|
+
template_id: DEBT_COLLECTION_CARD_ID,
|
|
108
|
+
// template_id: 'ctp_AAdI5Sp48YUT',
|
|
109
|
+
template_variable: {
|
|
110
|
+
title,
|
|
111
|
+
message_content,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
return larkClient.im.message.create(
|
|
116
|
+
{
|
|
117
|
+
params: {
|
|
118
|
+
receive_id_type: "chat_id",
|
|
119
|
+
},
|
|
120
|
+
data: {
|
|
121
|
+
receive_id: getEnv().LARK_X3_GROUP_ID,
|
|
122
|
+
msg_type: "interactive",
|
|
123
|
+
content: JSON.stringify(messageContent),
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
lark.withTenantToken(access_token)
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
99
130
|
export async function sendLarkTextMessage(p: { message_content: { text: string }; receive_id: string }) {
|
|
100
131
|
const { message_content, receive_id } = p;
|
|
101
132
|
const access_token = await getLarkTenantAccessToken();
|
package/src/tools/lark-tool.ts
CHANGED
|
@@ -3,6 +3,11 @@ import { extractMonth } from "../helpers";
|
|
|
3
3
|
import { searchLike } from "../helpers/search-like";
|
|
4
4
|
import { REPORT_COLUMS } from "../services/constants/report-columns";
|
|
5
5
|
import { fetchReportRecords } from "../services/lark-base.service";
|
|
6
|
+
import { sendReportOpsGroup } from "../services/lark.service";
|
|
7
|
+
|
|
8
|
+
const companyKey = "CÔNG TY";
|
|
9
|
+
const preiodKey = "KỲ LƯƠNG";
|
|
10
|
+
const debtCollectionRateKey = "TỈ LỆ THU NỢ";
|
|
6
11
|
|
|
7
12
|
export async function debtCollectionRateTool(options: {
|
|
8
13
|
sendMessageToLark: boolean;
|
|
@@ -36,10 +41,19 @@ export async function debtCollectionRateTool(options: {
|
|
|
36
41
|
)[0];
|
|
37
42
|
console.log(foundMonth);
|
|
38
43
|
const finalCompnay = companiesMatchName.find((item) => item.fields["KỲ LƯƠNG"] === foundMonth);
|
|
39
|
-
|
|
40
|
-
console.log(finalCompnay);
|
|
44
|
+
|
|
41
45
|
if (sendMessageToLark) {
|
|
46
|
+
await sendReportOpsGroup({
|
|
47
|
+
title: "Tỉ lệ thu nợ",
|
|
48
|
+
message_content: [
|
|
49
|
+
`Công ty: ${finalCompnay?.fields[companyKey] || "N/A"}`,
|
|
50
|
+
`Kỳ lương: ${finalCompnay?.fields[preiodKey] || "N/A"}`,
|
|
51
|
+
`Tỷ lệ thu nợ: ${Number(finalCompnay?.fields[debtCollectionRateKey]) * 100}%`,
|
|
52
|
+
].join("<hr>"),
|
|
53
|
+
});
|
|
42
54
|
}
|
|
55
|
+
return { content: [{ type: "text", text: JSON.stringify(finalCompnay) }] };
|
|
56
|
+
// console.log(finalCompnay);
|
|
43
57
|
} catch (e) {
|
|
44
58
|
return { content: [{ type: "text", text: JSON.stringify(e) }] };
|
|
45
59
|
}
|