gm-mcp 1.0.7

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.
Files changed (48) hide show
  1. package/README.md +60 -0
  2. package/dist/env.d.ts +36 -0
  3. package/dist/env.js +49 -0
  4. package/dist/helpers/currency.d.ts +1 -0
  5. package/dist/helpers/currency.js +43 -0
  6. package/dist/helpers/extract-date.d.ts +5 -0
  7. package/dist/helpers/extract-date.js +13 -0
  8. package/dist/helpers/extract-month.d.ts +4 -0
  9. package/dist/helpers/extract-month.js +17 -0
  10. package/dist/helpers/index.d.ts +3 -0
  11. package/dist/helpers/index.js +19 -0
  12. package/dist/index.d.ts +3 -0
  13. package/dist/index.js +83 -0
  14. package/dist/services/gimo.service.d.ts +3 -0
  15. package/dist/services/gimo.service.js +48 -0
  16. package/dist/services/lark.service.d.ts +109 -0
  17. package/dist/services/lark.service.js +162 -0
  18. package/dist/services/lending.service.d.ts +19 -0
  19. package/dist/services/lending.service.js +96 -0
  20. package/dist/services/types/gimo.type.d.ts +177 -0
  21. package/dist/services/types/gimo.type.js +2 -0
  22. package/dist/services/types/index.d.ts +2 -0
  23. package/dist/services/types/index.js +18 -0
  24. package/dist/services/types/lending.type.d.ts +168 -0
  25. package/dist/services/types/lending.type.js +21 -0
  26. package/dist/test.d.ts +1 -0
  27. package/dist/test.js +39 -0
  28. package/dist/tools/index.d.ts +1 -0
  29. package/dist/tools/index.js +17 -0
  30. package/dist/tools/statistic-x3.d.ts +26 -0
  31. package/dist/tools/statistic-x3.js +337 -0
  32. package/package.json +35 -0
  33. package/src/env.ts +45 -0
  34. package/src/helpers/currency.ts +8 -0
  35. package/src/helpers/extract-date.ts +10 -0
  36. package/src/helpers/extract-month.ts +14 -0
  37. package/src/helpers/index.ts +3 -0
  38. package/src/index.ts +104 -0
  39. package/src/services/gimo.service.ts +31 -0
  40. package/src/services/lark.service.ts +122 -0
  41. package/src/services/lending.service.ts +107 -0
  42. package/src/services/types/gimo.type.ts +184 -0
  43. package/src/services/types/index.ts +2 -0
  44. package/src/services/types/lending.type.ts +181 -0
  45. package/src/test.ts +38 -0
  46. package/src/tools/index.ts +1 -0
  47. package/src/tools/statistic-x3.ts +378 -0
  48. package/tsconfig.json +115 -0
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ ## GIMO MCP
2
+
3
+ This MCP server integrates with GIMO Backend system similarly Dash site
4
+
5
+ ## Tools
6
+
7
+ - **statistic_salary_x3_today**
8
+
9
+ - **Description**: Get statistic salary x3 today
10
+
11
+ - **statistic_salary_x3_yesterday**
12
+
13
+ - **Description**: Get statistic salary x3 yesterday
14
+
15
+ - **statistic_salary_x3_this_week**
16
+
17
+ - **Description**: Get statistic salary x3 this week
18
+
19
+ - **statistic_salary_x3_month**
20
+
21
+ - **Description**: Get statistic salary x3 with specific month
22
+
23
+ - **statistic_salary_x3**
24
+
25
+ - **Description**: Get statistic salary x3 with specific date
26
+
27
+ - **statistic_salary_x3_in_range**
28
+ - **Description**: Get statistic salary x3 with range of date
29
+
30
+ ## Env variables
31
+
32
+ Provide these varibales
33
+
34
+ ```ts
35
+ DASH_URL: z.string({ description: "Dash url for login" }),
36
+ PASSWORD: z.string({ description: "User password" }),
37
+ USER_NAME: z.string({ description: "User name" }),
38
+ LENDING_URL: z.string({ description: "Lending url" }),
39
+ LARK_APP_ID: z.string({ description: `Lark's Bot app id` }),
40
+ LARK_APP_SECRET: z.string({ description: `Lark's Bot app secret` }),
41
+ LARK_X3_GROUP_ID: z.string({ description: `Id of lark's group x3` }),
42
+ LARK_X3_TEMPLATE_ID: z.string({ description: `Id of lark's card template x3` }),
43
+ SEND_MESSAGE_TO_LARK: z.boolean({ description: "Send message to lark or not", coerce: true }),
44
+ ```
45
+
46
+ ## Usage with Desktop App like Claude,Cursor
47
+
48
+ ```json
49
+ {
50
+ "mcpServers": {
51
+ "gdrive": {
52
+ "command": "npx",
53
+ "args": ["-y", "gimo-mcp"],
54
+ "env": {
55
+ // List all varibale above #Env variables
56
+ }
57
+ }
58
+ }
59
+ }
60
+ ```
package/dist/env.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ import z from "zod";
2
+ declare const envSchema: z.ZodObject<{
3
+ DASH_URL: z.ZodString;
4
+ PASSWORD: z.ZodString;
5
+ USER_NAME: z.ZodString;
6
+ LENDING_URL: z.ZodString;
7
+ LARK_APP_ID: z.ZodString;
8
+ LARK_APP_SECRET: z.ZodString;
9
+ LARK_X3_GROUP_ID: z.ZodString;
10
+ LARK_X3_TEMPLATE_ID: z.ZodString;
11
+ SEND_MESSAGE_TO_LARK: z.ZodBoolean;
12
+ }, "strip", z.ZodTypeAny, {
13
+ DASH_URL: string;
14
+ PASSWORD: string;
15
+ USER_NAME: string;
16
+ LENDING_URL: string;
17
+ LARK_APP_ID: string;
18
+ LARK_APP_SECRET: string;
19
+ LARK_X3_GROUP_ID: string;
20
+ LARK_X3_TEMPLATE_ID: string;
21
+ SEND_MESSAGE_TO_LARK: boolean;
22
+ }, {
23
+ DASH_URL: string;
24
+ PASSWORD: string;
25
+ USER_NAME: string;
26
+ LENDING_URL: string;
27
+ LARK_APP_ID: string;
28
+ LARK_APP_SECRET: string;
29
+ LARK_X3_GROUP_ID: string;
30
+ LARK_X3_TEMPLATE_ID: string;
31
+ SEND_MESSAGE_TO_LARK: boolean;
32
+ }>;
33
+ export type GimoMcpEnv = z.infer<typeof envSchema>;
34
+ export declare function ensureEnvVariables(): boolean;
35
+ export declare function getEnv(): GimoMcpEnv;
36
+ export {};
package/dist/env.js ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ensureEnvVariables = ensureEnvVariables;
7
+ exports.getEnv = getEnv;
8
+ const zod_1 = __importDefault(require("zod"));
9
+ const envSchema = zod_1.default.object({
10
+ DASH_URL: zod_1.default.string({ description: "Dash url for login" }),
11
+ PASSWORD: zod_1.default.string({ description: "User password" }),
12
+ USER_NAME: zod_1.default.string({ description: "User name" }),
13
+ LENDING_URL: zod_1.default.string({ description: "Lending url" }),
14
+ LARK_APP_ID: zod_1.default.string({ description: `Lark's Bot app id` }),
15
+ LARK_APP_SECRET: zod_1.default.string({ description: `Lark's Bot app secret` }),
16
+ LARK_X3_GROUP_ID: zod_1.default.string({ description: `Id of lark's group x3` }),
17
+ LARK_X3_TEMPLATE_ID: zod_1.default.string({ description: `Id of lark's card template x3` }),
18
+ SEND_MESSAGE_TO_LARK: zod_1.default.boolean({ description: "Send message to lark or not", coerce: true }),
19
+ });
20
+ function ensureEnvVariables() {
21
+ const { success, error } = envSchema.safeParse(process.env);
22
+ if (!success) {
23
+ console.error("There is an error with the server environment variables", error.issues);
24
+ throw new Error("ENV_VARIABLES_INVALID");
25
+ }
26
+ return true;
27
+ }
28
+ function getEnv() {
29
+ const DASH_URL = process.env["DASH_URL"];
30
+ const PASSWORD = process.env["PASSWORD"];
31
+ const USER_NAME = process.env["USER_NAME"];
32
+ const LENDING_URL = process.env["LENDING_URL"];
33
+ const LARK_APP_ID = process.env["LARK_APP_ID"];
34
+ const LARK_APP_SECRET = process.env["LARK_APP_SECRET"];
35
+ const LARK_X3_GROUP_ID = process.env["LARK_X3_GROUP_ID"];
36
+ const LARK_X3_TEMPLATE_ID = process.env["LARK_X3_TEMPLATE_ID"];
37
+ const SEND_MESSAGE_TO_LARK = Boolean(process.env["SEND_MESSAGE_TO_LARK"]);
38
+ return {
39
+ DASH_URL,
40
+ PASSWORD,
41
+ USER_NAME,
42
+ LENDING_URL,
43
+ LARK_APP_ID,
44
+ LARK_APP_SECRET,
45
+ LARK_X3_GROUP_ID,
46
+ LARK_X3_TEMPLATE_ID,
47
+ SEND_MESSAGE_TO_LARK,
48
+ };
49
+ }
@@ -0,0 +1 @@
1
+ export declare function formatCurrency(val?: any): string | null;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.formatCurrency = formatCurrency;
37
+ const currencyFormatter = __importStar(require("currency-formatter"));
38
+ function formatCurrency(val) {
39
+ if (typeof val === 'undefined' || val === null || val === '') {
40
+ return null;
41
+ }
42
+ return currencyFormatter.format(val, { code: 'VND' });
43
+ }
@@ -0,0 +1,5 @@
1
+ export declare function extractDate(date: string): {
2
+ day: number;
3
+ month: number;
4
+ year: number;
5
+ } | null;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractDate = extractDate;
4
+ function extractDate(date) {
5
+ if (date.split("-").length === 3 || date.split("/").length === 3) {
6
+ const parts = date.split("/").length === 3 ? date.split("/") : date.split("-");
7
+ const day = parseInt(parts[0], 10);
8
+ const month = parseInt(parts[1], 10) - 1; // Month is 0-indexed in JavaScript
9
+ const year = parseInt(parts[2], 10);
10
+ return { day, month, year };
11
+ }
12
+ return null;
13
+ }
@@ -0,0 +1,4 @@
1
+ export declare function extractMonth(monthStr: string): {
2
+ month: number;
3
+ year?: number;
4
+ } | null;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractMonth = extractMonth;
4
+ function extractMonth(monthStr) {
5
+ if (monthStr.split("/").length === 2) {
6
+ const [month, year] = monthStr.split("/");
7
+ return { month: parseInt(month, 10), year: parseInt(year, 10) };
8
+ }
9
+ if (monthStr.split("-").length === 2) {
10
+ const [month, year] = monthStr.split("-");
11
+ return { month: parseInt(month, 10), year: parseInt(year, 10) };
12
+ }
13
+ if (!Number.isNaN(parseInt(monthStr, 10))) {
14
+ return { month: parseInt(monthStr, 10) };
15
+ }
16
+ return null;
17
+ }
@@ -0,0 +1,3 @@
1
+ export * from './currency';
2
+ export * from './extract-date';
3
+ export * from './extract-month';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./currency"), exports);
18
+ __exportStar(require("./extract-date"), exports);
19
+ __exportStar(require("./extract-month"), exports);
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+ export declare const server: McpServer;
package/dist/index.js ADDED
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.server = void 0;
17
+ const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
18
+ const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
19
+ const tools_1 = require("./tools");
20
+ const zod_1 = __importDefault(require("zod"));
21
+ const env_1 = require("./env");
22
+ exports.server = new mcp_js_1.McpServer({
23
+ name: "mcp-server",
24
+ version: "1.0.0",
25
+ }, {
26
+ capabilities: {
27
+ tools: {},
28
+ },
29
+ });
30
+ exports.server.tool("statistic_salary_x3_today", "Get statistic salary x3 today", {}, (args) => __awaiter(void 0, void 0, void 0, function* () {
31
+ return (0, tools_1.statisticX3TodayTool)({ sendMessageToLark: (0, env_1.getEnv)().SEND_MESSAGE_TO_LARK });
32
+ }));
33
+ exports.server.tool("statistic_salary_x3_yesterday", "Get statistic salary x3 yesterday", {}, (args) => __awaiter(void 0, void 0, void 0, function* () {
34
+ return (0, tools_1.statisticX3YesterdayTool)({ sendMessageToLark: (0, env_1.getEnv)().SEND_MESSAGE_TO_LARK });
35
+ }));
36
+ exports.server.tool("statistic_salary_x3_this_week", "Get statistic salary x3 this week", {}, (args) => __awaiter(void 0, void 0, void 0, function* () {
37
+ return (0, tools_1.statisticX3WeekTool)({ sendMessageToLark: (0, env_1.getEnv)().SEND_MESSAGE_TO_LARK });
38
+ }));
39
+ exports.server.tool("statistic_salary_x3_month", `Get statistic salary x3 with month (include), month must be represented with format MM/yyyy, if year is not provided, ask user again "what is year you are mentioning ?"`, {
40
+ month: zod_1.default.string().describe("Month to statistic, month must be represented with format MM/yyyy"),
41
+ }, (args) => __awaiter(void 0, void 0, void 0, function* () {
42
+ return (0, tools_1.statisticX3MonthTool)({ sendMessageToLark: (0, env_1.getEnv)().SEND_MESSAGE_TO_LARK, month: args.month });
43
+ }));
44
+ exports.server.tool("statistic_salary_x3_this_month", `Get statistic salary x3 this month`, {}, (args) => __awaiter(void 0, void 0, void 0, function* () {
45
+ return (0, tools_1.statisticX3ThisMonthTool)({ sendMessageToLark: (0, env_1.getEnv)().SEND_MESSAGE_TO_LARK });
46
+ }));
47
+ exports.server.tool("statistic_salary_x3", "Get statistic salary x3 with specific date,date must be formated in dd/mm/yyy or dd-mm-yyyy", {
48
+ date: zod_1.default.string({
49
+ description: "Date to statistic with format dd/mm/yyy or dd-mm-yyyy",
50
+ }),
51
+ }, (args) => __awaiter(void 0, void 0, void 0, function* () {
52
+ return (0, tools_1.statisticX3Tool)({
53
+ date: args.date,
54
+ sendMessageToLark: (0, env_1.getEnv)().SEND_MESSAGE_TO_LARK,
55
+ });
56
+ }));
57
+ exports.server.tool("statistic_salary_x3_in_range", "Get statistic salary x3 with range of date,date must be formated in dd/mm/yyy or dd-mm-yyyy", {
58
+ start_date: zod_1.default.string({
59
+ description: "Start date to statistic with format dd/mm/yyy or dd-mm-yyyy",
60
+ }),
61
+ end_date: zod_1.default.string({
62
+ description: "End date to statistic with format dd/mm/yyy or dd-mm-yyyy",
63
+ }),
64
+ }, (args) => __awaiter(void 0, void 0, void 0, function* () {
65
+ return (0, tools_1.statisticX3RangeTool)({
66
+ startDateStr: args.start_date,
67
+ endDateStr: args.end_date,
68
+ sendMessageToLark: (0, env_1.getEnv)().SEND_MESSAGE_TO_LARK,
69
+ });
70
+ }));
71
+ function bootstap() {
72
+ (0, env_1.ensureEnvVariables)();
73
+ const transport = new stdio_js_1.StdioServerTransport();
74
+ exports.server
75
+ .connect(transport)
76
+ .then((res) => {
77
+ console.log("Server connected and ready!");
78
+ })
79
+ .catch((e) => {
80
+ console.log("Error when start server", e);
81
+ });
82
+ }
83
+ bootstap();
@@ -0,0 +1,3 @@
1
+ import { Gimo } from './types';
2
+ export declare function getAccessToken(): Promise<string>;
3
+ export declare function findCustomerEWAByPhonenumber(phoneNumber: string): Promise<Gimo.CustomerEWA>;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getAccessToken = getAccessToken;
16
+ exports.findCustomerEWAByPhonenumber = findCustomerEWAByPhonenumber;
17
+ const axios_1 = __importDefault(require("axios"));
18
+ const env_1 = require("../env");
19
+ function getAccessToken() {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const url = `${(0, env_1.getEnv)().DASH_URL}/api/v1/auth/admin/login`;
22
+ return axios_1.default
23
+ .post(url, {
24
+ password: (0, env_1.getEnv)().PASSWORD,
25
+ username: (0, env_1.getEnv)().USER_NAME,
26
+ })
27
+ .then((res) => res.data.access_token);
28
+ });
29
+ }
30
+ function findCustomerEWAByPhonenumber(phoneNumber) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ const customerApiUrl = `${(0, env_1.getEnv)().DASH_URL}/api/v1/admin/customers/ewa/pagination`;
33
+ const access_token = yield getAccessToken();
34
+ // Find inlist
35
+ const customers = yield axios_1.default
36
+ .get(customerApiUrl, {
37
+ params: { phone_number: phoneNumber },
38
+ headers: {
39
+ Authorization: 'Bearer ' + access_token,
40
+ },
41
+ })
42
+ .then((res) => res.data)
43
+ .then((res) => res.content);
44
+ // Select first customer
45
+ const customer = customers === null || customers === void 0 ? void 0 : customers[0];
46
+ return customer || null;
47
+ });
48
+ }
@@ -0,0 +1,109 @@
1
+ export declare function sendStatisticX3Message(data: {
2
+ date: string;
3
+ content: string;
4
+ }): Promise<{
5
+ code?: number | undefined;
6
+ msg?: string | undefined;
7
+ data?: {
8
+ message_id?: string | undefined;
9
+ root_id?: string | undefined;
10
+ parent_id?: string | undefined;
11
+ thread_id?: string | undefined;
12
+ msg_type?: string | undefined;
13
+ create_time?: string | undefined;
14
+ update_time?: string | undefined;
15
+ deleted?: boolean | undefined;
16
+ updated?: boolean | undefined;
17
+ chat_id?: string | undefined;
18
+ sender?: {
19
+ id: string;
20
+ id_type: string;
21
+ sender_type: string;
22
+ tenant_key?: string | undefined;
23
+ } | undefined;
24
+ body?: {
25
+ content: string;
26
+ } | undefined;
27
+ mentions?: {
28
+ key: string;
29
+ id: string;
30
+ id_type: string;
31
+ name: string;
32
+ tenant_key?: string | undefined;
33
+ }[] | undefined;
34
+ upper_message_id?: string | undefined;
35
+ } | undefined;
36
+ }>;
37
+ export declare function sendLarkTextMessage(p: {
38
+ message_content: {
39
+ text: string;
40
+ };
41
+ receive_id: string;
42
+ }): Promise<{
43
+ code?: number | undefined;
44
+ msg?: string | undefined;
45
+ data?: {
46
+ message_id?: string | undefined;
47
+ root_id?: string | undefined;
48
+ parent_id?: string | undefined;
49
+ thread_id?: string | undefined;
50
+ msg_type?: string | undefined;
51
+ create_time?: string | undefined;
52
+ update_time?: string | undefined;
53
+ deleted?: boolean | undefined;
54
+ updated?: boolean | undefined;
55
+ chat_id?: string | undefined;
56
+ sender?: {
57
+ id: string;
58
+ id_type: string;
59
+ sender_type: string;
60
+ tenant_key?: string | undefined;
61
+ } | undefined;
62
+ body?: {
63
+ content: string;
64
+ } | undefined;
65
+ mentions?: {
66
+ key: string;
67
+ id: string;
68
+ id_type: string;
69
+ name: string;
70
+ tenant_key?: string | undefined;
71
+ }[] | undefined;
72
+ upper_message_id?: string | undefined;
73
+ } | undefined;
74
+ }>;
75
+ export declare function sendMessageToX3Group(message_content: {
76
+ text: string;
77
+ }): Promise<{
78
+ code?: number | undefined;
79
+ msg?: string | undefined;
80
+ data?: {
81
+ message_id?: string | undefined;
82
+ root_id?: string | undefined;
83
+ parent_id?: string | undefined;
84
+ thread_id?: string | undefined;
85
+ msg_type?: string | undefined;
86
+ create_time?: string | undefined;
87
+ update_time?: string | undefined;
88
+ deleted?: boolean | undefined;
89
+ updated?: boolean | undefined;
90
+ chat_id?: string | undefined;
91
+ sender?: {
92
+ id: string;
93
+ id_type: string;
94
+ sender_type: string;
95
+ tenant_key?: string | undefined;
96
+ } | undefined;
97
+ body?: {
98
+ content: string;
99
+ } | undefined;
100
+ mentions?: {
101
+ key: string;
102
+ id: string;
103
+ id_type: string;
104
+ name: string;
105
+ tenant_key?: string | undefined;
106
+ }[] | undefined;
107
+ upper_message_id?: string | undefined;
108
+ } | undefined;
109
+ }>;
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ var __importDefault = (this && this.__importDefault) || function (mod) {
45
+ return (mod && mod.__esModule) ? mod : { "default": mod };
46
+ };
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.sendStatisticX3Message = sendStatisticX3Message;
49
+ exports.sendLarkTextMessage = sendLarkTextMessage;
50
+ exports.sendMessageToX3Group = sendMessageToX3Group;
51
+ const axios_1 = __importDefault(require("axios"));
52
+ const lark = __importStar(require("@larksuiteoapi/node-sdk"));
53
+ const env_1 = require("../env");
54
+ // const LARK_BASE_TABLE_ID = process.env['LARK_BASE_TABLE_ID'];
55
+ // const LARK_BITABLE_APP_TOKEN = process.env['LARK_BITABLE_APP_TOKEN'];
56
+ // group test_bot
57
+ // const LARK_X3_GROUP_ID = 'oc_bb4e5b8dd8ada38127c790fa368c02b9';
58
+ // Group dan choi front end
59
+ const larkClient = new lark.Client({
60
+ appId: (0, env_1.getEnv)().LARK_APP_ID,
61
+ appSecret: (0, env_1.getEnv)().LARK_APP_SECRET,
62
+ disableTokenCache: true,
63
+ });
64
+ function getAccessToken() {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ const url = "https://open.larksuite.com/open-apis/auth/v3/tenant_access_token/internal";
67
+ return axios_1.default
68
+ .post(url, {
69
+ app_id: (0, env_1.getEnv)().LARK_APP_ID,
70
+ app_secret: (0, env_1.getEnv)().LARK_APP_SECRET,
71
+ })
72
+ .then((res) => res.data.tenant_access_token);
73
+ });
74
+ }
75
+ // export async function logX3Issue(p: {
76
+ // phone: string;
77
+ // company: string;
78
+ // created_at: number;
79
+ // customer_name: string;
80
+ // ekyc_link: { text: string; link: string };
81
+ // type: "ekyc" | "cic" | "datanest" | "pending_application";
82
+ // ops_status: "pending" | "done";
83
+ // assignee: { id: string }[];
84
+ // created_by: { id: string }[];
85
+ // }) {
86
+ // return logBaseRecord(
87
+ // { tableId: LARK_BASE_TABLE_ID, appToken: LARK_BITABLE_APP_TOKEN },
88
+ // p
89
+ // );
90
+ // }
91
+ // export async function logBaseRecord(
92
+ // config: { tableId: string; appToken: string },
93
+ // record: Record<string, any>
94
+ // ) {
95
+ // // const fields = new Map<string, any>();
96
+ // // Object.entries(record).forEach(([key, value]) => fields.set(key, value))
97
+ // const access_token = await getAccessToken();
98
+ // return larkClient.bitable.appTableRecord.create(
99
+ // {
100
+ // path: {
101
+ // app_token: config.appToken,
102
+ // table_id: config.tableId,
103
+ // },
104
+ // data: {
105
+ // fields: record,
106
+ // },
107
+ // },
108
+ // lark.withTenantToken(access_token)
109
+ // );
110
+ // }
111
+ // Split later
112
+ function sendStatisticX3Message(data) {
113
+ return __awaiter(this, void 0, void 0, function* () {
114
+ const access_token = yield getAccessToken();
115
+ const { date, content } = data;
116
+ const messageContent = {
117
+ type: "template",
118
+ data: {
119
+ template_id: (0, env_1.getEnv)().LARK_X3_TEMPLATE_ID,
120
+ // template_id: 'ctp_AAdI5Sp48YUT',
121
+ template_variable: {
122
+ date,
123
+ content,
124
+ },
125
+ },
126
+ };
127
+ return larkClient.im.message.create({
128
+ params: {
129
+ receive_id_type: "chat_id",
130
+ },
131
+ data: {
132
+ receive_id: (0, env_1.getEnv)().LARK_X3_GROUP_ID,
133
+ msg_type: "interactive",
134
+ content: JSON.stringify(messageContent),
135
+ },
136
+ }, lark.withTenantToken(access_token));
137
+ });
138
+ }
139
+ function sendLarkTextMessage(p) {
140
+ return __awaiter(this, void 0, void 0, function* () {
141
+ const { message_content, receive_id } = p;
142
+ const access_token = yield getAccessToken();
143
+ return larkClient.im.message.create({
144
+ params: {
145
+ receive_id_type: "chat_id",
146
+ },
147
+ data: {
148
+ receive_id,
149
+ msg_type: "text",
150
+ content: JSON.stringify(message_content),
151
+ },
152
+ }, lark.withTenantToken(access_token));
153
+ });
154
+ }
155
+ function sendMessageToX3Group(message_content) {
156
+ return __awaiter(this, void 0, void 0, function* () {
157
+ return sendLarkTextMessage({
158
+ receive_id: (0, env_1.getEnv)().LARK_X3_GROUP_ID,
159
+ message_content,
160
+ });
161
+ });
162
+ }