@satorijs/adapter-lark 3.8.3 → 3.8.5

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 CHANGED
@@ -394,6 +394,14 @@ var LarkMessageEncoder = class extends import_core3.MessageEncoder {
394
394
  async post(data) {
395
395
  try {
396
396
  let resp;
397
+ let quote = this.quote;
398
+ const payload = this.options?.session?.lark;
399
+ if (!quote && payload?.type === "im.message.receive_v1" && payload.event.message.thread_id) {
400
+ quote = {
401
+ id: payload.event.message.message_id,
402
+ replyInThread: true
403
+ };
404
+ }
397
405
  if (this.editMessageIds) {
398
406
  const messageId = this.editMessageIds.pop();
399
407
  if (!messageId) throw new Error("No message to edit");
@@ -403,10 +411,10 @@ var LarkMessageEncoder = class extends import_core3.MessageEncoder {
403
411
  } else {
404
412
  await this.bot.internal.updateImMessage(messageId, data);
405
413
  }
406
- } else if (this.quote?.id) {
407
- resp = await this.bot.internal.replyImMessage(this.quote.id, {
414
+ } else if (quote?.id) {
415
+ resp = await this.bot.internal.replyImMessage(quote.id, {
408
416
  ...data,
409
- reply_in_thread: this.quote.replyInThread
417
+ reply_in_thread: quote.replyInThread
410
418
  });
411
419
  } else {
412
420
  data.receive_id = this.channelId;
@@ -3353,7 +3361,7 @@ var LarkBot = class extends import_core5.Bot {
3353
3361
  this.logger.debug("refreshed token %s", token);
3354
3362
  this.token = token;
3355
3363
  if (this._refresher) clearTimeout(this._refresher);
3356
- this._refresher = setTimeout(() => this.refreshToken(), 3600 * 1e3);
3364
+ this._refresher = setTimeout(() => this.refreshToken(), import_core5.Time.minute * 100);
3357
3365
  this.online();
3358
3366
  }
3359
3367
  get token() {
package/lib/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export { Lark, Lark as Feishu };
5
5
  export default LarkBot;
6
6
  declare module '@satorijs/core' {
7
7
  interface Session {
8
- feishu: Lark.Internal;
9
- lark: Lark.Internal;
8
+ feishu: Lark.Internal & Lark.EventPayload;
9
+ lark: Lark.Internal & Lark.EventPayload;
10
10
  }
11
11
  }
@@ -16,6 +16,7 @@ declare module '../event' {
16
16
  message_id: string;
17
17
  root_id: string;
18
18
  parent_id: string;
19
+ thread_id: string;
19
20
  create_time: string;
20
21
  chat_id: string;
21
22
  chat_type: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@satorijs/adapter-lark",
3
3
  "description": "Lark (飞书) Adapter for Satorijs",
4
- "version": "3.8.3",
4
+ "version": "3.8.5",
5
5
  "type": "module",
6
6
  "main": "lib/index.cjs",
7
7
  "types": "lib/index.d.ts",
@@ -35,10 +35,10 @@
35
35
  ],
36
36
  "devDependencies": {
37
37
  "@cordisjs/plugin-server": "^0.2.5",
38
- "@satorijs/core": "^4.3.2",
38
+ "@satorijs/core": "^4.3.4",
39
39
  "cordis": "^3.18.1"
40
40
  },
41
41
  "peerDependencies": {
42
- "@satorijs/core": "^4.3.2"
42
+ "@satorijs/core": "^4.3.4"
43
43
  }
44
44
  }
package/src/bot.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Bot, Context, h, HTTP, Schema, Universal } from '@satorijs/core'
1
+ import { Bot, Context, h, HTTP, Schema, Time, Universal } from '@satorijs/core'
2
2
 
3
3
  import { HttpServer } from './http'
4
4
  import { LarkMessageEncoder } from './message'
@@ -71,10 +71,12 @@ export class LarkBot<C extends Context = Context> extends Bot<C, LarkBot.Config>
71
71
  })
72
72
  this.logger.debug('refreshed token %s', token)
73
73
  this.token = token
74
- // Token would be expired in 2 hours, refresh it every 1 hour
75
- // see https://open.larksuite.com/document/ukTMukTMukTM/ukDNz4SO0MjL5QzM/auth-v3/auth/tenant_access_token_internal
74
+ // tenant_access_token 的最大有效期是 2 小时。
75
+ // 剩余有效期小于 30 分钟时,调用本接口会返回一个新的 tenant_access_token,这会同时存在两个有效的 tenant_access_token。
76
+ // 剩余有效期大于等于 30 分钟时,调用本接口会返回原有的 tenant_access_token。
77
+ // https://open.feishu.cn/document/server-docs/authentication-management/access-token/tenant_access_token_internal
76
78
  if (this._refresher) clearTimeout(this._refresher)
77
- this._refresher = setTimeout(() => this.refreshToken(), 3600 * 1000)
79
+ this._refresher = setTimeout(() => this.refreshToken(), Time.minute * 100)
78
80
  this.online()
79
81
  }
80
82
 
package/src/index.ts CHANGED
@@ -9,7 +9,7 @@ export default LarkBot
9
9
 
10
10
  declare module '@satorijs/core' {
11
11
  interface Session {
12
- feishu: Lark.Internal
13
- lark: Lark.Internal
12
+ feishu: Lark.Internal & Lark.EventPayload
13
+ lark: Lark.Internal & Lark.EventPayload
14
14
  }
15
15
  }
package/src/message.ts CHANGED
@@ -16,6 +16,14 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco
16
16
  async post(data?: any) {
17
17
  try {
18
18
  let resp: Lark.Message
19
+ let quote = this.quote
20
+ const payload = this.options?.session?.lark
21
+ if (!quote && payload?.type === 'im.message.receive_v1' && payload.event.message.thread_id) {
22
+ quote = {
23
+ id: payload.event.message.message_id,
24
+ replyInThread: true,
25
+ }
26
+ }
19
27
  if (this.editMessageIds) {
20
28
  const messageId = this.editMessageIds.pop()
21
29
  if (!messageId) throw new Error('No message to edit')
@@ -25,10 +33,10 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco
25
33
  } else {
26
34
  await this.bot.internal.updateImMessage(messageId, data)
27
35
  }
28
- } else if (this.quote?.id) {
29
- resp = await this.bot.internal.replyImMessage(this.quote.id, {
36
+ } else if (quote?.id) {
37
+ resp = await this.bot.internal.replyImMessage(quote.id, {
30
38
  ...data,
31
- reply_in_thread: this.quote.replyInThread,
39
+ reply_in_thread: quote.replyInThread,
32
40
  })
33
41
  } else {
34
42
  data.receive_id = this.channelId
@@ -18,6 +18,7 @@ declare module '../event' {
18
18
  message_id: string
19
19
  root_id: string
20
20
  parent_id: string
21
+ thread_id: string
21
22
  create_time: string
22
23
  chat_id: string
23
24
  chat_type: string