@satorijs/adapter-lark 3.8.1 → 3.8.3
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.cjs +17 -6
- package/lib/message.d.ts +1 -0
- package/package.json +1 -1
- package/src/bot.ts +4 -5
- package/src/message.ts +14 -1
package/lib/index.cjs
CHANGED
|
@@ -390,10 +390,20 @@ var LarkMessageEncoder = class extends import_core3.MessageEncoder {
|
|
|
390
390
|
card;
|
|
391
391
|
noteElements;
|
|
392
392
|
actionElements = [];
|
|
393
|
+
editMessageIds;
|
|
393
394
|
async post(data) {
|
|
394
395
|
try {
|
|
395
396
|
let resp;
|
|
396
|
-
if (this.
|
|
397
|
+
if (this.editMessageIds) {
|
|
398
|
+
const messageId = this.editMessageIds.pop();
|
|
399
|
+
if (!messageId) throw new Error("No message to edit");
|
|
400
|
+
if (data.msg_type === "interactive") {
|
|
401
|
+
delete data.msg_type;
|
|
402
|
+
await this.bot.internal.patchImMessage(messageId, data);
|
|
403
|
+
} else {
|
|
404
|
+
await this.bot.internal.updateImMessage(messageId, data);
|
|
405
|
+
}
|
|
406
|
+
} else if (this.quote?.id) {
|
|
397
407
|
resp = await this.bot.internal.replyImMessage(this.quote.id, {
|
|
398
408
|
...data,
|
|
399
409
|
reply_in_thread: this.quote.replyInThread
|
|
@@ -404,6 +414,7 @@ var LarkMessageEncoder = class extends import_core3.MessageEncoder {
|
|
|
404
414
|
receive_id_type: extractIdType(this.channelId)
|
|
405
415
|
});
|
|
406
416
|
}
|
|
417
|
+
if (!resp) return;
|
|
407
418
|
const session = this.bot.session();
|
|
408
419
|
session.messageId = resp.message_id;
|
|
409
420
|
session.timestamp = Number(resp.create_time) * 1e3;
|
|
@@ -445,6 +456,7 @@ var LarkMessageEncoder = class extends import_core3.MessageEncoder {
|
|
|
445
456
|
await this.post({
|
|
446
457
|
msg_type: "interactive",
|
|
447
458
|
content: JSON.stringify({
|
|
459
|
+
header: this.card.header,
|
|
448
460
|
elements: this.card.elements
|
|
449
461
|
})
|
|
450
462
|
});
|
|
@@ -3310,7 +3322,7 @@ var LarkBot = class extends import_core5.Bot {
|
|
|
3310
3322
|
const response = await this.http("/" + params.path, {
|
|
3311
3323
|
method,
|
|
3312
3324
|
headers,
|
|
3313
|
-
data: body,
|
|
3325
|
+
data: method === "GET" || method === "HEAD" ? null : body,
|
|
3314
3326
|
params: Object.fromEntries(query.entries()),
|
|
3315
3327
|
responseType: "arraybuffer",
|
|
3316
3328
|
validateStatus: /* @__PURE__ */ __name(() => true, "validateStatus")
|
|
@@ -3352,10 +3364,9 @@ var LarkBot = class extends import_core5.Bot {
|
|
|
3352
3364
|
this.http.config.headers.Authorization = `Bearer ${v}`;
|
|
3353
3365
|
}
|
|
3354
3366
|
async editMessage(channelId, messageId, content) {
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
});
|
|
3367
|
+
const encoder = new LarkMessageEncoder(this, channelId);
|
|
3368
|
+
encoder.editMessageIds = [messageId];
|
|
3369
|
+
await encoder.send(content);
|
|
3359
3370
|
}
|
|
3360
3371
|
async deleteMessage(channelId, messageId) {
|
|
3361
3372
|
await this.internal.deleteImMessage(messageId);
|
package/lib/message.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare class LarkMessageEncoder<C extends Context = Context> extends Mes
|
|
|
7
7
|
private card;
|
|
8
8
|
private noteElements;
|
|
9
9
|
private actionElements;
|
|
10
|
+
editMessageIds: string[] | undefined;
|
|
10
11
|
post(data?: any): Promise<void>;
|
|
11
12
|
private flushText;
|
|
12
13
|
flush(): Promise<void>;
|
package/package.json
CHANGED
package/src/bot.ts
CHANGED
|
@@ -30,7 +30,7 @@ export class LarkBot<C extends Context = Context> extends Bot<C, LarkBot.Config>
|
|
|
30
30
|
const response = await this.http('/' + params.path, {
|
|
31
31
|
method,
|
|
32
32
|
headers,
|
|
33
|
-
data: body,
|
|
33
|
+
data: method === 'GET' || method === 'HEAD' ? null : body,
|
|
34
34
|
params: Object.fromEntries(query.entries()),
|
|
35
35
|
responseType: 'arraybuffer',
|
|
36
36
|
validateStatus: () => true,
|
|
@@ -88,10 +88,9 @@ export class LarkBot<C extends Context = Context> extends Bot<C, LarkBot.Config>
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
async editMessage(channelId: string, messageId: string, content: h.Fragment) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
})
|
|
91
|
+
const encoder = new LarkMessageEncoder(this, channelId)
|
|
92
|
+
encoder.editMessageIds = [messageId]
|
|
93
|
+
await encoder.send(content)
|
|
95
94
|
}
|
|
96
95
|
|
|
97
96
|
async deleteMessage(channelId: string, messageId: string) {
|
package/src/message.ts
CHANGED
|
@@ -11,10 +11,21 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco
|
|
|
11
11
|
private noteElements: MessageContent.Card.NoteElement.InnerElement[] | undefined
|
|
12
12
|
private actionElements: MessageContent.Card.Element[] = []
|
|
13
13
|
|
|
14
|
+
public editMessageIds: string[] | undefined
|
|
15
|
+
|
|
14
16
|
async post(data?: any) {
|
|
15
17
|
try {
|
|
16
18
|
let resp: Lark.Message
|
|
17
|
-
if (this.
|
|
19
|
+
if (this.editMessageIds) {
|
|
20
|
+
const messageId = this.editMessageIds.pop()
|
|
21
|
+
if (!messageId) throw new Error('No message to edit')
|
|
22
|
+
if (data.msg_type === 'interactive') {
|
|
23
|
+
delete data.msg_type
|
|
24
|
+
await this.bot.internal.patchImMessage(messageId, data)
|
|
25
|
+
} else {
|
|
26
|
+
await this.bot.internal.updateImMessage(messageId, data)
|
|
27
|
+
}
|
|
28
|
+
} else if (this.quote?.id) {
|
|
18
29
|
resp = await this.bot.internal.replyImMessage(this.quote.id, {
|
|
19
30
|
...data,
|
|
20
31
|
reply_in_thread: this.quote.replyInThread,
|
|
@@ -25,6 +36,7 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco
|
|
|
25
36
|
receive_id_type: extractIdType(this.channelId),
|
|
26
37
|
})
|
|
27
38
|
}
|
|
39
|
+
if (!resp) return
|
|
28
40
|
const session = this.bot.session()
|
|
29
41
|
session.messageId = resp.message_id
|
|
30
42
|
session.timestamp = Number(resp.create_time) * 1000
|
|
@@ -70,6 +82,7 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco
|
|
|
70
82
|
await this.post({
|
|
71
83
|
msg_type: 'interactive',
|
|
72
84
|
content: JSON.stringify({
|
|
85
|
+
header: this.card.header,
|
|
73
86
|
elements: this.card.elements,
|
|
74
87
|
}),
|
|
75
88
|
})
|