foliko 1.0.67 → 1.0.68
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
CHANGED
package/plugins/feishu-plugin.js
CHANGED
|
@@ -288,8 +288,18 @@ class FeishuPlugin extends Plugin {
|
|
|
288
288
|
|
|
289
289
|
// 确定 openId
|
|
290
290
|
let openId = null
|
|
291
|
-
|
|
292
|
-
|
|
291
|
+
let effectiveSessionId = sessionId
|
|
292
|
+
|
|
293
|
+
// 如果没有 sessionId,尝试从执行上下文获取
|
|
294
|
+
if (!effectiveSessionId) {
|
|
295
|
+
const ctx = this._framework.getExecutionContext()
|
|
296
|
+
if (ctx?.sessionId) {
|
|
297
|
+
effectiveSessionId = ctx.sessionId
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (effectiveSessionId && effectiveSessionId.startsWith('feishu_')) {
|
|
302
|
+
openId = effectiveSessionId.replace('feishu_', '')
|
|
293
303
|
} else if (this._sessionPlugin) {
|
|
294
304
|
// 获取最近的 feishu 会话
|
|
295
305
|
const sessions = this._sessionPlugin.listSessions()
|
|
@@ -188,8 +188,15 @@ class SchedulerPlugin extends Plugin {
|
|
|
188
188
|
return { success: false, error: 'Agent not available' }
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
// 如果没有指定 sessionId
|
|
191
|
+
// 如果没有指定 sessionId,优先从执行上下文获取(来自 WeChat 等消息源)
|
|
192
192
|
let targetSessionId = sessionId
|
|
193
|
+
if (!targetSessionId) {
|
|
194
|
+
const ctx = this._framework.getExecutionContext()
|
|
195
|
+
if (ctx?.sessionId) {
|
|
196
|
+
targetSessionId = ctx.sessionId
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
// 如果执行上下文也没有,从 sessionPlugin 获取最近活跃会话
|
|
193
200
|
if (!targetSessionId) {
|
|
194
201
|
const sessionPlugin = this._framework.pluginManager.get('session')
|
|
195
202
|
if (sessionPlugin) {
|
|
@@ -99,8 +99,10 @@ class TelegramPlugin extends Plugin {
|
|
|
99
99
|
this._framework.on('agent:created', (agent) => {
|
|
100
100
|
console.log('[Telegram] New agent created:', agent.name)
|
|
101
101
|
})
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
|
|
103
|
+
// 监听统一通知事件
|
|
104
|
+
this._framework.on('notification', async (data) => {
|
|
105
|
+
await this._handleNotification(data)
|
|
104
106
|
})
|
|
105
107
|
|
|
106
108
|
// 监听 webhook 事件
|
|
@@ -113,36 +115,62 @@ class TelegramPlugin extends Plugin {
|
|
|
113
115
|
}
|
|
114
116
|
}
|
|
115
117
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
console.log(`[Telegram] Reminder sent to chat ${chatId}`)
|
|
125
|
-
} catch (err) {
|
|
126
|
-
console.error(`[Telegram] Failed to send reminder:`, err.message)
|
|
127
|
-
}
|
|
118
|
+
/**
|
|
119
|
+
* 处理统一通知
|
|
120
|
+
*/
|
|
121
|
+
async _handleNotification(data) {
|
|
122
|
+
const { title, message, source, level } = data
|
|
123
|
+
|
|
124
|
+
if (!this._bot) {
|
|
125
|
+
console.warn('[Telegram] Bot not ready, cannot send notification')
|
|
128
126
|
return
|
|
129
127
|
}
|
|
130
128
|
|
|
131
|
-
|
|
129
|
+
// 确定 chatId
|
|
130
|
+
let chatId = null
|
|
131
|
+
let effectiveSessionId = data.sessionId
|
|
132
|
+
|
|
133
|
+
// 如果没有 sessionId,尝试从执行上下文获取
|
|
134
|
+
if (!effectiveSessionId) {
|
|
135
|
+
const ctx = this._framework.getExecutionContext()
|
|
136
|
+
if (ctx?.sessionId) {
|
|
137
|
+
effectiveSessionId = ctx.sessionId
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (effectiveSessionId && effectiveSessionId.startsWith('telegram_')) {
|
|
142
|
+
chatId = effectiveSessionId.replace('telegram_', '')
|
|
143
|
+
} else if (this._sessionPlugin) {
|
|
144
|
+
// 获取最近的 telegram 会话
|
|
132
145
|
const sessions = this._sessionPlugin.listSessions()
|
|
133
146
|
.filter(s => s.id.startsWith('telegram_'))
|
|
134
147
|
.sort((a, b) => new Date(b.lastActive).getTime() - new Date(a.lastActive).getTime())
|
|
135
|
-
|
|
136
148
|
if (sessions.length > 0) {
|
|
137
|
-
|
|
138
|
-
try {
|
|
139
|
-
await this._bot.sendMessage(chatId, reminderText)
|
|
140
|
-
console.log(`[Telegram] Reminder sent to recent chat ${chatId}`)
|
|
141
|
-
} catch (err) {
|
|
142
|
-
console.error(`[Telegram] Failed to send reminder:`, err.message)
|
|
143
|
-
}
|
|
149
|
+
chatId = sessions[0].id.replace('telegram_', '')
|
|
144
150
|
}
|
|
145
151
|
}
|
|
152
|
+
|
|
153
|
+
if (!chatId) {
|
|
154
|
+
console.warn('[Telegram] No telegram session found for notification')
|
|
155
|
+
return
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// 格式化通知消息
|
|
159
|
+
const levelEmoji = {
|
|
160
|
+
info: 'ℹ️',
|
|
161
|
+
warning: '⚠️',
|
|
162
|
+
success: '✅',
|
|
163
|
+
error: '❌'
|
|
164
|
+
}
|
|
165
|
+
const emoji = levelEmoji[level] || 'ℹ️'
|
|
166
|
+
const notificationText = `${emoji} [${source}] ${title}\n\n${message}`
|
|
167
|
+
|
|
168
|
+
try {
|
|
169
|
+
await this._bot.sendMessage(chatId, notificationText)
|
|
170
|
+
console.log(`[Telegram] Notification sent to chat ${chatId}`)
|
|
171
|
+
} catch (err) {
|
|
172
|
+
console.error(`[Telegram] Failed to send notification:`, err.message)
|
|
173
|
+
}
|
|
146
174
|
}
|
|
147
175
|
|
|
148
176
|
/**
|
package/plugins/weixin-plugin.js
CHANGED
|
@@ -424,8 +424,18 @@ class WeixinPlugin extends Plugin {
|
|
|
424
424
|
|
|
425
425
|
// 确定用户ID
|
|
426
426
|
let userId = null
|
|
427
|
-
|
|
428
|
-
|
|
427
|
+
let effectiveSessionId = sessionId
|
|
428
|
+
|
|
429
|
+
// 如果没有 sessionId,尝试从执行上下文获取
|
|
430
|
+
if (!effectiveSessionId) {
|
|
431
|
+
const ctx = this._framework.getExecutionContext()
|
|
432
|
+
if (ctx?.sessionId) {
|
|
433
|
+
effectiveSessionId = ctx.sessionId
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
if (effectiveSessionId && effectiveSessionId.startsWith('weixin_')) {
|
|
438
|
+
userId = effectiveSessionId.replace('weixin_', '')
|
|
429
439
|
} else if (this._sessionPlugin) {
|
|
430
440
|
// 获取最近的 weixin 会话
|
|
431
441
|
const sessions = this._sessionPlugin.listSessions()
|