@ducci/jarvis 1.0.17 → 1.0.18
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/src/channels/telegram/index.js +26 -10
package/package.json
CHANGED
|
@@ -45,20 +45,36 @@ export async function startTelegramChannel(config) {
|
|
|
45
45
|
ctx.api.sendChatAction(chatId, 'typing').catch(() => {});
|
|
46
46
|
}, 4000);
|
|
47
47
|
|
|
48
|
+
let result;
|
|
48
49
|
try {
|
|
49
|
-
|
|
50
|
+
result = await handleChat(config, sessionId, ctx.message.text);
|
|
51
|
+
} catch (e) {
|
|
52
|
+
console.error(`[telegram] agent error chat_id=${chatId}: ${e.message}`);
|
|
53
|
+
await ctx.reply('Sorry, something went wrong. Please try again.');
|
|
54
|
+
clearInterval(typingInterval);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
50
57
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
// Persist new session mapping on first message
|
|
59
|
+
if (!sessions[chatId]) {
|
|
60
|
+
sessions[chatId] = result.sessionId;
|
|
61
|
+
save(sessions);
|
|
62
|
+
console.log(`[telegram] session created sessionId=${result.sessionId.slice(0, 8)}`);
|
|
63
|
+
}
|
|
57
64
|
|
|
58
|
-
|
|
59
|
-
|
|
65
|
+
try {
|
|
66
|
+
const MAX_TG = 4096;
|
|
67
|
+
const text = result.response;
|
|
68
|
+
if (text.length <= MAX_TG) {
|
|
69
|
+
await ctx.reply(text);
|
|
70
|
+
} else {
|
|
71
|
+
for (let i = 0; i < text.length; i += MAX_TG) {
|
|
72
|
+
await ctx.reply(text.slice(i, i + MAX_TG));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
console.log(`[telegram] response sent chat_id=${chatId} length=${text.length}`);
|
|
60
76
|
} catch (e) {
|
|
61
|
-
console.error(`[telegram] error chat_id=${chatId}: ${e.message}`);
|
|
77
|
+
console.error(`[telegram] delivery error chat_id=${chatId} length=${result.response.length}: ${e.message}`);
|
|
62
78
|
await ctx.reply('Sorry, something went wrong. Please try again.');
|
|
63
79
|
} finally {
|
|
64
80
|
clearInterval(typingInterval);
|