foliko 1.0.57 → 1.0.59
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/package.json +1 -1
- package/plugins/feishu-plugin.js +4 -1
- package/plugins/weixin-plugin.js +51 -8
package/package.json
CHANGED
package/plugins/feishu-plugin.js
CHANGED
|
@@ -18,7 +18,10 @@ class FeishuPlugin extends Plugin {
|
|
|
18
18
|
this.description = '飞书对话插件,使用 WebSocket 长连接接收消息'
|
|
19
19
|
this.priority = 80
|
|
20
20
|
this.enabled = false
|
|
21
|
-
this.systemPrompt =
|
|
21
|
+
this.systemPrompt = `你是一个飞书助手。
|
|
22
|
+
|
|
23
|
+
**重要:**
|
|
24
|
+
-回复内容使用纯文本,不要使用markdown
|
|
22
25
|
|
|
23
26
|
**命令执行规范:**
|
|
24
27
|
- 执行 npx skills add / npx skills remove / npx skills list 命令时,必须自动添加参数:-a openclaw -y
|
package/plugins/weixin-plugin.js
CHANGED
|
@@ -22,7 +22,10 @@ class WeixinPlugin extends Plugin {
|
|
|
22
22
|
// 默认不启用,需要在 plugins.json 中设置 enabled: true
|
|
23
23
|
this.enabled = false
|
|
24
24
|
this.path=`.agent/data`
|
|
25
|
-
this.systemPrompt
|
|
25
|
+
this.systemPrompt=`你是一个微信助手。
|
|
26
|
+
|
|
27
|
+
**重要:**
|
|
28
|
+
-回复内容使用纯文本,不要使用markdown
|
|
26
29
|
|
|
27
30
|
**命令执行规范:**
|
|
28
31
|
- 执行 npx skills add / npx skills remove / npx skills list 命令时,必须自动添加参数:-a openclaw -y
|
|
@@ -254,17 +257,17 @@ class WeixinPlugin extends Plugin {
|
|
|
254
257
|
this._sessionPlugin.addMessage(sessionId, { role: 'assistant', content: fullResponse })
|
|
255
258
|
}
|
|
256
259
|
|
|
257
|
-
//
|
|
260
|
+
// 发送回复(超过500字自动分批)
|
|
258
261
|
if (fullResponse) {
|
|
259
|
-
await this.
|
|
262
|
+
await this._sendMessageBatch(originalMsg, userId, fullResponse, true)
|
|
260
263
|
console.log(`[WeChat] 回复成功 (${fullResponse.length} 字符)`)
|
|
261
264
|
} else {
|
|
262
|
-
await this.
|
|
265
|
+
await this._sendMessageBatch(originalMsg, userId, '抱歉,我没有收到有效的回复。', true)
|
|
263
266
|
}
|
|
264
267
|
|
|
265
268
|
} catch (err) {
|
|
266
269
|
console.error('[WeChat] Chat error:', err)
|
|
267
|
-
await this.
|
|
270
|
+
await this._sendMessageBatch(originalMsg, userId, `发生错误:${err.message}`, true)
|
|
268
271
|
}
|
|
269
272
|
}
|
|
270
273
|
|
|
@@ -278,6 +281,46 @@ class WeixinPlugin extends Plugin {
|
|
|
278
281
|
return this.config.allowedUsers.includes(userId)
|
|
279
282
|
}
|
|
280
283
|
|
|
284
|
+
/**
|
|
285
|
+
* 发送消息(超过500字自动分批)
|
|
286
|
+
* @param {Object} originalMsg - 原始消息对象(用于reply)
|
|
287
|
+
* @param {string} userId - 用户ID(用于sendText)
|
|
288
|
+
* @param {string} text - 要发送的文本
|
|
289
|
+
* @param {boolean} useReply - 是否使用reply方式
|
|
290
|
+
*/
|
|
291
|
+
async _sendMessageBatch(originalMsg, userId, text, useReply = true) {
|
|
292
|
+
const MAX_LEN = 500
|
|
293
|
+
if (!text || text.length <= MAX_LEN) {
|
|
294
|
+
if (useReply && originalMsg) {
|
|
295
|
+
await this._bot.reply(originalMsg, text)
|
|
296
|
+
} else {
|
|
297
|
+
await this._bot.sendText(userId, text)
|
|
298
|
+
}
|
|
299
|
+
return
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// 分批发送
|
|
303
|
+
const chunks = []
|
|
304
|
+
for (let i = 0; i < text.length; i += MAX_LEN) {
|
|
305
|
+
chunks.push(text.slice(i, i + MAX_LEN))
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
console.log(`[WeChat] Message too long (${text.length}), splitting into ${chunks.length} parts`)
|
|
309
|
+
|
|
310
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
311
|
+
const chunk = `[${i + 1}/${chunks.length}]\n${chunks[i]}`
|
|
312
|
+
if (useReply && originalMsg) {
|
|
313
|
+
await this._bot.reply(originalMsg, chunk)
|
|
314
|
+
} else {
|
|
315
|
+
await this._bot.sendText(userId, chunk)
|
|
316
|
+
}
|
|
317
|
+
// 批次间隔,避免发送太快
|
|
318
|
+
if (i < chunks.length - 1) {
|
|
319
|
+
await new Promise(r => setTimeout(r, 300))
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
281
324
|
/**
|
|
282
325
|
* 清除会话
|
|
283
326
|
*/
|
|
@@ -307,7 +350,7 @@ class WeixinPlugin extends Plugin {
|
|
|
307
350
|
if (sessionId && sessionId.startsWith('weixin_')) {
|
|
308
351
|
const userId = sessionId.replace('weixin_', '')
|
|
309
352
|
try {
|
|
310
|
-
await this.
|
|
353
|
+
await this._sendMessageBatch(null, userId, reminderText, false)
|
|
311
354
|
console.log(`[WeChat] Reminder sent to user ${userId}`)
|
|
312
355
|
} catch (err) {
|
|
313
356
|
console.error(`[WeChat] Failed to send reminder:`, err.message)
|
|
@@ -325,7 +368,7 @@ class WeixinPlugin extends Plugin {
|
|
|
325
368
|
if (weixinSessions.length > 0) {
|
|
326
369
|
const userId = weixinSessions[0].id.replace('weixin_', '')
|
|
327
370
|
try {
|
|
328
|
-
await this.
|
|
371
|
+
await this._sendMessageBatch(null, userId, reminderText, false)
|
|
329
372
|
console.log(`[WeChat] Reminder sent to recent user ${userId}`)
|
|
330
373
|
} catch (err) {
|
|
331
374
|
console.error(`[WeChat] Failed to send reminder:`, err.message)
|
|
@@ -356,7 +399,7 @@ class WeixinPlugin extends Plugin {
|
|
|
356
399
|
const notificationText = `📥 [Webhook 接收]\n\n路径: ${webhookData.path}\n方法: ${webhookData.method}\n\n处理结果: ${response || '处理中...'}`
|
|
357
400
|
|
|
358
401
|
try {
|
|
359
|
-
await this.
|
|
402
|
+
await this._sendMessageBatch(null, userId, notificationText, false)
|
|
360
403
|
console.log(`[WeChat] Webhook notification sent to user ${userId}`)
|
|
361
404
|
} catch (err) {
|
|
362
405
|
console.error(`[WeChat] Failed to send webhook notification:`, err.message)
|