dsh-feishu-lark-notify 0.27.0 → 0.28.1
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 +18 -1
- package/README.zh.md +18 -1
- package/docs/config-reference.md +2 -0
- package/lib/config.js +3 -0
- package/lib/env.js +2 -0
- package/lib/index.js +50 -6
- package/lib/session-router.js +5 -0
- package/package.json +1 -1
- package/scripts/gen-docs.mjs +1 -0
package/README.md
CHANGED
|
@@ -197,6 +197,23 @@ is not stolen by `日报`; order is exact → startsWith → includes.
|
|
|
197
197
|
- Several matches → the candidates are listed, you refine it; **it never guesses**
|
|
198
198
|
- Don't want to remember titles → `@最近 内容` (also `@上一个` / `@上次` / `@last`) goes to whatever received last
|
|
199
199
|
|
|
200
|
+
### Sticky target: stop repeating the number
|
|
201
|
+
|
|
202
|
+
Once you have named a target with @title or a number, **plain messages keep going there**:
|
|
203
|
+
|
|
204
|
+
`
|
|
205
|
+
@前端日报 帮我跑下构建 → remembers 前端日报
|
|
206
|
+
再跑一下测试 → still 前端日报
|
|
207
|
+
2 换个会话做事 → switches to #2 and sticks to it
|
|
208
|
+
放开 → releases it
|
|
209
|
+
`
|
|
210
|
+
|
|
211
|
+
| Detail | Notes |
|
|
212
|
+
|---|---|
|
|
213
|
+
| Basis | The session that last received a command (lastRoutedSessionId) |
|
|
214
|
+
| Expiry | If it is closed or reclaimed the route falls back automatically |
|
|
215
|
+
| Disable | inbound.stickyTarget: false (env DSH_NOTIFY_INBOUND_STICKY=false) |
|
|
216
|
+
|
|
200
217
|
### Control: stop and status
|
|
201
218
|
|
|
202
219
|
Feishu is not only an input channel — it can intervene:
|
|
@@ -261,7 +278,7 @@ The bot replies with **non-archived** sessions, running ones first:
|
|
|
261
278
|
|
|
262
279
|
| Case | Behaviour |
|
|
263
280
|
|---|---|
|
|
264
|
-
| No number | Goes to the session
|
|
281
|
+
| No number | Goes to **the session you last targeted explicitly** (sticky); with no history it falls back to the page selection / most recent root |
|
|
265
282
|
| Number points at a **dormant** session | Woken with `agents.resume` (plus the model that session last used), then delivered |
|
|
266
283
|
| Wake-up fails | The host's original error is echoed back — nothing is dropped silently |
|
|
267
284
|
| More than 10 minutes since `列表` | Numbers expire; send `列表` again. They are pinned to the order you received, so re-listing beats misdelivering |
|
package/README.zh.md
CHANGED
|
@@ -193,6 +193,23 @@ DSH 里同时开着一堆会话时,飞书里发一句话默认只交给「当
|
|
|
193
193
|
- 不想记标题 → `@最近 内容`(也认 `@上一个` / `@上次` / `@last`)交给**上次那个**会话
|
|
194
194
|
- 只 `@` 了标题没写内容 → 提示补上内容
|
|
195
195
|
|
|
196
|
+
### 粘性目标:不用每次都带编号
|
|
197
|
+
|
|
198
|
+
一旦你用 @标题 或编号指定过目标,**之后不带任何前缀的普通消息继续发给它**:
|
|
199
|
+
|
|
200
|
+
`
|
|
201
|
+
@前端日报 帮我跑下构建 → 记住「前端日报」
|
|
202
|
+
再跑一下测试 → 还是「前端日报」,不用再写一遍
|
|
203
|
+
2 换个会话做事 → 切到编号 2,并粘住它
|
|
204
|
+
放开 → 解除粘性,回到「配置页选定 / 最近根会话」
|
|
205
|
+
`
|
|
206
|
+
|
|
207
|
+
| 说明 | 细节 |
|
|
208
|
+
|---|---|
|
|
209
|
+
| 依据 | 上次真的投递成功的会话(lastRoutedSessionId) |
|
|
210
|
+
| 失效 | 那个会话被关掉/回收后自动退回,不会投进死目标 |
|
|
211
|
+
| 关闭 | inbound.stickyTarget: false(或环境变量 DSH_NOTIFY_INBOUND_STICKY=false) |
|
|
212
|
+
|
|
196
213
|
### 控制:停止 / 状态
|
|
197
214
|
|
|
198
215
|
飞书不只是能「下指令」,也能**插手**:
|
|
@@ -293,7 +310,7 @@ DSH 里同时开着一堆会话时,飞书里发一句话默认只交给「当
|
|
|
293
310
|
|
|
294
311
|
| 情况 | 行为 |
|
|
295
312
|
|---|---|
|
|
296
|
-
| 不带编号 |
|
|
313
|
+
| 不带编号 | 交给**上次你显式指定的会话**(粘性目标);没有历史时退回配置页选定的 / 最近的根会话 |
|
|
297
314
|
| 编号指向**休眠**会话 | 自动唤醒(`agents.resume` + 该会话上次用的模型),唤醒后照常投递 |
|
|
298
315
|
| 唤醒失败 | 回执里带上**宿主的原始错误**,不会静默丢消息 |
|
|
299
316
|
| 距上次「列表」超过 10 分钟 | 编号失效,提示重新发「列表」——编号绑定的是发清单那一刻的顺序,过期重发比投错安全 |
|
package/docs/config-reference.md
CHANGED
|
@@ -143,6 +143,7 @@
|
|
|
143
143
|
| `commandPrefix` | `#dsh` | 指令前缀,默认 `#dsh` | `DSH_NOTIFY_INBOUND_PREFIX` |
|
|
144
144
|
| `maxPerMinute` | `6` | 每个会话独立的 60 秒窗口;`0` = 不限制,最大 600 | `DSH_NOTIFY_INBOUND_MAX_PER_MINUTE` |
|
|
145
145
|
| `sessionId` | `''` | 指令交给哪个会话;空 = 最近一个根会话 | `DSH_NOTIFY_INBOUND_SESSION_ID` |
|
|
146
|
+
| `stickyTarget` | `true` | 普通消息发给「上次显式指定的会话」(`@标题` / 编号 / 新建);关掉则退回「最近的根会话」 | `DSH_NOTIFY_INBOUND_STICKY` |
|
|
146
147
|
| `requireMentionInGroups` | `true` | 群里要 @ 机器人才响应(私聊永远不需要);关掉则群里任何消息都处理 | `DSH_NOTIFY_INBOUND_REQUIRE_MENTION` |
|
|
147
148
|
|
|
148
149
|
## 在飞书里直接批准(`interactive`)
|
|
@@ -250,6 +251,7 @@ content:
|
|
|
250
251
|
| `DSH_NOTIFY_INBOUND_MAX_PER_MINUTE` | `inbound.maxPerMinute` | 数字 |
|
|
251
252
|
| `DSH_NOTIFY_INBOUND_SESSION_ID` | `inbound.sessionId` | string |
|
|
252
253
|
| `DSH_NOTIFY_INBOUND_REQUIRE_MENTION` | `inbound.requireMentionInGroups` | bool |
|
|
254
|
+
| `DSH_NOTIFY_INBOUND_STICKY` | `inbound.stickyTarget` | bool |
|
|
253
255
|
| `DSH_NOTIFY_INTERACTIVE_ENABLED` | `interactive.enabled` | bool |
|
|
254
256
|
| `DSH_NOTIFY_INTERACTIVE_TIMEOUT_MS` | `interactive.timeoutMs` | 数字 |
|
|
255
257
|
| `DSH_NOTIFY_INTERACTIVE_ALLOW_USERS` | `interactive.allowFromUsers` | 列表 |
|
package/lib/config.js
CHANGED
|
@@ -122,6 +122,8 @@ export const DEFAULTS = {
|
|
|
122
122
|
commandPrefix: '#dsh',
|
|
123
123
|
maxPerMinute: 6,
|
|
124
124
|
sessionId: '',
|
|
125
|
+
// 普通消息发给「上次显式指定的会话」;关掉则退回「最近的根会话」
|
|
126
|
+
stickyTarget: true,
|
|
125
127
|
// 群里要 @ 机器人才响应(私聊不需要)
|
|
126
128
|
requireMentionInGroups: true,
|
|
127
129
|
},
|
|
@@ -278,6 +280,7 @@ export function resolveInbound(raw) {
|
|
|
278
280
|
sessionId: typeof source.sessionId === 'string' ? source.sessionId.trim() : '',
|
|
279
281
|
// 群里必须 @ 机器人才响应(私聊永远不需要);默认开,避免在群里抢话
|
|
280
282
|
requireMentionInGroups: source.requireMentionInGroups !== false,
|
|
283
|
+
stickyTarget: source.stickyTarget !== false,
|
|
281
284
|
}
|
|
282
285
|
}
|
|
283
286
|
|
package/lib/env.js
CHANGED
|
@@ -89,6 +89,8 @@ export const ENV_BINDINGS = [
|
|
|
89
89
|
{ name: 'DSH_NOTIFY_INBOUND_SESSION_ID', inbound: 'sessionId', kind: 'string' },
|
|
90
90
|
// 群里必须 @ 机器人才响应;私聊不受影响
|
|
91
91
|
{ name: 'DSH_NOTIFY_INBOUND_REQUIRE_MENTION', inbound: 'requireMentionInGroups', kind: 'bool' },
|
|
92
|
+
// 普通消息发给「上次显式指定的会话」;false 则退回「最近的根会话」
|
|
93
|
+
{ name: 'DSH_NOTIFY_INBOUND_STICKY', inbound: 'stickyTarget', kind: 'bool' },
|
|
92
94
|
|
|
93
95
|
// 「在飞书里直接批准」:把工具审批发成带按钮的卡片
|
|
94
96
|
{ name: 'DSH_NOTIFY_INTERACTIVE_ENABLED', interactive: 'enabled', kind: 'bool' },
|
package/lib/index.js
CHANGED
|
@@ -37,7 +37,7 @@ import { startWsInbound } from './inbound-ws.js'
|
|
|
37
37
|
export const name = 'feishu-notify'
|
|
38
38
|
|
|
39
39
|
/** 版本号(与 package.json 保持一致,单测会校验)。 */
|
|
40
|
-
export const VERSION = '0.
|
|
40
|
+
export const VERSION = '0.28.1'
|
|
41
41
|
|
|
42
42
|
/** 内存日志上限。 */
|
|
43
43
|
const LOG_LIMIT = 200
|
|
@@ -1508,11 +1508,37 @@ export function apply(ctx, rawConfig) {
|
|
|
1508
1508
|
//#endregion
|
|
1509
1509
|
|
|
1510
1510
|
/** 用已配置的 webhook 渠道回一句(可选,失败不影响主流程)。 */
|
|
1511
|
-
|
|
1511
|
+
/**
|
|
1512
|
+
* 给用户回一句「收到了」。
|
|
1513
|
+
*
|
|
1514
|
+
* 之前的实现只在 **webhook 模式**下发回执(`webhooks.length === 0` 直接 return),
|
|
1515
|
+
* 于是用应用机器人的场景(绝大多数人)**一条回执都没有**——用户以为消息没被收到。
|
|
1516
|
+
* 现在应用机器人走 `sendRaw` 发文本,webhook 模式保持原样。
|
|
1517
|
+
* @param text - 回执正文。
|
|
1518
|
+
* @param chatId - 发到哪个会话;省略则用第一个推送目标。
|
|
1519
|
+
*/
|
|
1520
|
+
async function acknowledge(text, chatId) {
|
|
1512
1521
|
const channel = config.channels.feishu
|
|
1513
|
-
if (channel?.enabled !== true
|
|
1514
|
-
const
|
|
1522
|
+
if (channel?.enabled !== true) return
|
|
1523
|
+
const target = typeof chatId === 'string' && chatId !== ''
|
|
1524
|
+
? chatId
|
|
1525
|
+
: (Array.isArray(channel.receiveChatIds) && channel.receiveChatIds.length > 0 ? channel.receiveChatIds[0] : '')
|
|
1515
1526
|
try {
|
|
1527
|
+
if (channel.useAppBot === true && channel.appId !== '' && channel.appSecret !== '') {
|
|
1528
|
+
const results = await feishuChannel.sendRaw(
|
|
1529
|
+
channel,
|
|
1530
|
+
{ msg_type: 'text', content: { text } },
|
|
1531
|
+
{ chatIds: target === '' ? channel.receiveChatIds : [target], timeoutMs: config.timeoutMs },
|
|
1532
|
+
)
|
|
1533
|
+
if (results.some((item) => item.ok)) {
|
|
1534
|
+
log(`回执已发(${target || '默认目标'}):${clip(text, 40)}`)
|
|
1535
|
+
} else {
|
|
1536
|
+
log(`回执发送失败: ${results.map((item) => item.error).filter(Boolean).join('; ')}`)
|
|
1537
|
+
}
|
|
1538
|
+
return
|
|
1539
|
+
}
|
|
1540
|
+
if (!Array.isArray(channel.webhooks) || channel.webhooks.length === 0) return
|
|
1541
|
+
const summary = { title: '📥 DSH 收到指令', head: [text], body: '', footer: '', color: 'blue', plain: text }
|
|
1516
1542
|
await feishuChannel.deliver(channel, summary, { style: 'text', timeoutMs: config.timeoutMs })
|
|
1517
1543
|
} catch (error) {
|
|
1518
1544
|
log(`回执发送失败: ${error?.message ?? error}`)
|
|
@@ -1633,7 +1659,14 @@ export function apply(ctx, rawConfig) {
|
|
|
1633
1659
|
function resolveTargetAgent() {
|
|
1634
1660
|
const agents = ctx.get('agents')
|
|
1635
1661
|
if (agents === undefined) return undefined
|
|
1662
|
+
// ① 粘性:上次显式指定的会话(@标题 / 编号 / 新建)还活着,就用它
|
|
1663
|
+
if (config.inbound.stickyTarget !== false && lastRoutedSessionId !== '') {
|
|
1664
|
+
const sticky = typeof agents.get === 'function' ? agents.get(lastRoutedSessionId) : undefined
|
|
1665
|
+
if (sticky !== undefined && sticky !== null) return sticky
|
|
1666
|
+
}
|
|
1667
|
+
// ② 配置页固定
|
|
1636
1668
|
if (config.inbound.sessionId !== '') return agents.get(config.inbound.sessionId)
|
|
1669
|
+
// ③ 最近的根会话(原行为)
|
|
1637
1670
|
const roots = typeof agents.roots === 'function' ? agents.roots() : []
|
|
1638
1671
|
return roots[roots.length - 1]
|
|
1639
1672
|
}
|
|
@@ -1662,6 +1695,7 @@ export function apply(ctx, rawConfig) {
|
|
|
1662
1695
|
lastRoutedSessionId = agent.id
|
|
1663
1696
|
lastRoutedAt = Date.now()
|
|
1664
1697
|
log(`${meta.via ?? 'inbound'}:已提交指令到会话 ${agent.id}(来自 ${meta.chatId}/${meta.userId})`)
|
|
1698
|
+
return { id: agent.id, label: sessionLabel(agent) }
|
|
1665
1699
|
}
|
|
1666
1700
|
|
|
1667
1701
|
/** 机器人自己的身份(群里判断有没有 @ 我),取一次就缓存。 */
|
|
@@ -2079,6 +2113,15 @@ export function apply(ctx, rawConfig) {
|
|
|
2079
2113
|
* @returns 结构化结果。
|
|
2080
2114
|
*/
|
|
2081
2115
|
async function applyControl({ control, target, message, via }) {
|
|
2116
|
+
if (control.kind === 'release') {
|
|
2117
|
+
const previous = lastRoutedSessionId
|
|
2118
|
+
lastRoutedSessionId = ''
|
|
2119
|
+
log(`[${via}] 控制:已解除粘性目标(原 ${previous || '无'})`)
|
|
2120
|
+
void replyToChat(message.chatId, previous === ''
|
|
2121
|
+
? '本来就没有固定目标。'
|
|
2122
|
+
: '🔓 已解除,之后普通消息回到「配置页选定 / 最近的根会话」。')
|
|
2123
|
+
return { ok: true, control: 'release' }
|
|
2124
|
+
}
|
|
2082
2125
|
if (control.kind === 'status') {
|
|
2083
2126
|
const text = formatStatus(rosterSessions(), {
|
|
2084
2127
|
currentId: config.inbound.sessionId !== '' ? config.inbound.sessionId : lastRoutedSessionId,
|
|
@@ -2337,8 +2380,9 @@ export function apply(ctx, rawConfig) {
|
|
|
2337
2380
|
}
|
|
2338
2381
|
|
|
2339
2382
|
try {
|
|
2340
|
-
await enqueue(command, { chatId: message.chatId, userId: message.userId, via })
|
|
2341
|
-
|
|
2383
|
+
const delivered = await enqueue(command, { chatId: message.chatId, userId: message.userId, via })
|
|
2384
|
+
const targetName = delivered?.label || (delivered?.id ? delivered.id.slice(-6) : '会话')
|
|
2385
|
+
void acknowledge(`✅ 已收到,交给「${targetName}」:${clip(command, 300)}`, message.chatId)
|
|
2342
2386
|
return { ok: true, accepted: true }
|
|
2343
2387
|
} catch (error) {
|
|
2344
2388
|
log(`[${via}] 提交失败 ${error?.message ?? error}`)
|
package/lib/session-router.js
CHANGED
|
@@ -29,6 +29,9 @@ const STOP_COMMANDS = new Set(['停止', '停', '中断', '打住', 'stop', 'can
|
|
|
29
29
|
/** 控制命令:看状态。 */
|
|
30
30
|
const STATUS_COMMANDS = new Set(['状态', '进度', '在干嘛', 'status', 'state'])
|
|
31
31
|
|
|
32
|
+
/** 控制命令:解除粘性目标。 */
|
|
33
|
+
const RELEASE_COMMANDS = new Set(['放开', '取消默认', '不粘了', 'release'])
|
|
34
|
+
|
|
32
35
|
/** 新建会话的命令前缀词。 */
|
|
33
36
|
const CREATE_WORDS = ['新建', '新会话', '开一个', '开个', 'new', 'create']
|
|
34
37
|
|
|
@@ -108,6 +111,7 @@ export function parseControl(text) {
|
|
|
108
111
|
if (value === '') return undefined
|
|
109
112
|
if (STOP_COMMANDS.has(value)) return { kind: 'stop' }
|
|
110
113
|
if (STATUS_COMMANDS.has(value)) return { kind: 'status' }
|
|
114
|
+
if (RELEASE_COMMANDS.has(value)) return { kind: 'release' }
|
|
111
115
|
return undefined
|
|
112
116
|
}
|
|
113
117
|
|
|
@@ -256,6 +260,7 @@ export function formatHelp({ maxPerMinute, prefix } = {}) {
|
|
|
256
260
|
'· 发「2 帮我跑测试」→ 只交给第 2 个会话(编号 10 分钟内有效)',
|
|
257
261
|
'· 发「新建 前端日报」→ 开一个新会话;「新建 标题 内容」→ 建完直接投第一条指令',
|
|
258
262
|
'· 发「新建@灵畿 标题 内容」→ 建在「灵畿」那个工作区的目录里',
|
|
263
|
+
'· 不带编号 → 继续发给「上次你指定的会话」;发「放开」解除',
|
|
259
264
|
'· 发「状态」→ 看各会话在跑还是空闲;「停止」→ 中断当前这一轮(也能 @标题 停止)',
|
|
260
265
|
'',
|
|
261
266
|
'【审批】',
|
package/package.json
CHANGED
package/scripts/gen-docs.mjs
CHANGED
|
@@ -61,6 +61,7 @@ const INBOUND_NOTES = {
|
|
|
61
61
|
maxPerMinute: '每个会话独立的 60 秒窗口;`0` = 不限制,最大 600',
|
|
62
62
|
sessionId: '指令交给哪个会话;空 = 最近一个根会话',
|
|
63
63
|
requireMentionInGroups: '群里要 @ 机器人才响应(私聊永远不需要);关掉则群里任何消息都处理',
|
|
64
|
+
stickyTarget: '普通消息发给「上次显式指定的会话」(`@标题` / 编号 / 新建);关掉则退回「最近的根会话」',
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
/** 「在飞书里直接批准」字段的中文说明。 */
|