dsh-im-lark 0.1.0 → 0.1.2
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/README.md +5 -4
- package/docs/adr/0005-/347/213/254/347/253/213/346/250/241/345/274/217/351/227/256/351/242/230/344/270/216/345/256/241/346/211/271/346/217/220/351/206/222.md +22 -0
- package/lib/client.js +27 -10
- package/lib/src/host/bridge.js +59 -3
- package/lib/src/host/cards.js +24 -0
- package/lib/src/host/inbound-pipeline.js +8 -1
- package/lib/src/host/panel-host.js +3 -1
- package/lib/src/host/questions.js +22 -4
- package/lib/src/host/reminder-card.js +3 -0
- package/lib/src/host/runtime.js +3 -1
- package/lib/src/host/state/credentials.js +35 -9
- package/lib/src/shared/version.js +1 -1
- package/locale/en.json +3 -3
- package/locale/zh.json +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,9 +28,10 @@
|
|
|
28
28
|
- **面板**:Web 端插件页扫码一键创建应用,或手动填 App ID / App Secret;看连接状态、开关收发/核心接入、改消息行为;独立模式可调回合内插话、会话工作区、问题/审批提醒与长程任务提醒
|
|
29
29
|
|
|
30
30
|
> 提问卡片(勾选器 + 提交 + 「其他」输入)在独立模式与核心模式都已于真实飞书租户验收:
|
|
31
|
-
>
|
|
32
|
-
>
|
|
33
|
-
>
|
|
31
|
+
> 单选/多选靠卡片文案区分,提交后回传勾选项与「其他」输入。两种模式的作答被拒都有可见
|
|
32
|
+
> 反馈:还能答的卡会**整卡重画**并写上原因(飞书的表单提交是一次性的,只发一句提示
|
|
33
|
+
> 会让卡片点不动),可以重新勾选提交;已经不能再答的卡直接改成失效态、去掉勾选框。
|
|
34
|
+
> `Typing` 表情与卡片排版随租户配置略有差异,以实际表现为准。
|
|
34
35
|
|
|
35
36
|
## 安装
|
|
36
37
|
|
|
@@ -108,7 +109,7 @@ dsh plugin --profile web add file:/绝对路径/dsh-im-lark
|
|
|
108
109
|
failureReminders: true # 独立模式:回合失败或被外部中止时立刻提醒
|
|
109
110
|
```
|
|
110
111
|
|
|
111
|
-
面板能改的项会落到 `$DSH_HOME/.dsh-im-lark/config.json`,卸载重装后沿用。凭据单独存 `credentials.json`,目录 0700、文件 0600
|
|
112
|
+
面板能改的项会落到 `$DSH_HOME/.dsh-im-lark/config.json`,卸载重装后沿用。凭据单独存 `credentials.json`,目录 0700、文件 0600,日志与错误信息里只出现 App ID 尾号;面板显示完整 App ID 与绑定时间,Secret 不回显。
|
|
112
113
|
|
|
113
114
|
## 独立会话命令
|
|
114
115
|
|
|
@@ -58,6 +58,28 @@ Web 与飞书可能同时有人在等;两边都答会重复或矛盾;审批
|
|
|
58
58
|
> 真机验收:多选勾两项提交两项都回传;单选勾一项提交回传一项。
|
|
59
59
|
> 参考:[表单容器](https://open.feishu.cn/document/feishu-cards/card-json-v2-components/containers/form-container)、
|
|
60
60
|
> [勾选器](https://open.feishu.cn/document/feishu-cards/card-json-v2-components/interactive-components/checker)。
|
|
61
|
+
>
|
|
62
|
+
> 2026-11-22 修订(核心模式):核心模式的卡片作答原先只在被拒时写调试日志,用户侧
|
|
63
|
+
> 表现为「勾完点提交没反应」。现在对**每一次拒绝**都说明原因:能继续答的卡(例如单选
|
|
64
|
+
> 勾了两项)**整卡重画**——保留勾选框与提交按钮、附上原因;已经不能再答的
|
|
65
|
+
> (`unknown` / `expired` / `wrong-bridge` / `not-delivered`)改成失效态、去掉勾选框并
|
|
66
|
+
> 清掉待作答;`settled`(已经答过)保持静默。
|
|
67
|
+
>
|
|
68
|
+
> 为什么必须重画而不是发一句提示:实测(2026-11-22,真实租户)提交过的卡再点「提交」
|
|
69
|
+
> 收不到回调——第一版只补了一句文字提示,用户报「提示收到了,但此后不能再答」。官方把
|
|
70
|
+
> 「表单提交后更新为已提交卡片」列为全量更新的典型场景,正是这个用法
|
|
71
|
+
> ([更新卡片](https://open.feishu.cn/document/feishu-cards/update-feishu-card))。
|
|
72
|
+
> 「提交后这张卡的控件一律失效」是实测结论,未在文档里找到明文,按现象记录。
|
|
73
|
+
> 独立模式的提醒卡同样改为重画(`questions.ts` 的 `#noteChoice`)。
|
|
74
|
+
>
|
|
75
|
+
> 只有卡不在手里(重启丢了记录、回调缺 id)才退化成一条文字提示,同卡同原因只发一次。
|
|
76
|
+
>
|
|
77
|
+
> 同次排查还挖出第二个原因:入站去重键只看按钮的 `value`(`{d,q}`),而同一张卡每次
|
|
78
|
+
> 提交的 `value` 完全一样——勾选项在 `form_value` 里。于是「勾两项被拒 → 改勾一项重新
|
|
79
|
+
> 提交」的第二次回调被当成平台重推丢掉,用户侧同样表现为「此后不能再答」。现在去重键
|
|
80
|
+
> 带上 `form_value` 与 `option`;没有 `event_id` 时只覆盖 5s 重推窗口,窗口之外允许同一
|
|
81
|
+
> 张卡再次提交(平台重推仍由待作答状态兜底:第二次会得到 `settled`,静默丢弃)。
|
|
82
|
+
> 单测覆盖:同一张卡改选项再提交能处理、同一份回调在窗口内只处理一次。
|
|
61
83
|
|
|
62
84
|
## 备选
|
|
63
85
|
|
package/lib/client.js
CHANGED
|
@@ -74,7 +74,6 @@ var en_default = {
|
|
|
74
74
|
"panel.refresh": "Refresh",
|
|
75
75
|
"panel.retry": "Retry",
|
|
76
76
|
"status.title": "Connection",
|
|
77
|
-
"status.connection": "Long connection",
|
|
78
77
|
"status.appId": "App ID",
|
|
79
78
|
"status.domain": "Platform",
|
|
80
79
|
"status.enabled": "Connect Lark",
|
|
@@ -91,7 +90,8 @@ var en_default = {
|
|
|
91
90
|
"state.failed": "Failed",
|
|
92
91
|
"credentials.title": "App credentials",
|
|
93
92
|
"credentials.hint": "From the Lark developer console. Stored locally; the secret is never echoed.",
|
|
94
|
-
"credentials.configured": "
|
|
93
|
+
"credentials.configured": "Bound to {appId} \xB7 {domain}",
|
|
94
|
+
"credentials.boundAt": "Bound since {boundAt}",
|
|
95
95
|
"credentials.manual": "Enter credentials manually",
|
|
96
96
|
"credentials.appId": "App ID",
|
|
97
97
|
"credentials.appSecret": "App Secret",
|
|
@@ -105,7 +105,7 @@ var en_default = {
|
|
|
105
105
|
"credentials.probing": "Testing\u2026",
|
|
106
106
|
"credentials.clear": "Clear credentials",
|
|
107
107
|
"credentials.clearTitle": "Clear credentials?",
|
|
108
|
-
"credentials.clearHint": "This removes the credentials for
|
|
108
|
+
"credentials.clearHint": "This removes the credentials for {appId} (App ID and App Secret).",
|
|
109
109
|
"credentials.clearWarning": "The long connection closes immediately; reconnecting requires entering them again.",
|
|
110
110
|
"credentials.clearConfirm": "Clear",
|
|
111
111
|
"credentials.cleared": "Credentials cleared",
|
|
@@ -186,7 +186,6 @@ var zh_default = {
|
|
|
186
186
|
"panel.refresh": "\u5237\u65B0",
|
|
187
187
|
"panel.retry": "\u91CD\u8BD5",
|
|
188
188
|
"status.title": "\u8FDE\u63A5\u72B6\u6001",
|
|
189
|
-
"status.connection": "\u957F\u8FDE\u63A5",
|
|
190
189
|
"status.appId": "App ID",
|
|
191
190
|
"status.domain": "\u5E73\u53F0",
|
|
192
191
|
"status.enabled": "\u63A5\u5165\u98DE\u4E66",
|
|
@@ -203,7 +202,8 @@ var zh_default = {
|
|
|
203
202
|
"state.failed": "\u8FDE\u63A5\u5931\u8D25",
|
|
204
203
|
"credentials.title": "\u5E94\u7528\u51ED\u636E",
|
|
205
204
|
"credentials.hint": "\u5728\u98DE\u4E66\u5F00\u653E\u5E73\u53F0\u300C\u51ED\u8BC1\u4E0E\u57FA\u7840\u4FE1\u606F\u300D\u91CC\u83B7\u53D6\u3002\u53EA\u4FDD\u5B58\u5728\u672C\u673A\uFF0C\u9762\u677F\u4E0D\u4F1A\u56DE\u663E Secret\u3002",
|
|
206
|
-
"credentials.configured": "\u5DF2\
|
|
205
|
+
"credentials.configured": "\u5DF2\u7ED1\u5B9A {appId} \xB7 {domain}",
|
|
206
|
+
"credentials.boundAt": "\u7ED1\u5B9A\u4E8E {boundAt}",
|
|
207
207
|
"credentials.manual": "\u624B\u52A8\u586B\u5199\u51ED\u636E",
|
|
208
208
|
"credentials.appId": "App ID",
|
|
209
209
|
"credentials.appSecret": "App Secret",
|
|
@@ -217,7 +217,7 @@ var zh_default = {
|
|
|
217
217
|
"credentials.probing": "\u6B63\u5728\u81EA\u68C0\u2026",
|
|
218
218
|
"credentials.clear": "\u6E05\u9664\u51ED\u636E",
|
|
219
219
|
"credentials.clearTitle": "\u6E05\u9664\u51ED\u636E\uFF1F",
|
|
220
|
-
"credentials.clearHint": "\u5C06\u6E05\u9664
|
|
220
|
+
"credentials.clearHint": "\u5C06\u6E05\u9664 {appId} \u7684\u5E94\u7528\u51ED\u636E\uFF08App ID \u4E0E App Secret\uFF09\u3002",
|
|
221
221
|
"credentials.clearWarning": "\u6E05\u9664\u540E\u957F\u8FDE\u63A5\u7ACB\u5373\u65AD\u5F00\uFF0C\u91CD\u65B0\u63A5\u5165\u9700\u8981\u518D\u586B\u4E00\u6B21\u51ED\u636E\u3002",
|
|
222
222
|
"credentials.clearConfirm": "\u6E05\u9664",
|
|
223
223
|
"credentials.cleared": "\u51ED\u636E\u5DF2\u6E05\u9664",
|
|
@@ -744,6 +744,7 @@ function LarkSettingsPanel(props) {
|
|
|
744
744
|
const [error, setError] = useState("");
|
|
745
745
|
const [notice, setNotice] = useState("");
|
|
746
746
|
const [appId, setAppId] = useState("");
|
|
747
|
+
const appIdPrefilled = useRef(false);
|
|
747
748
|
const [appSecret, setAppSecret] = useState("");
|
|
748
749
|
const [domain, setDomain] = useState("feishu");
|
|
749
750
|
const [registration, setRegistration] = useState(null);
|
|
@@ -758,6 +759,11 @@ function LarkSettingsPanel(props) {
|
|
|
758
759
|
const applySnapshot = useCallback((next) => {
|
|
759
760
|
setSnapshot(next);
|
|
760
761
|
setDomain((current) => current === "" ? next.status.domain : current);
|
|
762
|
+
const bound = next.status.appId;
|
|
763
|
+
if (!appIdPrefilled.current && bound !== null && bound !== "") {
|
|
764
|
+
appIdPrefilled.current = true;
|
|
765
|
+
setAppId((current) => current === "" ? bound : current);
|
|
766
|
+
}
|
|
761
767
|
}, []);
|
|
762
768
|
const refresh = useCallback(async (quiet = false) => {
|
|
763
769
|
try {
|
|
@@ -1014,8 +1020,10 @@ function LarkSettingsPanel(props) {
|
|
|
1014
1020
|
h(
|
|
1015
1021
|
"div",
|
|
1016
1022
|
{ className: "lark-rows" },
|
|
1017
|
-
row(
|
|
1018
|
-
|
|
1023
|
+
row(
|
|
1024
|
+
t("status.appId"),
|
|
1025
|
+
status?.appId === null || status?.appId === void 0 ? t("status.notConfigured") : h("span", { className: "lark-mono" }, status.appId)
|
|
1026
|
+
),
|
|
1019
1027
|
row(t("status.domain"), domainLabel)
|
|
1020
1028
|
),
|
|
1021
1029
|
toggleRow(h(Switch, { checked: settings?.enabled === true, onChange: (value) => toggle("enabled", value), label: t("status.enabled") }), t("status.enabled"), t("status.enabledHint")),
|
|
@@ -1040,7 +1048,8 @@ function LarkSettingsPanel(props) {
|
|
|
1040
1048
|
"div",
|
|
1041
1049
|
{ className: "lark-card-heading" },
|
|
1042
1050
|
h("div", { className: "lark-card-title" }, t("credentials.title")),
|
|
1043
|
-
!credentialsOpen && credentialsConfigured ? h("div", { className: "lark-card-hint" }, t("credentials.configured", { appId: status?.
|
|
1051
|
+
!credentialsOpen && credentialsConfigured ? h("div", { className: "lark-card-hint" }, t("credentials.configured", { appId: status?.appId ?? "", domain: domainLabel })) : null,
|
|
1052
|
+
!credentialsOpen && credentialsConfigured ? h("div", { className: "lark-card-hint" }, t("credentials.boundAt", { boundAt: formatBoundAt(status?.boundAt) })) : null
|
|
1044
1053
|
),
|
|
1045
1054
|
h(
|
|
1046
1055
|
Button,
|
|
@@ -1067,7 +1076,7 @@ function LarkSettingsPanel(props) {
|
|
|
1067
1076
|
h(ConfirmDialog, {
|
|
1068
1077
|
open: clearOpen,
|
|
1069
1078
|
title: t("credentials.clearTitle"),
|
|
1070
|
-
lines: [t("credentials.clearHint", { appId: status?.
|
|
1079
|
+
lines: [t("credentials.clearHint", { appId: status?.appId ?? "" }), t("credentials.clearWarning")],
|
|
1071
1080
|
cancelLabel: t("common.cancel"),
|
|
1072
1081
|
confirmLabel: t("credentials.clearConfirm"),
|
|
1073
1082
|
closeLabel: t("common.close"),
|
|
@@ -1077,6 +1086,8 @@ function LarkSettingsPanel(props) {
|
|
|
1077
1086
|
credentialsOpen ? h(
|
|
1078
1087
|
"div",
|
|
1079
1088
|
{ id: "lark-credentials-body", className: "lark-card-body" },
|
|
1089
|
+
credentialsConfigured ? h("div", { className: "lark-card-hint" }, t("credentials.configured", { appId: status?.appId ?? "", domain: domainLabel })) : null,
|
|
1090
|
+
credentialsConfigured ? h("div", { className: "lark-card-hint" }, t("credentials.boundAt", { boundAt: formatBoundAt(status?.boundAt) })) : null,
|
|
1080
1091
|
h("div", { className: "lark-card-hint" }, t("credentials.hint")),
|
|
1081
1092
|
h(
|
|
1082
1093
|
"div",
|
|
@@ -1322,6 +1333,12 @@ function workspaceOptions(catalog, current, t) {
|
|
|
1322
1333
|
function row(label, value) {
|
|
1323
1334
|
return h("div", { className: "lark-row" }, h("span", { className: "lark-row-label" }, label), h("span", { className: "lark-row-value" }, value));
|
|
1324
1335
|
}
|
|
1336
|
+
function formatBoundAt(boundAt) {
|
|
1337
|
+
if (boundAt === void 0 || boundAt === null) return "\u2014";
|
|
1338
|
+
const at = new Date(boundAt);
|
|
1339
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
1340
|
+
return `${at.getFullYear()}-${pad(at.getMonth() + 1)}-${pad(at.getDate())} ${pad(at.getHours())}:${pad(at.getMinutes())}:${pad(at.getSeconds())}`;
|
|
1341
|
+
}
|
|
1325
1342
|
function fieldRow(label, control) {
|
|
1326
1343
|
return h(
|
|
1327
1344
|
"div",
|
package/lib/src/host/bridge.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* (核心侧对「先注册后确定账号」没有宽容度)。
|
|
9
9
|
*/
|
|
10
10
|
import { DEFAULT_MAX_TEXT_CHARS } from "../shared/limits.js";
|
|
11
|
-
import { InteractionStore, answerFromAction, renderAnsweredCard, renderDeliveryCard, renderSupersededCard, cardFits } from "./cards.js";
|
|
11
|
+
import { InteractionStore, answerFromAction, renderAnsweredCard, renderDeliveryCard, renderRejectedCard, renderRetryCard, renderSupersededCard, cardFits } from "./cards.js";
|
|
12
12
|
import { OutboundChannel } from "./outbound.js";
|
|
13
13
|
import { PROTOCOL_V1 } from "./protocol.js";
|
|
14
14
|
/** 能力声明:与方案设计 6.3 一致,测试里会用核心的 Schema 再校验一次。 */
|
|
@@ -31,6 +31,22 @@ const CAPABILITIES = {
|
|
|
31
31
|
outbound: Object.freeze({ requiresPriorInbound: false, images: true }),
|
|
32
32
|
};
|
|
33
33
|
export const LARK_CAPABILITIES = Object.freeze(CAPABILITIES);
|
|
34
|
+
/**
|
|
35
|
+
* 作答被拒的可见说明:核心模式没有独立模式那条提示通道,拒绝如果只写调试日志,
|
|
36
|
+
* 用户看到的就是「点了没反应」。文案对齐独立模式(`questions.ts` 的提示)。
|
|
37
|
+
*/
|
|
38
|
+
const REJECT_NOTES = {
|
|
39
|
+
invalid: '这张卡的作答信息不完整,请在 Web 端作答。',
|
|
40
|
+
'not-owner': '这张卡只认主人作答,请在 Web 端作答。',
|
|
41
|
+
unknown: '这张卡已经失效(插件重启过),不再接收作答;请在 Web 端重新作答。',
|
|
42
|
+
expired: '这张卡已经过期,请在 Web 端重新作答。',
|
|
43
|
+
'wrong-bridge': '这张卡不属于当前接入的机器人,请在 Web 端作答。',
|
|
44
|
+
'not-delivered': '这张卡没有真正发出去,请在 Web 端作答。',
|
|
45
|
+
'not-allowed': '审批要在 Web 端处理,飞书里不代答。',
|
|
46
|
+
'invalid-answer': '没认出这次选择:单选题只能勾一项,勾选(或填「其他」)后点「提交」。',
|
|
47
|
+
};
|
|
48
|
+
/** 这些原因意味着卡不能再答:改成失效态,别留一排还能点的勾选框。 */
|
|
49
|
+
const TERMINAL_REJECTS = new Set(['unknown', 'expired', 'wrong-bridge', 'not-delivered']);
|
|
34
50
|
/** 已交付记录与流式修订的内存上限:长跑进程不能让它们无限涨。 */
|
|
35
51
|
const MAX_DELIVERED = 2_000;
|
|
36
52
|
/** 入站引用表与「收件人 → 会话」表的上限。 */
|
|
@@ -219,13 +235,53 @@ export function createLarkBridge(deps) {
|
|
|
219
235
|
}
|
|
220
236
|
interactions.markAnswered(deliveryId);
|
|
221
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* 作答被拒时说清原因。
|
|
240
|
+
*
|
|
241
|
+
* 核心模式没有独立模式那条提示通道:拒绝如果只写调试日志,用户看到的就是「点了没反应」。
|
|
242
|
+
* 能答的卡要**重画**——飞书的表单提交是一次性的,提交过的卡不会再触发回调,只发一句
|
|
243
|
+
* 提示等于把这张卡废掉;不能再答的直接改成失效态。都改写同一张卡,所以不会刷屏;
|
|
244
|
+
* 只有卡不在手里(重启丢了记录、回调缺 id)才退化成一条文字提示,同卡同原因只发一次。
|
|
245
|
+
*/
|
|
246
|
+
async function noteRejected(action, reason, deliveryId) {
|
|
247
|
+
if (reason === 'settled')
|
|
248
|
+
return; // 已经答过了,再提示只会吵。
|
|
249
|
+
const note = REJECT_NOTES[reason];
|
|
250
|
+
const terminal = TERMINAL_REJECTS.has(reason);
|
|
251
|
+
const record = deliveryId === undefined ? undefined : delivered.get(deliveryId);
|
|
252
|
+
if (record !== undefined) {
|
|
253
|
+
const card = terminal ? renderRejectedCard(record.delivery, note) : renderRetryCard(record.delivery, note);
|
|
254
|
+
try {
|
|
255
|
+
await deps.api.patchCard({ messageId: record.messageId, card });
|
|
256
|
+
if (terminal && deliveryId !== undefined)
|
|
257
|
+
interactions.delete(deliveryId);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
logger.debug?.('卡片改写失败,改为发提示', errorText(error));
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
const key = `note:${action.messageId}:${reason}`;
|
|
265
|
+
const receipt = await outbound.deliver({ deliveryId: key, chatId: action.chatId, text: note }).catch((error) => {
|
|
266
|
+
logger.debug?.('作答被拒的提示没发出去', errorText(error));
|
|
267
|
+
return undefined;
|
|
268
|
+
});
|
|
269
|
+
if (receipt !== undefined && receipt.errorCode !== undefined) {
|
|
270
|
+
logger.debug?.('作答被拒的提示发送失败', `${receipt.errorCode} ${receipt.error ?? ''}`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
222
273
|
async function applyCardAction(action) {
|
|
274
|
+
const deliveryId = typeof action.value.d === 'string' ? action.value.d : undefined;
|
|
223
275
|
const result = answerFromAction(action.value, action.option, action.formValues, action.operatorOpenId, interactions, now());
|
|
224
|
-
if ('reason' in result)
|
|
276
|
+
if ('reason' in result) {
|
|
277
|
+
await noteRejected(action, result.reason, deliveryId);
|
|
225
278
|
return { accepted: false, reason: result.reason, ...(result.detail === undefined ? {} : { detail: result.detail }) };
|
|
279
|
+
}
|
|
226
280
|
const accepted = await answer(result);
|
|
227
|
-
if (!accepted.accepted)
|
|
281
|
+
if (!accepted.accepted) {
|
|
282
|
+
await noteRejected(action, accepted.reason, deliveryId);
|
|
228
283
|
return accepted;
|
|
284
|
+
}
|
|
229
285
|
interactions.markAnswered(result.deliveryId);
|
|
230
286
|
const record = delivered.get(result.deliveryId);
|
|
231
287
|
if (record === undefined)
|
package/lib/src/host/cards.js
CHANGED
|
@@ -174,6 +174,30 @@ export function renderSupersededCard(delivery) {
|
|
|
174
174
|
body.elements.push({ tag: 'markdown', content: '_这条已过期,已被新卡片替代。_', text_size: 'notation' });
|
|
175
175
|
return card;
|
|
176
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* 作答被拒但还能重来的卡:保留勾选框与提交按钮,附上原因。
|
|
179
|
+
*
|
|
180
|
+
* 飞书的表单提交是一次性的——提交之后这张卡的控件不会再触发回调,只有整卡改写才
|
|
181
|
+
* 回到可用状态(官方「表单提交后更新为已提交卡片」的同一套做法)。所以拒绝时不能只
|
|
182
|
+
* 发一句提示,得把这张卡本身重画一遍。
|
|
183
|
+
*/
|
|
184
|
+
export function renderRetryCard(delivery, note) {
|
|
185
|
+
const card = renderDeliveryCard(delivery, { interactive: true });
|
|
186
|
+
const body = card.body;
|
|
187
|
+
body.elements.push({ tag: 'markdown', content: `_**${note}**_`, text_size: 'notation' });
|
|
188
|
+
return card;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* 作答被拒且这张卡不能再答的终态:去掉按钮,写清为什么。
|
|
192
|
+
*
|
|
193
|
+
* 留着一排还能点的勾选框,用户只会反复点、反复被拒,还以为插件坏了。
|
|
194
|
+
*/
|
|
195
|
+
export function renderRejectedCard(delivery, note) {
|
|
196
|
+
const card = renderDeliveryCard(delivery, { interactive: false });
|
|
197
|
+
const body = card.body;
|
|
198
|
+
body.elements.push({ tag: 'markdown', content: `_${note}_`, text_size: 'notation' });
|
|
199
|
+
return card;
|
|
200
|
+
}
|
|
177
201
|
/**
|
|
178
202
|
* 未作答的交互卡。
|
|
179
203
|
*
|
|
@@ -23,6 +23,8 @@ const TEXT_MAX = 20_000;
|
|
|
23
23
|
const REACTION_TYPING = 'Typing';
|
|
24
24
|
const REACTION_DONE = 'DONE';
|
|
25
25
|
const KNOWN_IMAGE_TYPES = new Set(['image/png', 'image/jpeg', 'image/webp', 'image/gif']);
|
|
26
|
+
/** 卡片回调的重推窗口:没有 `event_id` 时用它兜住平台重推,窗口之外允许同一张卡再提交。 */
|
|
27
|
+
const CARD_RETRY_WINDOW_MS = 5_000;
|
|
26
28
|
export class InboundPipeline {
|
|
27
29
|
#api;
|
|
28
30
|
#bridge;
|
|
@@ -100,7 +102,12 @@ export class InboundPipeline {
|
|
|
100
102
|
this.#logger.debug?.('非主人卡片回调,忽略', action.operatorOpenId);
|
|
101
103
|
return;
|
|
102
104
|
}
|
|
103
|
-
|
|
105
|
+
// 去重键要带上**表单值**:同一张卡每次提交的 `value` 都一样,勾选项在 `form_value` 里。
|
|
106
|
+
// 只按 `value` 去重会把「改一项重新提交」当成平台重推丢掉——真机上表现为「提示收到了,
|
|
107
|
+
// 但此后不能再答」。没有 `event_id` 时也只覆盖重推窗口(几秒),窗口之外允许再提交。
|
|
108
|
+
const stamp = Math.floor(this.#now() / CARD_RETRY_WINDOW_MS);
|
|
109
|
+
const key = `card:${action.eventId ||
|
|
110
|
+
`${action.messageId}:${JSON.stringify(action.value)}:${JSON.stringify(action.formValues ?? null)}:${String(action.option ?? '')}:${stamp}`}`;
|
|
104
111
|
if (!this.#seen.claim(key))
|
|
105
112
|
return;
|
|
106
113
|
this.#enqueue(async () => {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* 出来就回 `invalid-config`。浏览器发来的 JSON 是不可信输入,不把它直接塞进
|
|
10
10
|
* 运行期,也不把内部错误原文透给页面(可能带本机路径)。
|
|
11
11
|
*
|
|
12
|
-
*
|
|
12
|
+
* 凭据只在保存时经过这里;读取回完整 App ID 与绑定时间(Secret 不出边界)。
|
|
13
13
|
*/
|
|
14
14
|
import { PANEL_CONTRACT, PLUGIN_VERSION, RPC_CHANNEL, RPC_ENDPOINT, RPC_PREFIX } from "../shared/version.js";
|
|
15
15
|
import { normalizeQuestionDelayMinutes } from "./config.js";
|
|
@@ -74,7 +74,9 @@ export function snapshotOf(deps) {
|
|
|
74
74
|
maxText: deps.config.maxText,
|
|
75
75
|
rpcChannel: RPC_CHANNEL,
|
|
76
76
|
},
|
|
77
|
+
appId: status.appId,
|
|
77
78
|
appIdTail: status.appIdTail,
|
|
79
|
+
boundAt: status.boundAt,
|
|
78
80
|
};
|
|
79
81
|
}
|
|
80
82
|
export async function handleEndpoint(deps, endpoint, payload) {
|
|
@@ -259,11 +259,11 @@ export class QuestionBroker {
|
|
|
259
259
|
return false;
|
|
260
260
|
const answer = answerFromCard(question, action.value, action.option, action.formValues);
|
|
261
261
|
if (answer === null) {
|
|
262
|
-
this.#noteChoice(`提醒 #${pending.no} 还没选择任何选项,勾选后再点「提交」。`);
|
|
262
|
+
this.#noteChoice(pending, `提醒 #${pending.no} 还没选择任何选项,勾选后再点「提交」。`);
|
|
263
263
|
return true;
|
|
264
264
|
}
|
|
265
265
|
if (question.multiSelect !== true && answer.selected.length > 1) {
|
|
266
|
-
this.#noteChoice(`提醒 #${pending.no} 是单选题,只能勾选一项,请重新提交。`);
|
|
266
|
+
this.#noteChoice(pending, `提醒 #${pending.no} 是单选题,只能勾选一项,请重新提交。`);
|
|
267
267
|
return true;
|
|
268
268
|
}
|
|
269
269
|
pending.resolve({ answers: [answer] });
|
|
@@ -272,8 +272,26 @@ export class QuestionBroker {
|
|
|
272
272
|
this.#closeCard(pending, `已在飞书作答:${chosen}`);
|
|
273
273
|
return true;
|
|
274
274
|
}
|
|
275
|
-
/**
|
|
276
|
-
|
|
275
|
+
/**
|
|
276
|
+
* 提交不合规:把同一张卡连同原因重画一遍,待答保留。
|
|
277
|
+
*
|
|
278
|
+
* 飞书的表单提交是一次性的——提交过的卡不会再触发回调,只回一句文字会让卡片表面
|
|
279
|
+
* 还在、实际点不动。没有卡片或卡 id 时才退回文字提示。
|
|
280
|
+
*/
|
|
281
|
+
#noteChoice(pending, message) {
|
|
282
|
+
const cardMessageId = pending.cardMessageId;
|
|
283
|
+
const question = pending.questions[0];
|
|
284
|
+
if (cardMessageId !== undefined && this.#options.patchCard !== undefined && question !== undefined) {
|
|
285
|
+
this.#options.logger?.info?.('卡片作答不合规,已重发卡片', message);
|
|
286
|
+
try {
|
|
287
|
+
const card = renderReminderCard({ reminderId: pending.id, no: pending.no, question, note: message });
|
|
288
|
+
void this.#options.patchCard(cardMessageId, card).catch(() => { });
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
catch {
|
|
292
|
+
// 卡片装不下就退回文字:提示不能因为体积发不出去。
|
|
293
|
+
}
|
|
294
|
+
}
|
|
277
295
|
this.#options.logger?.info?.('卡片作答不合规,已提示主人', message);
|
|
278
296
|
void this.#options.send(message).catch(() => { });
|
|
279
297
|
}
|
|
@@ -34,6 +34,9 @@ export function renderReminderCard(input) {
|
|
|
34
34
|
const instruction = question.multiSelect === true
|
|
35
35
|
? '多选:可以勾选多项,选好后点「提交」。'
|
|
36
36
|
: '单选:只能勾选一项,选好后点「提交」。';
|
|
37
|
+
if (input.note !== undefined && input.note !== '') {
|
|
38
|
+
elements.push({ tag: 'markdown', content: `_**${input.note}**_`, text_size: 'notation' });
|
|
39
|
+
}
|
|
37
40
|
elements.push({ tag: 'markdown', content: instruction, text_size: 'notation' }, {
|
|
38
41
|
tag: 'form',
|
|
39
42
|
name: 'ask_form',
|
package/lib/src/host/runtime.js
CHANGED
|
@@ -83,7 +83,9 @@ export class LarkRuntime {
|
|
|
83
83
|
status() {
|
|
84
84
|
const connection = this.#connection?.status() ?? { state: 'idle', since: Date.now(), reconnectAttempts: 0 };
|
|
85
85
|
return {
|
|
86
|
+
appId: this.#credentials === null ? null : this.#credentials.appId,
|
|
86
87
|
appIdTail: this.#credentials === null ? null : tailOf(this.#credentials.appId),
|
|
88
|
+
boundAt: this.#credentials?.boundAt ?? null,
|
|
87
89
|
domain: this.#credentials?.domain ?? this.#deps.config.domain,
|
|
88
90
|
enabled: this.#settings?.enabled ?? this.#deps.config.enabled,
|
|
89
91
|
superagent: this.#settings?.superagent ?? this.#deps.config.superagent,
|
|
@@ -198,7 +200,7 @@ export class LarkRuntime {
|
|
|
198
200
|
}
|
|
199
201
|
}
|
|
200
202
|
}
|
|
201
|
-
/** App ID
|
|
203
|
+
/** App ID 尾号:日志与错误信息用(面板显示完整 App ID)。 */
|
|
202
204
|
function tailOf(appId) {
|
|
203
205
|
return appId.length > 6 ? appId.slice(-6) : appId;
|
|
204
206
|
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 凭据存储与自检。
|
|
3
3
|
*
|
|
4
|
-
* 凭据只落本机状态文件(`0700` 目录、`0600`
|
|
5
|
-
*
|
|
4
|
+
* 凭据只落本机状态文件(`0700` 目录、`0600` 文件、原子写),**不进日志、不随包
|
|
5
|
+
* 发布**。面板可以显示完整 App ID 与绑定时间(App ID 不是密钥),App Secret 永远
|
|
6
|
+
* 不出这个边界。
|
|
6
7
|
*
|
|
7
8
|
* 自检走两条独立的最小请求:先换 `tenant_access_token`(验 app_id/app_secret),
|
|
8
9
|
* 再查机器人信息(验机器人能力是否开启)。两件事分开报错,面板才能给出
|
|
9
10
|
* 「密钥不对」和「机器人能力没开」两种不同的提示。
|
|
10
11
|
*/
|
|
12
|
+
import { stat } from 'node:fs/promises';
|
|
11
13
|
import { join } from 'node:path';
|
|
12
14
|
import { baseUrlOf } from "../lark/api.js";
|
|
13
15
|
import { readJsonIfPresent, writePrivateFile } from "./files.js";
|
|
@@ -16,9 +18,9 @@ const CREDENTIALS_FILE = 'credentials.json';
|
|
|
16
18
|
/** App ID 尾号长度:面板只显示这么多,够区分不同应用就够了。 */
|
|
17
19
|
const TAIL_LENGTH = 6;
|
|
18
20
|
/** 面板能看到的凭据摘要。 */
|
|
19
|
-
export function summarize(appId, domain) {
|
|
21
|
+
export function summarize(appId, domain, boundAt) {
|
|
20
22
|
const tail = appId.length > TAIL_LENGTH ? appId.slice(-TAIL_LENGTH) : appId;
|
|
21
|
-
return { appIdTail: tail, domain };
|
|
23
|
+
return { appId, appIdTail: tail, domain, ...(boundAt === undefined ? {} : { boundAt }) };
|
|
22
24
|
}
|
|
23
25
|
/** 收窄磁盘上的凭据:形状不对就当没配置。 */
|
|
24
26
|
function normalizeStored(raw) {
|
|
@@ -30,15 +32,20 @@ function normalizeStored(raw) {
|
|
|
30
32
|
const domain = input.domain === 'lark' ? 'lark' : 'feishu';
|
|
31
33
|
if (appId === '' || appSecret === '')
|
|
32
34
|
return undefined;
|
|
33
|
-
|
|
35
|
+
const boundAt = typeof input.boundAt === 'number' && Number.isFinite(input.boundAt) && input.boundAt > 0
|
|
36
|
+
? input.boundAt
|
|
37
|
+
: undefined;
|
|
38
|
+
return { appId, appSecret, domain, ...(boundAt === undefined ? {} : { boundAt }) };
|
|
34
39
|
}
|
|
35
40
|
export class CredentialStore {
|
|
36
41
|
#path;
|
|
37
42
|
#logger;
|
|
43
|
+
#now;
|
|
38
44
|
#cached;
|
|
39
45
|
constructor(options) {
|
|
40
46
|
this.#path = join(options.dataDir, CREDENTIALS_FILE);
|
|
41
47
|
this.#logger = options.logger ?? {};
|
|
48
|
+
this.#now = options.now ?? Date.now;
|
|
42
49
|
}
|
|
43
50
|
/** 读凭据;没有或损坏返回 null。 */
|
|
44
51
|
async load() {
|
|
@@ -49,9 +56,25 @@ export class CredentialStore {
|
|
|
49
56
|
if (raw !== undefined && parsed === undefined) {
|
|
50
57
|
this.#logger.warn?.('凭据文件存在但内容不完整,按未配置处理');
|
|
51
58
|
}
|
|
52
|
-
this.#cached = parsed
|
|
59
|
+
this.#cached = parsed === undefined ? null : await this.#withFileTime(parsed);
|
|
53
60
|
return this.#cached;
|
|
54
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* 老凭据没有绑定时间:用文件修改时间兜底(≈ 上次保存凭据的时间)。
|
|
64
|
+
*
|
|
65
|
+
* 只补在内存里,不写盘——写盘会把「猜出来的时间」固化成事实。
|
|
66
|
+
*/
|
|
67
|
+
async #withFileTime(app) {
|
|
68
|
+
if (app.boundAt !== undefined)
|
|
69
|
+
return app;
|
|
70
|
+
try {
|
|
71
|
+
const info = await stat(this.#path);
|
|
72
|
+
return { ...app, boundAt: Math.round(info.mtimeMs) };
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return app;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
55
78
|
/** 覆盖保存;返回可以展示的摘要。 */
|
|
56
79
|
async save(input) {
|
|
57
80
|
const appId = input.appId.trim();
|
|
@@ -60,10 +83,13 @@ export class CredentialStore {
|
|
|
60
83
|
throw new Error('App ID 不能为空');
|
|
61
84
|
if (appSecret === '')
|
|
62
85
|
throw new Error('App Secret 不能为空');
|
|
63
|
-
|
|
86
|
+
// 绑定时间跟着 App ID 走:同一个应用重复保存(哪怕换了 Secret)保留首次时间。
|
|
87
|
+
const previous = await this.load();
|
|
88
|
+
const boundAt = previous !== null && previous.appId === appId && previous.boundAt !== undefined ? previous.boundAt : this.#now();
|
|
89
|
+
const payload = { appId, appSecret, domain: input.domain, boundAt };
|
|
64
90
|
await writePrivateFile(this.#path, `${JSON.stringify(payload, null, 2)}\n`);
|
|
65
91
|
this.#cached = payload;
|
|
66
|
-
return summarize(appId, input.domain);
|
|
92
|
+
return summarize(appId, input.domain, boundAt);
|
|
67
93
|
}
|
|
68
94
|
/** 清空凭据(卸载应用或换应用时用)。 */
|
|
69
95
|
async clear() {
|
|
@@ -73,7 +99,7 @@ export class CredentialStore {
|
|
|
73
99
|
/** 已配置时的摘要;未配置返回 null。 */
|
|
74
100
|
async summary() {
|
|
75
101
|
const app = await this.load();
|
|
76
|
-
return app ? summarize(app.appId, app.domain) : null;
|
|
102
|
+
return app ? summarize(app.appId, app.domain, app.boundAt) : null;
|
|
77
103
|
}
|
|
78
104
|
}
|
|
79
105
|
/**
|
package/locale/en.json
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
"panel.refresh": "Refresh",
|
|
6
6
|
"panel.retry": "Retry",
|
|
7
7
|
"status.title": "Connection",
|
|
8
|
-
"status.connection": "Long connection",
|
|
9
8
|
"status.appId": "App ID",
|
|
10
9
|
"status.domain": "Platform",
|
|
11
10
|
"status.enabled": "Connect Lark",
|
|
@@ -22,7 +21,8 @@
|
|
|
22
21
|
"state.failed": "Failed",
|
|
23
22
|
"credentials.title": "App credentials",
|
|
24
23
|
"credentials.hint": "From the Lark developer console. Stored locally; the secret is never echoed.",
|
|
25
|
-
"credentials.configured": "
|
|
24
|
+
"credentials.configured": "Bound to {appId} · {domain}",
|
|
25
|
+
"credentials.boundAt": "Bound since {boundAt}",
|
|
26
26
|
"credentials.manual": "Enter credentials manually",
|
|
27
27
|
"credentials.appId": "App ID",
|
|
28
28
|
"credentials.appSecret": "App Secret",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"credentials.probing": "Testing…",
|
|
37
37
|
"credentials.clear": "Clear credentials",
|
|
38
38
|
"credentials.clearTitle": "Clear credentials?",
|
|
39
|
-
"credentials.clearHint": "This removes the credentials for
|
|
39
|
+
"credentials.clearHint": "This removes the credentials for {appId} (App ID and App Secret).",
|
|
40
40
|
"credentials.clearWarning": "The long connection closes immediately; reconnecting requires entering them again.",
|
|
41
41
|
"credentials.clearConfirm": "Clear",
|
|
42
42
|
"credentials.cleared": "Credentials cleared",
|
package/locale/zh.json
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
"panel.refresh": "刷新",
|
|
6
6
|
"panel.retry": "重试",
|
|
7
7
|
"status.title": "连接状态",
|
|
8
|
-
"status.connection": "长连接",
|
|
9
8
|
"status.appId": "App ID",
|
|
10
9
|
"status.domain": "平台",
|
|
11
10
|
"status.enabled": "接入飞书",
|
|
@@ -22,7 +21,8 @@
|
|
|
22
21
|
"state.failed": "连接失败",
|
|
23
22
|
"credentials.title": "应用凭据",
|
|
24
23
|
"credentials.hint": "在飞书开放平台「凭证与基础信息」里获取。只保存在本机,面板不会回显 Secret。",
|
|
25
|
-
"credentials.configured": "
|
|
24
|
+
"credentials.configured": "已绑定 {appId} · {domain}",
|
|
25
|
+
"credentials.boundAt": "绑定于 {boundAt}",
|
|
26
26
|
"credentials.manual": "手动填写凭据",
|
|
27
27
|
"credentials.appId": "App ID",
|
|
28
28
|
"credentials.appSecret": "App Secret",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"credentials.probing": "正在自检…",
|
|
37
37
|
"credentials.clear": "清除凭据",
|
|
38
38
|
"credentials.clearTitle": "清除凭据?",
|
|
39
|
-
"credentials.clearHint": "
|
|
39
|
+
"credentials.clearHint": "将清除 {appId} 的应用凭据(App ID 与 App Secret)。",
|
|
40
40
|
"credentials.clearWarning": "清除后长连接立即断开,重新接入需要再填一次凭据。",
|
|
41
41
|
"credentials.clearConfirm": "清除",
|
|
42
42
|
"credentials.cleared": "凭据已清除",
|