@mindlink-ai/dsh-wechat-bot 1.0.0 → 1.3.0
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 +84 -10
- package/bridge/relay.js +139 -0
- package/client.js +261 -118
- package/index.js +542 -58
- package/package.json +68 -42
package/client.js
CHANGED
|
@@ -9,7 +9,7 @@ window.__ModuleLoader__.load({
|
|
|
9
9
|
factory(require) {
|
|
10
10
|
const React = require('react')
|
|
11
11
|
const h = React.createElement
|
|
12
|
-
const { useCallback, useEffect,
|
|
12
|
+
const { useCallback, useEffect, useState } = React
|
|
13
13
|
|
|
14
14
|
const MUTED = 'var(--dsw-alias-text-secondary, #6b7280)'
|
|
15
15
|
const TEXT = 'var(--dsw-alias-text-primary, #111827)'
|
|
@@ -130,6 +130,8 @@ window.__ModuleLoader__.load({
|
|
|
130
130
|
const [notice, setNotice] = useState('')
|
|
131
131
|
const [testText, setTestText] = useState('这是一条来自 DSH 微信 bot 的测试消息')
|
|
132
132
|
const [copied, setCopied] = useState(false)
|
|
133
|
+
const [failures, setFailures] = useState([])
|
|
134
|
+
const [failuresError, setFailuresError] = useState('')
|
|
133
135
|
|
|
134
136
|
const refresh = useCallback(async () => {
|
|
135
137
|
try {
|
|
@@ -141,6 +143,17 @@ window.__ModuleLoader__.load({
|
|
|
141
143
|
}
|
|
142
144
|
}, [])
|
|
143
145
|
|
|
146
|
+
// 失败记录单独拉取:单条内容可达数 KB,不塞进 2s 轮询的状态里
|
|
147
|
+
const loadFailures = useCallback(async () => {
|
|
148
|
+
try {
|
|
149
|
+
const value = await get('/wechat-bot/failures')
|
|
150
|
+
setFailures(Array.isArray(value?.items) ? value.items : [])
|
|
151
|
+
setFailuresError('')
|
|
152
|
+
} catch (cause) {
|
|
153
|
+
setFailuresError(String(cause?.message || cause))
|
|
154
|
+
}
|
|
155
|
+
}, [])
|
|
156
|
+
|
|
144
157
|
useEffect(() => {
|
|
145
158
|
let alive = true
|
|
146
159
|
const tick = () => {
|
|
@@ -154,6 +167,19 @@ window.__ModuleLoader__.load({
|
|
|
154
167
|
}
|
|
155
168
|
}, [refresh])
|
|
156
169
|
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
let alive = true
|
|
172
|
+
const tick = () => {
|
|
173
|
+
if (alive) loadFailures()
|
|
174
|
+
}
|
|
175
|
+
tick()
|
|
176
|
+
const timer = setInterval(tick, 10000)
|
|
177
|
+
return () => {
|
|
178
|
+
alive = false
|
|
179
|
+
clearInterval(timer)
|
|
180
|
+
}
|
|
181
|
+
}, [loadFailures])
|
|
182
|
+
|
|
157
183
|
const act = (name, fn) => async () => {
|
|
158
184
|
setBusy(name)
|
|
159
185
|
setNotice('')
|
|
@@ -187,6 +213,22 @@ window.__ModuleLoader__.load({
|
|
|
187
213
|
else setNotice(`发送失败:${result?.error || '未知错误'}${result?.message ? ` · ${result.message}` : ''}`)
|
|
188
214
|
} catch (cause) {
|
|
189
215
|
setNotice(`发送失败:${String(cause?.message || cause)}`)
|
|
216
|
+
} finally {
|
|
217
|
+
setBusy('')
|
|
218
|
+
loadFailures()
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const clearFailures = async () => {
|
|
223
|
+
if (typeof window !== 'undefined' && typeof window.confirm === 'function' && !window.confirm('确定清空全部推送失败记录?')) return
|
|
224
|
+
setBusy('clear-failures')
|
|
225
|
+
setNotice('')
|
|
226
|
+
try {
|
|
227
|
+
await post('/wechat-bot/failures/clear', {})
|
|
228
|
+
setFailures([])
|
|
229
|
+
setNotice('推送失败记录已清空')
|
|
230
|
+
} catch (cause) {
|
|
231
|
+
setNotice(`清空失败记录失败:${String(cause?.message || cause)}`)
|
|
190
232
|
} finally {
|
|
191
233
|
setBusy('')
|
|
192
234
|
}
|
|
@@ -196,142 +238,243 @@ window.__ModuleLoader__.load({
|
|
|
196
238
|
return h('div', { style: { padding: 24, color: MUTED } }, error ? `微信 bot 不可用:${error}` : '正在读取微信 bot 状态…')
|
|
197
239
|
}
|
|
198
240
|
|
|
199
|
-
const { connection, account, qr, counters, lastPush, recent, settings } = state
|
|
241
|
+
const { connection, account, qr, counters, lastPush, recent, settings, session, preset, presets } = state
|
|
200
242
|
const online = connection.state === 'online'
|
|
201
243
|
const qrUrl = qr?.url || ''
|
|
202
244
|
|
|
245
|
+
// 「main」槽位由 AppFrame 的 .mainPanel 承载:它是 overflow:hidden 的 flex 列,
|
|
246
|
+
// 自身不滚动。面板必须自己占满可用高度并成为滚动视口,否则超长内容被直接裁掉。
|
|
203
247
|
return h(
|
|
204
248
|
'div',
|
|
205
|
-
{
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
:
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
connection.error ? `|${connection.error}` : '',
|
|
223
|
-
h('br'),
|
|
224
|
-
`最近推送:${lastPush?.at ? `${fmtTime(lastPush.at)}${lastPush.ok ? ` 成功(${lastPush.chunks} 条 / ${lastPush.chars} 字)` : ` 失败(${lastPush.error || '未知错误'})`}` : '尚未推送'}`,
|
|
225
|
-
h('br'),
|
|
226
|
-
`会话转发:${settings?.chatForward ? '开启' : '关闭'}${settings?.chatSessionId ? `(${settings.chatSessionId})` : ''}`,
|
|
227
|
-
h('br'),
|
|
228
|
-
'微信指令:/help /status /login /logout /recent /news /new',
|
|
249
|
+
{
|
|
250
|
+
style: {
|
|
251
|
+
height: '100%',
|
|
252
|
+
overflowY: 'auto',
|
|
253
|
+
overflowX: 'hidden',
|
|
254
|
+
boxSizing: 'border-box',
|
|
255
|
+
color: TEXT,
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
h('div', { style: { padding: '24px 28px 40px', maxWidth: 820, boxSizing: 'border-box' } },
|
|
259
|
+
h('div', { style: { ...row, marginBottom: 14 } },
|
|
260
|
+
h('div', { style: { fontSize: 18, fontWeight: 600, marginRight: 6 } }, '微信 bot'),
|
|
261
|
+
h(StatusPill, { ok: online }, STATE_TEXT[connection.state] || connection.state),
|
|
262
|
+
connection.state === 'online' && account?.botId
|
|
263
|
+
? h('span', { style: { fontSize: 12, color: MUTED } }, `bot ${account.botId}`)
|
|
264
|
+
: null,
|
|
265
|
+
h('span', { style: { fontSize: 12, color: MUTED } }, `收 ${counters.received} · 发 ${counters.sent} · 失败 ${counters.failed}`),
|
|
229
266
|
),
|
|
230
|
-
h('div', { style: {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
267
|
+
error ? h('div', { style: { color: DANGER, fontSize: 12, marginBottom: 8 } }, error) : null,
|
|
268
|
+
notice ? h('div', { style: { color: MUTED, fontSize: 12, marginBottom: 8 } }, notice) : null,
|
|
269
|
+
|
|
270
|
+
// 连接状态
|
|
271
|
+
h('div', { style: card },
|
|
272
|
+
h('div', { style: { fontSize: 14, fontWeight: 600, marginBottom: 6 } }, '连接状态'),
|
|
273
|
+
h('div', { style: { fontSize: 12, color: MUTED, lineHeight: 1.8, overflowWrap: 'anywhere' } },
|
|
274
|
+
`状态:${STATE_TEXT[connection.state] || connection.state}(${connection.state})`,
|
|
275
|
+
connection.error ? `|${connection.error}` : '',
|
|
276
|
+
h('br'),
|
|
277
|
+
`最近推送:${lastPush?.at ? `${fmtTime(lastPush.at)}${lastPush.ok ? ` 成功(${lastPush.chunks} 条 / ${lastPush.chars} 字)` : ` 失败(${lastPush.error || '未知错误'})`}` : '尚未推送'}`,
|
|
278
|
+
h('br'),
|
|
279
|
+
`会话转发:${settings?.chatForward ? '开启' : '关闭'}${settings?.chatSessionId ? `(${settings.chatSessionId})` : ''}`,
|
|
280
|
+
h('br'),
|
|
281
|
+
`专用会话:预设 ${session?.agentPreset || settings?.agentPreset || '部署默认'} · 模型 ${session?.model || '会话默认'} · 权限 ${session?.permission || '部署默认'}`,
|
|
282
|
+
h('br'),
|
|
283
|
+
`进度回传:${settings?.stream?.enabled ? `按步骤流式(静默 ${Math.round((settings.stream.progressEveryMs || 0) / 1000)}s 回进度)` : '整轮结束一次性回传'}`,
|
|
284
|
+
h('br'),
|
|
285
|
+
'微信指令:/help /status /login /logout /recent /news /new',
|
|
286
|
+
),
|
|
287
|
+
h('div', { style: { marginTop: 10 } },
|
|
288
|
+
h('button', { style: primaryButton, disabled: Boolean(busy), onClick: act('开始登录', () => post('/wechat-bot/login', { action: 'start' })) }, '开始 / 刷新登录'),
|
|
289
|
+
qrUrl ? h('button', { style: button, disabled: Boolean(busy), onClick: act('换一个二维码', () => post('/wechat-bot/login', { action: 'start' })) }, '换一个二维码') : null,
|
|
290
|
+
h('button', { style: button, disabled: Boolean(busy) || !account?.botId, onClick: act('退出登录', () => post('/wechat-bot/login', { action: 'logout' })) }, '退出登录'),
|
|
291
|
+
),
|
|
234
292
|
),
|
|
235
|
-
),
|
|
236
293
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
294
|
+
// 推送失败记录:推送失败时自动落盘,面板直接可读(哪个智能体 / 内容 / 时间 / 原因)
|
|
295
|
+
h('div', { style: card },
|
|
296
|
+
h('div', { style: { fontSize: 14, fontWeight: 600, marginBottom: 6 } },
|
|
297
|
+
`推送失败记录${failures.length ? `(${failures.length})` : ''}`),
|
|
298
|
+
h('div', { style: { fontSize: 12, color: MUTED, marginBottom: 8, lineHeight: 1.8 } },
|
|
299
|
+
'只要推送失败(未登录、连接失效、没有会话凭证、发送失败),这里自动记录:哪个智能体、发送了什么内容、发送时间与失败原因。只保留最近 50 条。',
|
|
300
|
+
),
|
|
301
|
+
failuresError
|
|
302
|
+
? h('div', { style: { fontSize: 12, color: DANGER, marginBottom: 6 } }, `读取失败记录出错:${failuresError}`)
|
|
303
|
+
: null,
|
|
304
|
+
failures.length === 0
|
|
305
|
+
? h('div', { style: { fontSize: 12, color: MUTED } }, '暂无推送失败记录。')
|
|
306
|
+
: h('div', { style: { maxHeight: 460, overflowY: 'auto', overflowX: 'hidden' } },
|
|
307
|
+
failures.map((item) => {
|
|
308
|
+
const agentLabel = item?.agent?.label || '未识别来源'
|
|
309
|
+
const failedAt = item?.at || item?.startedAt
|
|
310
|
+
return h('div', { key: item.id || `${failedAt}-${item.chars}`, style: { borderBottom: `1px solid ${BORDER}`, padding: '8px 0' } },
|
|
311
|
+
h('div', { style: { display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', gap: 8, flexWrap: 'wrap' } },
|
|
312
|
+
h('span', { style: { fontSize: 13, fontWeight: 600, overflowWrap: 'anywhere' } }, agentLabel),
|
|
313
|
+
h('span', { style: { fontSize: 12, color: MUTED, whiteSpace: 'nowrap' } }, fmtTime(failedAt)),
|
|
314
|
+
),
|
|
315
|
+
h('div', { style: { fontSize: 12, color: DANGER, marginTop: 2, overflowWrap: 'anywhere' } },
|
|
316
|
+
`${item.error || 'send_failed'}${item.message ? ` · ${item.message}` : ''}${item.chunksSent ? `(已发出 ${item.chunksSent} 片后才失败)` : ''}`,
|
|
317
|
+
),
|
|
318
|
+
item.file
|
|
319
|
+
? h('div', { style: { ...mono, fontSize: 11, color: MUTED, marginTop: 2, overflowWrap: 'anywhere' } }, `文件:${item.file}`)
|
|
320
|
+
: null,
|
|
321
|
+
h('details', { style: { marginTop: 4 } },
|
|
322
|
+
h('summary', { style: { cursor: 'pointer', fontSize: 12, color: ACCENT } },
|
|
323
|
+
`查看发送内容(${item.chars ?? 0} 字)`),
|
|
324
|
+
h('pre', {
|
|
325
|
+
style: {
|
|
326
|
+
...mono,
|
|
327
|
+
whiteSpace: 'pre-wrap',
|
|
328
|
+
overflowWrap: 'anywhere',
|
|
329
|
+
background: '#f7f7f7',
|
|
330
|
+
padding: '8px',
|
|
331
|
+
borderRadius: 6,
|
|
332
|
+
marginTop: 4,
|
|
333
|
+
maxHeight: 260,
|
|
334
|
+
overflow: 'auto',
|
|
335
|
+
},
|
|
336
|
+
}, item.content || '(内容为空)'),
|
|
337
|
+
item.truncated
|
|
338
|
+
? h('div', { style: { fontSize: 11, color: MUTED } }, '内容过长,仅保留前 4000 字。')
|
|
339
|
+
: null,
|
|
340
|
+
),
|
|
341
|
+
)
|
|
342
|
+
}),
|
|
343
|
+
),
|
|
344
|
+
failures.length
|
|
345
|
+
? h('div', { style: { marginTop: 8 } },
|
|
346
|
+
h('button', { style: button, disabled: Boolean(busy), onClick: clearFailures },
|
|
347
|
+
busy === 'clear-failures' ? '清空中…' : '清空记录'),
|
|
348
|
+
)
|
|
349
|
+
: null,
|
|
350
|
+
),
|
|
268
351
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
'
|
|
275
|
-
|
|
352
|
+
// 回答预设:切换微信消息交给哪个 Agent 预设(人设 + 工具)
|
|
353
|
+
h('div', { style: card },
|
|
354
|
+
h('div', { style: { fontSize: 14, fontWeight: 600, marginBottom: 6 } }, '回答预设'),
|
|
355
|
+
h('div', { style: { fontSize: 12, color: MUTED, lineHeight: 1.8, marginBottom: 8 } },
|
|
356
|
+
'微信消息交给哪个 Agent 预设处理(决定人设与可用工具)。切换后旧会话解绑,下一条微信消息按新预设新建会话;已建会话的预设是创建时固化的,不会就地改变。',
|
|
357
|
+
h('br'),
|
|
358
|
+
`当前生效:${session?.agentPreset || (preset?.followDefault ? '跟随 DSH 默认' : '尚未建会话')}`,
|
|
359
|
+
preset?.configured ? ` · 已配置 ${preset.configured}` : ' · 跟随 DSH 默认',
|
|
276
360
|
),
|
|
277
|
-
h('
|
|
278
|
-
'
|
|
279
|
-
|
|
280
|
-
|
|
361
|
+
h('select', {
|
|
362
|
+
style: { ...input, maxWidth: 340, display: 'block' },
|
|
363
|
+
value: settings?.agentPreset || '',
|
|
364
|
+
disabled: Boolean(busy) || !presets || presets.length === 0,
|
|
365
|
+
onChange: (event) =>
|
|
366
|
+
act('切换预设', () => post('/wechat-bot/preset', { id: event.target.value }))(),
|
|
367
|
+
},
|
|
368
|
+
h('option', { value: '' }, '跟随 DSH 默认预设'),
|
|
369
|
+
(presets || []).map((item) =>
|
|
370
|
+
h('option', { key: item.id, value: item.id },
|
|
371
|
+
`${item.name && item.name !== item.id ? `${item.name}(${item.id})` : item.id}${item.isDefault ? ' · 默认' : ''}${item.broken ? ' · 加载失败' : ''}`),
|
|
372
|
+
),
|
|
281
373
|
),
|
|
282
|
-
|
|
283
|
-
|
|
374
|
+
!presets || presets.length === 0
|
|
375
|
+
? h('div', { style: { fontSize: 12, color: MUTED, marginTop: 6 } }, '暂无可选预设(agentPresets 服务不可用或未注册任何预设)')
|
|
376
|
+
: null,
|
|
284
377
|
),
|
|
285
|
-
),
|
|
286
378
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
379
|
+
// 登录二维码
|
|
380
|
+
qrUrl
|
|
381
|
+
? h('div', { style: card },
|
|
382
|
+
h('div', { style: { fontSize: 14, fontWeight: 600, marginBottom: 4 } }, '扫码登录'),
|
|
383
|
+
h('div', { style: { fontSize: 12, color: MUTED, marginBottom: 8 } },
|
|
384
|
+
qr.hasQr
|
|
385
|
+
? '用手机微信扫描下方二维码确认登录(二维码约 2 分钟自动更换)。'
|
|
386
|
+
: '用手机微信打开下方链接并确认登录(二维码约 2 分钟过期)。'),
|
|
387
|
+
qr.hasQr
|
|
388
|
+
? h('img', {
|
|
389
|
+
src: qr.dataUrl,
|
|
390
|
+
alt: '微信登录二维码',
|
|
391
|
+
style: {
|
|
392
|
+
width: 220,
|
|
393
|
+
height: 220,
|
|
394
|
+
display: 'block',
|
|
395
|
+
border: `1px solid ${BORDER}`,
|
|
396
|
+
borderRadius: 8,
|
|
397
|
+
background: '#fff',
|
|
398
|
+
marginBottom: 8,
|
|
399
|
+
},
|
|
400
|
+
})
|
|
401
|
+
: null,
|
|
402
|
+
h('div', { style: { ...mono, fontSize: 11, color: MUTED, wordBreak: 'break-all', background: '#f7f7f7', padding: '6px 8px', borderRadius: 6, userSelect: 'all' } }, qrUrl),
|
|
403
|
+
h('div', { style: { marginTop: 8 } },
|
|
404
|
+
h('button', { style: primaryButton, onClick: copyQr }, copied ? '已复制' : '复制链接'),
|
|
405
|
+
h('a', { href: qrUrl, target: '_blank', rel: 'noreferrer', style: { ...button, display: 'inline-block', textDecoration: 'none' } }, '在新标签页打开'),
|
|
406
|
+
h('button', { style: button, disabled: Boolean(busy), onClick: act('取消登录', () => post('/wechat-bot/login', { action: 'cancel' })) }, '取消登录'),
|
|
407
|
+
),
|
|
299
408
|
)
|
|
300
|
-
:
|
|
301
|
-
),
|
|
409
|
+
: null,
|
|
302
410
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
411
|
+
// 作者信息
|
|
412
|
+
h('div', { style: card },
|
|
413
|
+
h('div', { style: { fontSize: 14, fontWeight: 600, marginBottom: 6 } }, '作者信息'),
|
|
414
|
+
h('div', { style: { fontSize: 12, color: MUTED, lineHeight: 2 } },
|
|
415
|
+
h('div', null,
|
|
416
|
+
'作者:',
|
|
417
|
+
h('span', { style: { color: TEXT, fontWeight: 600 } }, '思链科技(MindLink)'),
|
|
418
|
+
),
|
|
419
|
+
h('div', null,
|
|
420
|
+
'插件:',
|
|
421
|
+
h('span', { style: mono }, '@mindlink-ai/dsh-wechat-bot'),
|
|
422
|
+
' · v1.3.0',
|
|
423
|
+
),
|
|
424
|
+
h('div', null, '通道:微信官方 iLink(ClawBot) · 本地优先,聊天数据只留在本机'),
|
|
425
|
+
h('div', null, '许可:MIT · 反馈与定制请联系插件维护者'),
|
|
426
|
+
),
|
|
319
427
|
),
|
|
320
|
-
),
|
|
321
428
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
429
|
+
// 账号信息
|
|
430
|
+
h('div', { style: card },
|
|
431
|
+
h('div', { style: { fontSize: 14, fontWeight: 600, marginBottom: 6 } }, '账号信息'),
|
|
432
|
+
account?.botId
|
|
433
|
+
? h('div', { style: { ...mono, color: MUTED, lineHeight: 2, overflowWrap: 'anywhere' } },
|
|
434
|
+
`bot ID:${account.botId}`,
|
|
435
|
+
h('br'),
|
|
436
|
+
`用户 ID:${account.userId || '—'}`,
|
|
437
|
+
h('br'),
|
|
438
|
+
`网关:${account.baseUrl || '—'}`,
|
|
439
|
+
h('br'),
|
|
440
|
+
`登录时间:${account.savedAt ? fmtTime(Date.parse(account.savedAt)) : '—'}`,
|
|
441
|
+
)
|
|
442
|
+
: h('div', { style: { fontSize: 12, color: MUTED } }, '尚未登录。点上面的「开始 / 刷新登录」,然后用手机微信扫码确认。'),
|
|
443
|
+
),
|
|
444
|
+
|
|
445
|
+
// 测试推送
|
|
446
|
+
h('div', { style: card },
|
|
447
|
+
h('div', { style: { fontSize: 14, fontWeight: 600, marginBottom: 4 } }, '测试推送'),
|
|
448
|
+
h('div', { style: { fontSize: 12, color: MUTED } }, '推送到你本人的微信(1:1 会话)。首次使用前,请在微信里给机器人发一条任意消息,让 bot 记录会话上下文。'),
|
|
449
|
+
h('label', { style: label }, '消息内容'),
|
|
450
|
+
h('textarea', {
|
|
451
|
+
style: { ...input, minHeight: 64, resize: 'vertical' },
|
|
452
|
+
value: testText,
|
|
453
|
+
onChange: (event) => setTestText(event.target.value),
|
|
454
|
+
}),
|
|
455
|
+
h('div', { style: { marginTop: 8 } },
|
|
456
|
+
h('button', {
|
|
457
|
+
style: primaryButton,
|
|
458
|
+
disabled: Boolean(busy) || !testText.trim(),
|
|
459
|
+
onClick: sendTest,
|
|
460
|
+
}, busy === 'send' ? '发送中…' : '发送到微信'),
|
|
461
|
+
),
|
|
462
|
+
),
|
|
463
|
+
|
|
464
|
+
// 最近消息
|
|
465
|
+
h('div', { style: card },
|
|
466
|
+
h('div', { style: { fontSize: 14, fontWeight: 600, marginBottom: 8 } }, `最近收到的消息(${recent.length})`),
|
|
467
|
+
recent.length === 0
|
|
468
|
+
? h('div', { style: { fontSize: 12, color: MUTED } }, '暂无。给机器人发一条消息后,这里会显示记录并刷新推送上下文。')
|
|
469
|
+
: h('ul', { style: { listStyle: 'none', margin: 0, padding: 0, maxHeight: 240, overflowY: 'auto', overflowX: 'hidden' } },
|
|
470
|
+
recent.slice().reverse().map((item, index) =>
|
|
471
|
+
h('li', { key: `${item.at}-${index}`, style: { padding: '6px 0', borderBottom: `1px solid ${BORDER}`, fontSize: 12, overflowWrap: 'anywhere' } },
|
|
472
|
+
h('span', { style: { color: MUTED } }, `${fmtTime(item.at)} `),
|
|
473
|
+
h('span', null, item.text || '[非文本]'),
|
|
474
|
+
),
|
|
332
475
|
),
|
|
333
476
|
),
|
|
334
|
-
|
|
477
|
+
),
|
|
335
478
|
),
|
|
336
479
|
|
|
337
480
|
)
|