@satorijs/adapter-lark 3.9.4 → 3.9.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 +25 -10
- package/package.json +1 -1
- package/src/bot.ts +15 -8
- package/src/message.ts +11 -3
package/lib/index.cjs
CHANGED
|
@@ -574,10 +574,18 @@ var LarkMessageEncoder = class extends import_core3.MessageEncoder {
|
|
|
574
574
|
if (type === "text") {
|
|
575
575
|
this.textContent += attrs.content;
|
|
576
576
|
} else if (type === "at") {
|
|
577
|
-
if (
|
|
578
|
-
|
|
577
|
+
if (this.card) {
|
|
578
|
+
if (attrs.type === "all") {
|
|
579
|
+
this.textContent += `<at id=all>${attrs.name ?? "所有人"}</at>`;
|
|
580
|
+
} else {
|
|
581
|
+
this.textContent += `<at id=${attrs.id}>${attrs.name ?? ""}</at>`;
|
|
582
|
+
}
|
|
579
583
|
} else {
|
|
580
|
-
|
|
584
|
+
if (attrs.type === "all") {
|
|
585
|
+
this.textContent += `<at user_id="all">${attrs.name ?? "所有人"}</at>`;
|
|
586
|
+
} else {
|
|
587
|
+
this.textContent += `<at user_id="${attrs.id}">${attrs.name ?? ""}</at>`;
|
|
588
|
+
}
|
|
581
589
|
}
|
|
582
590
|
} else if (type === "a") {
|
|
583
591
|
await this.render(children);
|
|
@@ -916,14 +924,21 @@ var LarkBot = class extends import_core5.Bot {
|
|
|
916
924
|
this.online();
|
|
917
925
|
}
|
|
918
926
|
async refreshToken() {
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
927
|
+
let timeout = import_core5.Time.minute * 20;
|
|
928
|
+
try {
|
|
929
|
+
const { tenant_access_token: token } = await this.internal.tenantAccessTokenInternalAuth({
|
|
930
|
+
app_id: this.config.appId,
|
|
931
|
+
app_secret: this.config.appSecret
|
|
932
|
+
});
|
|
933
|
+
this.logger.debug("refreshed token %s", token);
|
|
934
|
+
this.token = token;
|
|
935
|
+
} catch (error) {
|
|
936
|
+
this.logger.error("failed to refresh token, retrying in 10s");
|
|
937
|
+
this.logger.error(error);
|
|
938
|
+
timeout = import_core5.Time.second * 10;
|
|
939
|
+
}
|
|
925
940
|
if (this._refresher) clearTimeout(this._refresher);
|
|
926
|
-
this._refresher = setTimeout(() => this.refreshToken(),
|
|
941
|
+
this._refresher = setTimeout(() => this.refreshToken(), timeout);
|
|
927
942
|
this.online();
|
|
928
943
|
}
|
|
929
944
|
get token() {
|
package/package.json
CHANGED
package/src/bot.ts
CHANGED
|
@@ -74,19 +74,26 @@ export class LarkBot<C extends Context = Context> extends Bot<C, LarkBot.Config>
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
private async refreshToken() {
|
|
77
|
-
const { tenant_access_token: token } = await this.internal.tenantAccessTokenInternalAuth({
|
|
78
|
-
app_id: this.config.appId,
|
|
79
|
-
app_secret: this.config.appSecret,
|
|
80
|
-
})
|
|
81
|
-
this.logger.debug('refreshed token %s', token)
|
|
82
|
-
this.token = token
|
|
83
|
-
if (this._refresher) clearTimeout(this._refresher)
|
|
84
77
|
// https://open.feishu.cn/document/server-docs/authentication-management/access-token/tenant_access_token_internal
|
|
85
78
|
// tenant_access_token 的最大有效期是 2 小时。
|
|
86
79
|
// 剩余有效期小于 30 分钟时,调用本接口会返回一个新的 tenant_access_token,此时会同时存在两个有效的 tenant_access_token。
|
|
87
80
|
// 剩余有效期大于等于 30 分钟时,调用本接口会返回原有的 tenant_access_token。
|
|
88
81
|
// 初次获得 token 后的半小时内必须刷新一次,因为初次获得的 token 可能是 1.5 小时前生成的。
|
|
89
|
-
|
|
82
|
+
let timeout = Time.minute * 20
|
|
83
|
+
try {
|
|
84
|
+
const { tenant_access_token: token } = await this.internal.tenantAccessTokenInternalAuth({
|
|
85
|
+
app_id: this.config.appId,
|
|
86
|
+
app_secret: this.config.appSecret,
|
|
87
|
+
})
|
|
88
|
+
this.logger.debug('refreshed token %s', token)
|
|
89
|
+
this.token = token
|
|
90
|
+
} catch (error) {
|
|
91
|
+
this.logger.error('failed to refresh token, retrying in 10s')
|
|
92
|
+
this.logger.error(error)
|
|
93
|
+
timeout = Time.second * 10
|
|
94
|
+
}
|
|
95
|
+
if (this._refresher) clearTimeout(this._refresher)
|
|
96
|
+
this._refresher = setTimeout(() => this.refreshToken(), timeout)
|
|
90
97
|
this.online()
|
|
91
98
|
}
|
|
92
99
|
|
package/src/message.ts
CHANGED
|
@@ -206,10 +206,18 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco
|
|
|
206
206
|
if (type === 'text') {
|
|
207
207
|
this.textContent += attrs.content
|
|
208
208
|
} else if (type === 'at') {
|
|
209
|
-
if (
|
|
210
|
-
|
|
209
|
+
if (this.card) {
|
|
210
|
+
if (attrs.type === 'all') {
|
|
211
|
+
this.textContent += `<at id=all>${attrs.name ?? '所有人'}</at>`
|
|
212
|
+
} else {
|
|
213
|
+
this.textContent += `<at id=${attrs.id}>${attrs.name ?? ''}</at>`
|
|
214
|
+
}
|
|
211
215
|
} else {
|
|
212
|
-
|
|
216
|
+
if (attrs.type === 'all') {
|
|
217
|
+
this.textContent += `<at user_id="all">${attrs.name ?? '所有人'}</at>`
|
|
218
|
+
} else {
|
|
219
|
+
this.textContent += `<at user_id="${attrs.id}">${attrs.name ?? ''}</at>`
|
|
220
|
+
}
|
|
213
221
|
}
|
|
214
222
|
} else if (type === 'a') {
|
|
215
223
|
await this.render(children)
|