@satorijs/adapter-lark 3.4.0 → 3.5.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 DELETED
@@ -1,755 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- Feishu: () => types_exports,
34
- FeishuBot: () => LarkBot,
35
- Lark: () => types_exports,
36
- LarkBot: () => LarkBot,
37
- default: () => src_default
38
- });
39
- module.exports = __toCommonJS(src_exports);
40
-
41
- // src/bot.ts
42
- var import_satori5 = require("@satorijs/satori");
43
-
44
- // src/http.ts
45
- var import_satori2 = require("@satorijs/satori");
46
-
47
- // src/utils.ts
48
- var import_crypto = __toESM(require("crypto"));
49
- var import_satori = require("@satorijs/satori");
50
- function adaptSender(sender, session) {
51
- let userId;
52
- if ("sender_id" in sender) {
53
- userId = sender.sender_id.open_id;
54
- } else {
55
- userId = sender.id;
56
- }
57
- session.userId = userId;
58
- return session;
59
- }
60
- __name(adaptSender, "adaptSender");
61
- function adaptMessage(bot, data, session) {
62
- const json = JSON.parse(data.message.content);
63
- const assetEndpoint = (0, import_satori.trimSlash)(bot.config.selfUrl ?? bot.ctx.server.config.selfUrl) + bot.config.path + "/assets";
64
- const content = [];
65
- switch (data.message.message_type) {
66
- case "text": {
67
- const text = json.text;
68
- if (!data.message.mentions?.length) {
69
- content.push(text);
70
- break;
71
- }
72
- text.split(" ").forEach((word) => {
73
- if (word.startsWith("@")) {
74
- const mention = data.message.mentions.find((mention2) => mention2.key === word);
75
- content.push(import_satori.h.at(mention.id.open_id, { name: mention.name }));
76
- } else {
77
- content.push(word);
78
- }
79
- });
80
- break;
81
- }
82
- case "image":
83
- content.push(import_satori.h.image(`${assetEndpoint}/image/${data.message.message_id}/${json.image_key}?self_id=${bot.selfId}`));
84
- break;
85
- case "audio":
86
- content.push(import_satori.h.audio(`${assetEndpoint}/file/${data.message.message_id}/${json.file_key}?self_id=${bot.selfId}`));
87
- break;
88
- case "media":
89
- content.push(import_satori.h.video(`${assetEndpoint}/file/${data.message.message_id}/${json.file_key}?self_id=${bot.selfId}`, json.image_key));
90
- break;
91
- case "file":
92
- content.push(import_satori.h.file(`${assetEndpoint}/file/${data.message.message_id}/${json.file_key}?self_id=${bot.selfId}`));
93
- break;
94
- }
95
- session.timestamp = +data.message.create_time;
96
- session.messageId = data.message.message_id;
97
- session.channelId = data.message.chat_id;
98
- session.content = content.map((c) => c.toString()).join(" ");
99
- return session;
100
- }
101
- __name(adaptMessage, "adaptMessage");
102
- function adaptSession(bot, body) {
103
- const session = bot.session();
104
- session.setInternal("lark", body);
105
- switch (body.type) {
106
- case "im.message.receive_v1":
107
- session.type = "message";
108
- session.subtype = body.event.message.chat_type;
109
- if (session.subtype === "p2p")
110
- session.subtype = "private";
111
- session.isDirect = session.subtype === "private";
112
- adaptSender(body.event.sender, session);
113
- adaptMessage(bot, body.event, session);
114
- break;
115
- }
116
- return session;
117
- }
118
- __name(adaptSession, "adaptSession");
119
- async function decodeMessage(bot, body) {
120
- const json = JSON.parse(body.body.content);
121
- const assetEndpoint = (0, import_satori.trimSlash)(bot.config.selfUrl ?? bot.ctx.server.config.selfUrl) + bot.config.path + "/assets";
122
- const content = [];
123
- switch (body.msg_type) {
124
- case "text": {
125
- const text = json.text;
126
- if (!body.mentions?.length) {
127
- content.push(import_satori.h.text(text));
128
- break;
129
- }
130
- text.split(" ").forEach((word) => {
131
- if (word.startsWith("@")) {
132
- const mention = body.mentions.find((mention2) => mention2.key === word);
133
- content.push(import_satori.h.at(mention.id, { name: mention.name }));
134
- } else {
135
- content.push(import_satori.h.text(word));
136
- }
137
- });
138
- break;
139
- }
140
- case "image":
141
- content.push(import_satori.h.image(`${assetEndpoint}/image/${body.message_id}/${json.image_key}?self_id=${bot.selfId}`));
142
- break;
143
- case "audio":
144
- content.push(import_satori.h.audio(`${assetEndpoint}/file/${body.message_id}/${json.file_key}?self_id=${bot.selfId}`));
145
- break;
146
- case "media":
147
- content.push(import_satori.h.video(`${assetEndpoint}/file/${body.message_id}/${json.file_key}?self_id=${bot.selfId}`, json.image_key));
148
- break;
149
- case "file":
150
- content.push(import_satori.h.file(`${assetEndpoint}/file/${body.message_id}/${json.file_key}?self_id=${bot.selfId}`));
151
- break;
152
- }
153
- return {
154
- timestamp: +body.update_time,
155
- createdAt: +body.create_time,
156
- updatedAt: +body.update_time,
157
- id: body.message_id,
158
- content: content.map((c) => c.toString()).join(" "),
159
- elements: content,
160
- quote: body.upper_message_id ? await bot.getMessage(body.chat_id, body.upper_message_id) : void 0
161
- };
162
- }
163
- __name(decodeMessage, "decodeMessage");
164
- function extractIdType(id) {
165
- if (id.startsWith("ou"))
166
- return "open_id";
167
- if (id.startsWith("on"))
168
- return "union_id";
169
- if (id.startsWith("oc"))
170
- return "chat_id";
171
- if (id.includes("@"))
172
- return "email";
173
- return "user_id";
174
- }
175
- __name(extractIdType, "extractIdType");
176
- function decodeChannel(guild) {
177
- return {
178
- id: guild.chat_id,
179
- type: import_satori.Universal.Channel.Type.TEXT,
180
- name: guild.name,
181
- parentId: guild.chat_id
182
- };
183
- }
184
- __name(decodeChannel, "decodeChannel");
185
- function decodeGuild(guild) {
186
- return {
187
- id: guild.chat_id,
188
- name: guild.name,
189
- avatar: guild.avatar
190
- };
191
- }
192
- __name(decodeGuild, "decodeGuild");
193
- function decodeUser(user) {
194
- return {
195
- id: user.open_id,
196
- avatar: user.avatar?.avatar_origin,
197
- isBot: false,
198
- name: user.name
199
- };
200
- }
201
- __name(decodeUser, "decodeUser");
202
- var Cipher = class {
203
- static {
204
- __name(this, "Cipher");
205
- }
206
- encryptKey;
207
- key;
208
- constructor(key) {
209
- this.encryptKey = key;
210
- const hash = import_crypto.default.createHash("sha256");
211
- hash.update(key);
212
- this.key = hash.digest();
213
- }
214
- decrypt(encrypt) {
215
- const encryptBuffer = Buffer.from(encrypt, "base64");
216
- const decipher = import_crypto.default.createDecipheriv("aes-256-cbc", this.key, encryptBuffer.slice(0, 16));
217
- let decrypted = decipher.update(encryptBuffer.slice(16).toString("hex"), "hex", "utf8");
218
- decrypted += decipher.final("utf8");
219
- return decrypted;
220
- }
221
- calculateSignature(timestamp, nonce, body) {
222
- const content = timestamp + nonce + this.encryptKey + body;
223
- const sign = import_crypto.default.createHash("sha256").update(content).digest("hex");
224
- return sign;
225
- }
226
- };
227
-
228
- // src/http.ts
229
- var HttpServer = class extends import_satori2.Adapter {
230
- static {
231
- __name(this, "HttpServer");
232
- }
233
- static inject = ["server"];
234
- logger;
235
- ciphers = {};
236
- constructor(ctx, bot) {
237
- super(ctx);
238
- this.logger = ctx.logger("lark");
239
- }
240
- fork(ctx, bot) {
241
- super.fork(ctx, bot);
242
- this._refreshCipher();
243
- return bot.initialize();
244
- }
245
- async connect(bot) {
246
- const { path } = bot.config;
247
- bot.ctx.server.post(path, (ctx) => {
248
- this._refreshCipher();
249
- const signature = ctx.get("X-Lark-Signature");
250
- const enabledSignatureVerify = this.bots.filter((bot2) => bot2.config.verifySignature);
251
- if (signature && enabledSignatureVerify.length) {
252
- const result = enabledSignatureVerify.some((bot2) => {
253
- const timestamp = ctx.get("X-Lark-Request-Timestamp");
254
- const nonce = ctx.get("X-Lark-Request-Nonce");
255
- const body2 = ctx.request.rawBody;
256
- const actualSignature = this.ciphers[bot2.config.appId]?.calculateSignature(timestamp, nonce, body2);
257
- if (actualSignature === signature)
258
- return true;
259
- else
260
- return false;
261
- });
262
- if (!result)
263
- return ctx.status = 403;
264
- }
265
- const body = this._tryDecryptBody(ctx.request.body);
266
- if (body?.type === "url_verification" && body?.challenge && typeof body.challenge === "string") {
267
- ctx.response.body = { challenge: body.challenge };
268
- return;
269
- }
270
- const enabledVerifyTokenVerify = this.bots.filter((bot2) => bot2.config.verifyToken && bot2.config.verificationToken);
271
- if (enabledVerifyTokenVerify.length) {
272
- const token = ctx.request.body?.token;
273
- if (token) {
274
- const result = enabledVerifyTokenVerify.some((bot2) => {
275
- if (token === bot2.config.verificationToken)
276
- return true;
277
- else
278
- return false;
279
- });
280
- if (!result)
281
- return ctx.status = 403;
282
- }
283
- }
284
- bot.logger.debug("received decryped event: %o", body);
285
- this.dispatchSession(body);
286
- return ctx.status = 200;
287
- });
288
- bot.ctx.server.get(path + "/assets/:type/:message_id/:key", async (ctx) => {
289
- const type = ctx.params.type === "image" ? "image" : "file";
290
- const key = ctx.params.key;
291
- const messageId = ctx.params.message_id;
292
- const selfId = ctx.request.query.self_id;
293
- const bot2 = this.bots.find((bot3) => bot3.selfId === selfId);
294
- if (!bot2)
295
- return ctx.status = 404;
296
- const resp = await bot2.http(`/im/v1/messages/${messageId}/resources/${key}`, {
297
- method: "GET",
298
- params: { type },
299
- responseType: "stream"
300
- });
301
- ctx.status = 200;
302
- ctx.response.headers["Content-Type"] = resp.headers.get("content-type");
303
- ctx.response.body = resp.data;
304
- });
305
- }
306
- dispatchSession(body) {
307
- const { header } = body;
308
- if (!header)
309
- return;
310
- const { app_id, event_type } = header;
311
- body.type = event_type;
312
- const bot = this.bots.find((bot2) => bot2.selfId === app_id);
313
- const session = adaptSession(bot, body);
314
- bot.dispatch(session);
315
- }
316
- _tryDecryptBody(body) {
317
- this._refreshCipher();
318
- const ciphers = Object.values(this.ciphers);
319
- if (ciphers.length && typeof body.encrypt === "string") {
320
- for (const cipher of ciphers) {
321
- try {
322
- return JSON.parse(cipher.decrypt(body.encrypt));
323
- } catch {
324
- }
325
- }
326
- this.logger.warn("failed to decrypt message: %o", body);
327
- }
328
- if (typeof body.encrypt === "string" && !ciphers.length) {
329
- this.logger.warn("encryptKey is not set, but received encrypted message: %o", body);
330
- }
331
- return body;
332
- }
333
- _refreshCipher() {
334
- const ciphers = Object.keys(this.ciphers);
335
- const bots = this.bots.map((bot) => bot.config.appId);
336
- if (bots.length === ciphers.length && bots.every((bot) => ciphers.includes(bot)))
337
- return;
338
- this.ciphers = {};
339
- for (const bot of this.bots) {
340
- this.ciphers[bot.config.appId] = new Cipher(bot.config.encryptKey);
341
- }
342
- }
343
- };
344
- ((HttpServer2) => {
345
- HttpServer2.createConfig = /* @__PURE__ */ __name((path) => import_satori2.Schema.object({
346
- path: import_satori2.Schema.string().role("url").description("要连接的服务器地址。").default(path),
347
- selfUrl: import_satori2.Schema.string().role("link").description("服务器暴露在公网的地址。缺省时将使用全局配置。"),
348
- verifyToken: import_satori2.Schema.boolean().description("是否验证令牌。"),
349
- verifySignature: import_satori2.Schema.boolean().description("是否验证签名。")
350
- }).description("服务端设置"), "createConfig");
351
- })(HttpServer || (HttpServer = {}));
352
-
353
- // src/message.ts
354
- var import_satori3 = require("@satorijs/satori");
355
- var LarkMessageEncoder = class extends import_satori3.MessageEncoder {
356
- static {
357
- __name(this, "LarkMessageEncoder");
358
- }
359
- quote;
360
- content = "";
361
- addition;
362
- // TODO: currently not used, would be supported in the future
363
- richText;
364
- async post(data) {
365
- try {
366
- let resp;
367
- if (this.quote) {
368
- resp = await this.bot.internal?.replyMessage(this.quote, data);
369
- } else {
370
- data.receive_id = this.channelId;
371
- resp = await this.bot.internal?.sendMessage(extractIdType(this.channelId), data);
372
- }
373
- const session = this.bot.session();
374
- session.messageId = resp.data.message_id;
375
- session.timestamp = Number(resp.data.create_time) * 1e3;
376
- session.userId = resp.data.sender.id;
377
- session.app.emit(session, "send", session);
378
- this.results.push(session.event.message);
379
- } catch (e) {
380
- if (import_satori3.Quester.Error.is(e)) {
381
- if (e.response?.data?.code) {
382
- const generalErrorMsg = `Check error code at https://open.larksuite.com/document/server-docs/getting-started/server-error-codes`;
383
- e.message += ` (Lark error code ${e.response.data.code}: ${e.response.data.msg ?? generalErrorMsg})`;
384
- }
385
- }
386
- this.errors.push(e);
387
- }
388
- }
389
- async flush() {
390
- if (this.content === "" && !this.addition && !this.richText)
391
- return;
392
- let message;
393
- if (this.addition) {
394
- message = {
395
- ...message,
396
- ...this.addition.file
397
- };
398
- }
399
- if (this.richText) {
400
- message = { zh_cn: this.richText };
401
- }
402
- if (this.content) {
403
- message = { text: this.content };
404
- }
405
- await this.post({
406
- msg_type: this.richText ? "post" : this.addition ? this.addition.type : "text",
407
- content: JSON.stringify(message)
408
- });
409
- this.quote = void 0;
410
- this.content = "";
411
- this.addition = void 0;
412
- this.richText = void 0;
413
- }
414
- async sendFile(type, url) {
415
- const payload = new FormData();
416
- const assetKey = type === "img" || type === "image" ? "image" : "file";
417
- const { filename, mime, data } = await this.bot.assetsQuester.file(url);
418
- payload.append(assetKey, new Blob([data], { type: mime }), filename);
419
- if (type === "img" || type === "image") {
420
- payload.append("image_type", "message");
421
- const { data: data2 } = await this.bot.internal.uploadImage(payload);
422
- return {
423
- type: "image",
424
- file: {
425
- image_key: data2.image_key
426
- }
427
- };
428
- } else {
429
- let msgType = "file";
430
- if (type === "audio") {
431
- payload.append("file_type", "opus");
432
- msgType = "audio";
433
- } else if (type === "video") {
434
- payload.append("file_type", "mp4");
435
- msgType = "media";
436
- } else {
437
- const ext = filename.split(".").pop();
438
- if (["xls", "ppt", "pdf"].includes(ext)) {
439
- payload.append("file_type", ext);
440
- } else {
441
- payload.append("file_type", "stream");
442
- }
443
- }
444
- payload.append("file_name", filename);
445
- const { data: data2 } = await this.bot.internal.uploadFile(payload);
446
- return {
447
- type: msgType,
448
- file: {
449
- file_key: data2.file_key
450
- }
451
- };
452
- }
453
- }
454
- async visit(element) {
455
- const { type, attrs, children } = element;
456
- switch (type) {
457
- case "text":
458
- this.content += attrs.content;
459
- break;
460
- case "at": {
461
- if (attrs.type === "all") {
462
- this.content += `<at user_id="all">${attrs.name ?? "所有人"}</at>`;
463
- } else {
464
- this.content += `<at user_id="${attrs.id}">${attrs.name}</at>`;
465
- }
466
- break;
467
- }
468
- case "a":
469
- await this.render(children);
470
- if (attrs.href)
471
- this.content += ` (${attrs.href})`;
472
- break;
473
- case "p":
474
- if (!this.content.endsWith("\n"))
475
- this.content += "\n";
476
- await this.render(children);
477
- if (!this.content.endsWith("\n"))
478
- this.content += "\n";
479
- break;
480
- case "br":
481
- this.content += "\n";
482
- break;
483
- case "sharp":
484
- break;
485
- case "quote":
486
- await this.flush();
487
- this.quote = attrs.id;
488
- break;
489
- case "img":
490
- case "image":
491
- case "video":
492
- case "audio":
493
- case "file":
494
- if (attrs.src || attrs.url) {
495
- await this.flush();
496
- this.addition = await this.sendFile(type, attrs.src || attrs.url);
497
- }
498
- break;
499
- case "figure":
500
- case "message":
501
- await this.flush();
502
- await this.render(children, true);
503
- break;
504
- default:
505
- await this.render(children);
506
- }
507
- }
508
- };
509
-
510
- // src/types/index.ts
511
- var types_exports = {};
512
- __export(types_exports, {
513
- Internal: () => Internal
514
- });
515
-
516
- // src/types/internal.ts
517
- var import_satori4 = require("@satorijs/satori");
518
- var Internal = class _Internal {
519
- constructor(bot) {
520
- this.bot = bot;
521
- }
522
- static {
523
- __name(this, "Internal");
524
- }
525
- processReponse(response) {
526
- const { code, msg } = response;
527
- if (code === 0) {
528
- return response;
529
- } else {
530
- this.bot.logger.debug("response: %o", response);
531
- throw new Error(`HTTP response with non-zero status (${code}) with message "${msg}"`);
532
- }
533
- }
534
- static define(routes) {
535
- for (const path in routes) {
536
- for (const key in routes[path]) {
537
- const method = key;
538
- for (const name of (0, import_satori4.makeArray)(routes[path][method])) {
539
- _Internal.prototype[name] = async function(...args) {
540
- const raw = args.join(", ");
541
- const url = path.replace(/\{([^}]+)\}/g, () => {
542
- if (!args.length)
543
- throw new Error(`too few arguments for ${path}, received ${raw}`);
544
- return args.shift();
545
- });
546
- const config = {};
547
- if (args.length === 1) {
548
- if (method === "GET" || method === "DELETE") {
549
- config.params = args[0];
550
- } else {
551
- config.data = args[0];
552
- }
553
- } else if (args.length === 2 && method !== "GET" && method !== "DELETE") {
554
- config.data = args[0];
555
- config.params = args[1];
556
- } else if (args.length > 1) {
557
- throw new Error(`too many arguments for ${path}, received ${raw}`);
558
- }
559
- return this.processReponse((await this.bot.http(method, url, config)).data);
560
- };
561
- }
562
- }
563
- }
564
- }
565
- };
566
-
567
- // src/types/auth.ts
568
- Internal.define({
569
- "/auth/v3/app_access_token/internal": {
570
- POST: "getAppAccessToken"
571
- },
572
- "/auth/v3/tenant_access_token/internal": {
573
- POST: "getTenantAccessToken"
574
- }
575
- });
576
-
577
- // src/types/guild.ts
578
- Internal.define({
579
- "/im/v1/chats": {
580
- GET: "getCurrentUserGuilds"
581
- },
582
- "/im/v1/chats/{chat_id}": {
583
- GET: "getGuildInfo"
584
- },
585
- "/im/v1/chats/{chat_id}/members": {
586
- GET: "getGuildMembers"
587
- }
588
- });
589
-
590
- // src/types/message/asset.ts
591
- Internal.define({
592
- "/im/v1/images": {
593
- POST: "uploadImage"
594
- },
595
- "/im/v1/files": {
596
- POST: "uploadFile"
597
- }
598
- });
599
-
600
- // src/types/message/index.ts
601
- Internal.define({
602
- "/im/v1/messages": {
603
- GET: "getMessageList"
604
- },
605
- "/im/v1/messages?receive_id_type={receive_id_type}": {
606
- POST: "sendMessage"
607
- },
608
- "/im/v1/messages/{message_id}/reply": {
609
- POST: "replyMessage"
610
- },
611
- "/im/v1/messages/{message_id}": {
612
- GET: "getMessage",
613
- PUT: "updateMessage",
614
- DELETE: "deleteMessage"
615
- },
616
- "/im/v1/messages/{message_id}/read_users": {
617
- GET: "getMessageReadUsers"
618
- },
619
- "/im/v1/messages/{message_id}/forward?receive_id_type={receive_id_type}": {
620
- POST: "forwardMessage"
621
- },
622
- "/im/v1/messages/merge_forward?receive_id_type={receive_id_type}": {
623
- POST: "mergeForwardMessage"
624
- }
625
- });
626
-
627
- // src/bot.ts
628
- var LarkBot = class extends import_satori5.Bot {
629
- static {
630
- __name(this, "LarkBot");
631
- }
632
- static inject = ["server", "http"];
633
- static MessageEncoder = LarkMessageEncoder;
634
- _token;
635
- _refresher;
636
- http;
637
- assetsQuester;
638
- internal;
639
- constructor(ctx, config) {
640
- super(ctx, config, "lark");
641
- if (!config.selfUrl && !ctx.server.config.selfUrl) {
642
- this.logger.warn("selfUrl is not set, some features may not work");
643
- }
644
- this.selfId = config.appId;
645
- this.http = ctx.http.extend({
646
- endpoint: config.endpoint
647
- });
648
- this.assetsQuester = ctx.http;
649
- this.internal = new Internal(this);
650
- ctx.plugin(HttpServer, this);
651
- }
652
- async initialize() {
653
- await this.refreshToken();
654
- this.online();
655
- }
656
- async refreshToken() {
657
- const { tenant_access_token: token } = await this.internal.getTenantAccessToken({
658
- app_id: this.config.appId,
659
- app_secret: this.config.appSecret
660
- });
661
- this.logger.debug("refreshed token %s", token);
662
- this.token = token;
663
- if (this._refresher)
664
- clearTimeout(this._refresher);
665
- this._refresher = setTimeout(() => this.refreshToken(), 3600 * 1e3);
666
- this.online();
667
- }
668
- get token() {
669
- return this._token;
670
- }
671
- set token(v) {
672
- this._token = v;
673
- this.http.config.headers.Authorization = `Bearer ${v}`;
674
- }
675
- async editMessage(channelId, messageId, content) {
676
- await this.internal.updateMessage(messageId, {
677
- content: import_satori5.h.normalize(content).join(""),
678
- msg_type: "text"
679
- });
680
- }
681
- async deleteMessage(channelId, messageId) {
682
- await this.internal.deleteMessage(messageId);
683
- }
684
- async getMessage(channelId, messageId) {
685
- const data = await this.internal.getMessage(messageId);
686
- return await decodeMessage(this, data.data);
687
- }
688
- async getMessageList(channelId, before) {
689
- const { data: messages } = await this.internal.getMessageList({ container_id_type: "chat", container_id: channelId, page_token: before });
690
- const data = await Promise.all(messages.items.reverse().map((data2) => decodeMessage(this, data2)));
691
- return { data, next: data[0]?.id };
692
- }
693
- async getUser(userId, guildId) {
694
- const data = await this.internal.getContactUser(userId);
695
- return decodeUser(data.data);
696
- }
697
- async getChannel(channelId) {
698
- const { data } = await this.internal.getGuildInfo(channelId);
699
- return decodeChannel(data);
700
- }
701
- async getChannelList(guildId) {
702
- return { data: [await this.getChannel(guildId)] };
703
- }
704
- async getGuild(guildId) {
705
- const { data } = await this.internal.getGuildInfo(guildId);
706
- return decodeGuild(data);
707
- }
708
- async getGuildList(after) {
709
- const { data: guilds } = await this.internal.getCurrentUserGuilds({ page_token: after });
710
- return { data: guilds.items.map(decodeGuild), next: guilds.page_token };
711
- }
712
- async getGuildMemberList(guildId, after) {
713
- const { data: users } = await this.internal.getGuildMembers(guildId, { page_token: after });
714
- const data = users.items.map((v) => ({ user: { id: v.member_id, name: v.name }, name: v.name }));
715
- return { data, next: users.page_token };
716
- }
717
- };
718
- ((LarkBot2) => {
719
- LarkBot2.Config = import_satori5.Schema.intersect([
720
- import_satori5.Schema.object({
721
- platform: import_satori5.Schema.union(["feishu", "lark"]).required().description("平台名称。"),
722
- appId: import_satori5.Schema.string().required().description("机器人的应用 ID。"),
723
- appSecret: import_satori5.Schema.string().role("secret").required().description("机器人的应用密钥。"),
724
- encryptKey: import_satori5.Schema.string().role("secret").description("机器人的 Encrypt Key。"),
725
- verificationToken: import_satori5.Schema.string().description("事件推送的验证令牌。")
726
- }),
727
- import_satori5.Schema.union([
728
- import_satori5.Schema.intersect([
729
- import_satori5.Schema.object({
730
- platform: import_satori5.Schema.const("feishu").required()
731
- }),
732
- import_satori5.Quester.createConfig("https://open.feishu.cn/open-apis/"),
733
- HttpServer.createConfig("/feishu")
734
- ]),
735
- import_satori5.Schema.intersect([
736
- import_satori5.Schema.object({
737
- platform: import_satori5.Schema.const("lark").required()
738
- }),
739
- import_satori5.Quester.createConfig("https://open.larksuite.com/open-apis/"),
740
- HttpServer.createConfig("/lark")
741
- ])
742
- ])
743
- ]);
744
- })(LarkBot || (LarkBot = {}));
745
-
746
- // src/index.ts
747
- var src_default = LarkBot;
748
- // Annotate the CommonJS export names for ESM import in node:
749
- 0 && (module.exports = {
750
- Feishu,
751
- FeishuBot,
752
- Lark,
753
- LarkBot
754
- });
755
- //# sourceMappingURL=index.js.map