dsh-line-bot 0.10.5 → 0.10.7
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/CHANGELOG.md +10 -0
- package/lib/host.mjs +4 -3
- package/lib/webhook-server.mjs +30 -11
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## 0.10.7
|
|
2
|
+
|
|
3
|
+
- 修正自訂參考音無法上傳:`/api/line-bot/action` 的請求上限從 2MB 提高到 32MB。20MB 音檔轉成 data URL 後約 27MB,先前會在面板顯示「上傳失敗:請求內容過大」。
|
|
4
|
+
|
|
5
|
+
## 0.10.6
|
|
6
|
+
|
|
7
|
+
- 連傳訊息:webhook 佇列改成「停手 1.8 秒才開始處理」,每收到新的一則就重新計時;快速連傳的兩三則會一起進同一輪,不會因為第一則回得快就變成兩次獨立回覆。
|
|
8
|
+
- 合併提示改為「使用者連續傳了 N 則訊息」,不再假設一定是在上一輪處理中補傳。
|
|
9
|
+
- 每次收到 webhook 事件都會記錄合併佇列狀態,方便追查「第二則沒送達」與「有送達但沒合併」的差異。
|
|
10
|
+
|
|
1
11
|
## 0.10.5
|
|
2
12
|
|
|
3
13
|
- 合併連續訊息:模型還在處理上一則時,使用者又補了下一句,會先排進佇列;這一輪結束後把補充內容合成同一段一起回應,不再每句各回一次。
|
package/lib/host.mjs
CHANGED
|
@@ -51,7 +51,7 @@ const { createVision } = visionMod
|
|
|
51
51
|
const { createTts } = ttsMod
|
|
52
52
|
const { chunkText, clip, inQuietWindow, jsonFail, jsonOk, maskSecret, readJsonBody, safeArray, sleep, readJsonSafe } = utilMod
|
|
53
53
|
|
|
54
|
-
export const VERSION = '0.10.
|
|
54
|
+
export const VERSION = '0.10.7'
|
|
55
55
|
|
|
56
56
|
// 環境變數提供的 Cloudflare API Token(方便用 shell 注入、不用把 token 寫進設定檔)。
|
|
57
57
|
// 設定檔裡的 token 優先;兩者都沒有時才用環境變數。
|
|
@@ -1715,7 +1715,7 @@ export async function create({ ctx, config: pluginConfig, logger: upstream }) {
|
|
|
1715
1715
|
message: {
|
|
1716
1716
|
...last.message,
|
|
1717
1717
|
type: 'text',
|
|
1718
|
-
text:
|
|
1718
|
+
text: `(使用者連續傳了 ${texts.length} 則訊息;請把下面這些話視為同一段,一起回應,不要逐句分開回。)\n${texts.join('\n')}`,
|
|
1719
1719
|
},
|
|
1720
1720
|
__mergedCount: texts.length,
|
|
1721
1721
|
}
|
|
@@ -3179,7 +3179,8 @@ export async function create({ ctx, config: pluginConfig, logger: upstream }) {
|
|
|
3179
3179
|
return
|
|
3180
3180
|
}
|
|
3181
3181
|
if (req.method === 'POST' && sub === '/action') {
|
|
3182
|
-
|
|
3182
|
+
// 參考音以 data URL 上傳,20MB 音檔轉成 base64 後約 27MB;預設 2MB 會讓上傳直接失敗。
|
|
3183
|
+
const body = await readJsonBody(req, 32 * 1024 * 1024)
|
|
3183
3184
|
const result = await runAction(String(body.action || ''), body.payload || {})
|
|
3184
3185
|
jsonOk(res, { action: body.action, result, status: await buildStatus() })
|
|
3185
3186
|
return
|
package/lib/webhook-server.mjs
CHANGED
|
@@ -32,6 +32,20 @@ export function createWebhookServer({ getConfig, logger, dispatch, getMedia, get
|
|
|
32
32
|
for (const [id, at] of dedupe) if (at < cutoff) dedupe.delete(id)
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
// 先等使用者停手 1.8 秒再開始處理:快速連傳時,兩三則會一起進同一輪;
|
|
36
|
+
// 每收到新的一則就重新計時,避免第一則先被處理、第二則變成獨立回覆。
|
|
37
|
+
const COALESCE_MS = 1800
|
|
38
|
+
|
|
39
|
+
function scheduleDrain(key, queue, delay = COALESCE_MS) {
|
|
40
|
+
if (queue.timer) return
|
|
41
|
+
queue.timer = setTimeout(() => {
|
|
42
|
+
queue.timer = null
|
|
43
|
+
queue.running = true
|
|
44
|
+
void drain(key, queue)
|
|
45
|
+
}, delay)
|
|
46
|
+
queue.timer.unref?.()
|
|
47
|
+
}
|
|
48
|
+
|
|
35
49
|
function enqueue(event) {
|
|
36
50
|
const id = event?.webhookEventId
|
|
37
51
|
if (id) {
|
|
@@ -45,26 +59,32 @@ export function createWebhookServer({ getConfig, logger, dispatch, getMedia, get
|
|
|
45
59
|
const key = event?.source?.userId || event?.source?.groupId || event?.source?.roomId || 'unknown'
|
|
46
60
|
let queue = queues.get(key)
|
|
47
61
|
if (!queue) {
|
|
48
|
-
queue = { pending: [], running: false }
|
|
62
|
+
queue = { pending: [], running: false, timer: null }
|
|
49
63
|
queues.set(key, queue)
|
|
50
64
|
}
|
|
51
65
|
queue.pending.push(event)
|
|
66
|
+
if (queue.timer) {
|
|
67
|
+
clearTimeout(queue.timer)
|
|
68
|
+
queue.timer = null
|
|
69
|
+
logger?.info?.(`${key} 先收進合併佇列(目前 ${queue.pending.length} 則)`)
|
|
70
|
+
scheduleDrain(key, queue)
|
|
71
|
+
return
|
|
72
|
+
}
|
|
52
73
|
if (queue.running) {
|
|
53
|
-
logger?.info?.(`${key}
|
|
74
|
+
logger?.info?.(`${key} 先收進合併佇列(目前 ${queue.pending.length} 則)`)
|
|
54
75
|
return
|
|
55
76
|
}
|
|
56
|
-
queue
|
|
57
|
-
void drain(key, queue)
|
|
77
|
+
scheduleDrain(key, queue)
|
|
58
78
|
}
|
|
59
79
|
|
|
60
80
|
async function drain(key, queue) {
|
|
61
81
|
try {
|
|
62
82
|
while (queue.pending.length > 0) {
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
logger?.info?.(`合併 ${batch.length}
|
|
83
|
+
const batch = queue.pending.splice(0)
|
|
84
|
+
if (batch.length === 1) {
|
|
85
|
+
await dispatch(batch[0])
|
|
86
|
+
} else {
|
|
87
|
+
logger?.info?.(`合併 ${batch.length} 則連續訊息(${key})`)
|
|
68
88
|
await dispatch({ type: 'message_batch', batch })
|
|
69
89
|
}
|
|
70
90
|
}
|
|
@@ -74,8 +94,7 @@ export function createWebhookServer({ getConfig, logger, dispatch, getMedia, get
|
|
|
74
94
|
} finally {
|
|
75
95
|
queue.running = false
|
|
76
96
|
if (queue.pending.length > 0) {
|
|
77
|
-
queue
|
|
78
|
-
void drain(key, queue)
|
|
97
|
+
scheduleDrain(key, queue, 150)
|
|
79
98
|
} else {
|
|
80
99
|
queues.delete(key)
|
|
81
100
|
}
|