@secret-momo/notifier 1.0.8 → 1.1.0
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/lib/index.js +1 -1
- package/lib/lark/helper.d.ts +1 -1
- package/lib/lark/helper.js +2 -2
- package/lib/lark/index.d.ts +7 -7
- package/lib/lark/index.d.ts.map +1 -1
- package/lib/lark/index.js +22 -22
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { replyCardMessage, replyTextMessage, sendCardMessage, sendErrorCardMessage, sendPostMessage, sendTextMessage, startWsClient, updateCardMessage, uploadImage, webhookSendCardMessage, webhookSendTextMessage } from './lark/index.js';
|
|
2
2
|
export { e, sendMessage } from './telegram/index.js';
|
|
3
|
-
export {
|
|
3
|
+
export { getTextMessageContent } from './lark/helper.js';
|
package/lib/lark/helper.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { LarkIMMessageReceiveV1Event } from './types/receive.type';
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function getTextMessageContent(e: LarkIMMessageReceiveV1Event): string;
|
|
3
3
|
//# sourceMappingURL=helper.d.ts.map
|
package/lib/lark/helper.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
function
|
|
1
|
+
function getTextMessageContent(e) {
|
|
2
2
|
if (e.message?.message_type === "text") {
|
|
3
3
|
return JSON.parse(e.message.content ?? "{}").text ?? "";
|
|
4
4
|
}
|
|
5
5
|
return "";
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
export {
|
|
8
|
+
export { getTextMessageContent };
|
package/lib/lark/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { Post } from './types/post.type';
|
|
2
2
|
import type { InteractiveCard, InteractiveCardHeader, InteractiveCardBody, InteractiveCardElement, InteractiveCardMarkdownElement, InteractiveCardButtonElement } from './types/card.type';
|
|
3
3
|
import type { LarkIMMessageReceiveV1Event } from './types/receive.type';
|
|
4
|
-
export {
|
|
4
|
+
export { getTextMessageContent } from './helper';
|
|
5
5
|
export type { Post, InteractiveCard, InteractiveCardHeader, InteractiveCardBody, InteractiveCardElement, InteractiveCardMarkdownElement, InteractiveCardButtonElement, LarkIMMessageReceiveV1Event, };
|
|
6
6
|
/**
|
|
7
7
|
* 发送普通文本消息,文档地址:
|
|
8
8
|
* https://open.feishu.cn/document/server-docs/im-v1/message-content-description/create_json#c9e08671
|
|
9
9
|
*/
|
|
10
|
-
export declare function sendTextMessage(message: string): Promise<{
|
|
10
|
+
export declare function sendTextMessage(message: string, chatId?: string): Promise<{
|
|
11
11
|
code?: number | undefined;
|
|
12
12
|
msg?: string | undefined;
|
|
13
13
|
data?: {
|
|
@@ -44,13 +44,11 @@ export declare function sendTextMessage(message: string): Promise<{
|
|
|
44
44
|
thread_message_position?: string | undefined;
|
|
45
45
|
} | undefined;
|
|
46
46
|
}>;
|
|
47
|
-
export declare function webhookSendTextMessage(text: string): Promise<unknown>;
|
|
48
|
-
export declare function webhookSendCardMessage(card: InteractiveCard): Promise<unknown>;
|
|
49
47
|
/**
|
|
50
48
|
* 发送富文本消息,文档地址:
|
|
51
49
|
* https://open.feishu.cn/document/server-docs/im-v1/message-content-description/create_json#45e0953e
|
|
52
50
|
*/
|
|
53
|
-
export declare function sendPostMessage(post: Post): Promise<{
|
|
51
|
+
export declare function sendPostMessage(post: Post, chatId?: string): Promise<{
|
|
54
52
|
code?: number | undefined;
|
|
55
53
|
msg?: string | undefined;
|
|
56
54
|
data?: {
|
|
@@ -91,7 +89,7 @@ export declare function sendPostMessage(post: Post): Promise<{
|
|
|
91
89
|
* 发送卡片消息,文档地址:
|
|
92
90
|
* https://open.feishu.cn/document/server-docs/im-v1/message-content-description/create_json#3ea4c2d5
|
|
93
91
|
*/
|
|
94
|
-
export declare function sendCardMessage(card: InteractiveCard): Promise<{
|
|
92
|
+
export declare function sendCardMessage(card: InteractiveCard, chatId?: string): Promise<{
|
|
95
93
|
code?: number | undefined;
|
|
96
94
|
msg?: string | undefined;
|
|
97
95
|
data?: {
|
|
@@ -131,7 +129,7 @@ export declare function sendCardMessage(card: InteractiveCard): Promise<{
|
|
|
131
129
|
/**
|
|
132
130
|
* 发送通用的错误卡片消息
|
|
133
131
|
*/
|
|
134
|
-
export declare function sendErrorCardMessage(message: string): Promise<{
|
|
132
|
+
export declare function sendErrorCardMessage(message: string, chatId?: string): Promise<{
|
|
135
133
|
code?: number | undefined;
|
|
136
134
|
msg?: string | undefined;
|
|
137
135
|
data?: {
|
|
@@ -254,6 +252,8 @@ export declare function updateCardMessage(message_id: string, card: InteractiveC
|
|
|
254
252
|
msg?: string | undefined;
|
|
255
253
|
data?: {} | undefined;
|
|
256
254
|
}>;
|
|
255
|
+
export declare function webhookSendTextMessage(text: string, webhookUrl?: string): Promise<unknown>;
|
|
256
|
+
export declare function webhookSendCardMessage(card: InteractiveCard, webhookUrl?: string): Promise<unknown>;
|
|
257
257
|
export declare function uploadImage(filePath: string): Promise<string>;
|
|
258
258
|
/**
|
|
259
259
|
* 启动 WebSocket 客户端
|
package/lib/lark/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lark/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,EACtB,8BAA8B,EAC9B,4BAA4B,EAC7B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,YAAY,EACV,IAAI,EACJ,eAAe,EACf,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,EACtB,8BAA8B,EAC9B,4BAA4B,EAC5B,2B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C;uBAA6D,CAAC;;YAAyF,CAAC;;;gBAAwH,CAAC;;;;;sBAAkN,CAAC;;wBAAuG,CAAC;wBAA8D,CAAC;wBAA8D,CAAC;+BAAqE,CAAC;;GAlEhj6nb;AAED,wBAAsB,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe;;;;kBAgEq/2nb,CAAC;eAAqD,CAAC;iBAAuD,CAAC;iBAAuD,CAAC;gBAAsD,CAAC;mBAAyD,CAAC;mBAAyD,CAAC;eAAqD,CAAC;eAAsD,CAAC;eAAsD,CAAC;cAAoD,CAAC;;;;sBAAgL,CAAC;uBAA6D,CAAC;;YAAyF,CAAC;;;gBAAwH,CAAC;;;;;sBAAkN,CAAC;;wBAAuG,CAAC;wBAA8D,CAAC;wBAA8D,CAAC;+BAAqE,CAAC;;GAvDhj6nb;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe;;;;GAOhF;AAED,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,oBAK7E;AAED,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,eAAe,EAAE,UAAU,CAAC,EAAE,MAAM,oBAKtF;AAED,wBAAsB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CASnE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,2BAA2B,KAAK,IAAI,iBASnF"}
|
package/lib/lark/index.js
CHANGED
|
@@ -1,58 +1,46 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import * as lark from '@larksuiteoapi/node-sdk';
|
|
3
3
|
import { fetchJson } from '@secret-momo/utils';
|
|
4
|
-
export {
|
|
4
|
+
export { getTextMessageContent } from './helper.js';
|
|
5
5
|
|
|
6
6
|
const client = new lark.Client({
|
|
7
7
|
appId: process.env.LARK_APP_ID ?? "",
|
|
8
8
|
appSecret: process.env.LARK_APP_SECRET ?? ""
|
|
9
9
|
});
|
|
10
|
-
const
|
|
11
|
-
async function sendTextMessage(message) {
|
|
10
|
+
const defaultChatId = process.env.LARK_CHAT_ID ?? "";
|
|
11
|
+
async function sendTextMessage(message, chatId) {
|
|
12
12
|
return client.im.v1.message.create({
|
|
13
13
|
params: {
|
|
14
14
|
receive_id_type: "chat_id"
|
|
15
15
|
},
|
|
16
16
|
data: {
|
|
17
|
-
receive_id: chatId,
|
|
17
|
+
receive_id: chatId ?? defaultChatId,
|
|
18
18
|
msg_type: "text",
|
|
19
19
|
content: JSON.stringify({ text: message })
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
|
-
async function
|
|
24
|
-
return await fetchJson(process.env.LARK_WEBHOOK_URL ?? "", {
|
|
25
|
-
method: "POST",
|
|
26
|
-
body: JSON.stringify({ msg_type: "text", content: { text } })
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
async function webhookSendCardMessage(card) {
|
|
30
|
-
return await fetchJson(process.env.LARK_WEBHOOK_URL ?? "", {
|
|
31
|
-
method: "POST",
|
|
32
|
-
body: JSON.stringify({ msg_type: "interactive", card })
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
async function sendPostMessage(post) {
|
|
23
|
+
async function sendPostMessage(post, chatId) {
|
|
36
24
|
return await client.im.v1.message.create({
|
|
37
25
|
params: { receive_id_type: "chat_id" },
|
|
38
26
|
data: {
|
|
39
|
-
receive_id: chatId,
|
|
27
|
+
receive_id: chatId ?? defaultChatId,
|
|
40
28
|
msg_type: "post",
|
|
41
29
|
content: JSON.stringify(post)
|
|
42
30
|
}
|
|
43
31
|
});
|
|
44
32
|
}
|
|
45
|
-
async function sendCardMessage(card) {
|
|
33
|
+
async function sendCardMessage(card, chatId) {
|
|
46
34
|
return await client.im.v1.message.create({
|
|
47
35
|
params: { receive_id_type: "chat_id" },
|
|
48
36
|
data: {
|
|
49
|
-
receive_id: chatId,
|
|
37
|
+
receive_id: chatId ?? defaultChatId,
|
|
50
38
|
msg_type: "interactive",
|
|
51
39
|
content: JSON.stringify(card)
|
|
52
40
|
}
|
|
53
41
|
});
|
|
54
42
|
}
|
|
55
|
-
async function sendErrorCardMessage(message) {
|
|
43
|
+
async function sendErrorCardMessage(message, chatId) {
|
|
56
44
|
const card = {
|
|
57
45
|
schema: "2.0",
|
|
58
46
|
config: { update_multi: true },
|
|
@@ -94,7 +82,7 @@ async function sendErrorCardMessage(message) {
|
|
|
94
82
|
}
|
|
95
83
|
});
|
|
96
84
|
}
|
|
97
|
-
return await sendCardMessage(card);
|
|
85
|
+
return await sendCardMessage(card, chatId);
|
|
98
86
|
}
|
|
99
87
|
async function replyTextMessage(message_id, message) {
|
|
100
88
|
return await client.im.v1.message.reply({
|
|
@@ -124,6 +112,18 @@ async function updateCardMessage(message_id, card) {
|
|
|
124
112
|
}
|
|
125
113
|
});
|
|
126
114
|
}
|
|
115
|
+
async function webhookSendTextMessage(text, webhookUrl) {
|
|
116
|
+
return await fetchJson(webhookUrl ?? process.env.LARK_WEBHOOK_URL ?? "", {
|
|
117
|
+
method: "POST",
|
|
118
|
+
body: JSON.stringify({ msg_type: "text", content: { text } })
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
async function webhookSendCardMessage(card, webhookUrl) {
|
|
122
|
+
return await fetchJson(webhookUrl ?? process.env.LARK_WEBHOOK_URL ?? "", {
|
|
123
|
+
method: "POST",
|
|
124
|
+
body: JSON.stringify({ msg_type: "interactive", card })
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
127
|
async function uploadImage(filePath) {
|
|
128
128
|
const res = await client.im.v1.image.create({
|
|
129
129
|
data: {
|