@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ducci/jarvis",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
4
4
  "description": "A fully automated agent system that lives on a server.",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -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
- const result = await handleChat(config, sessionId, ctx.message.text);
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
- // Persist new session mapping on first message
52
- if (!sessions[chatId]) {
53
- sessions[chatId] = result.sessionId;
54
- save(sessions);
55
- console.log(`[telegram] session created sessionId=${result.sessionId.slice(0, 8)}`);
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
- await ctx.reply(result.response);
59
- console.log(`[telegram] response sent chat_id=${chatId}`);
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);