@elizaos/plugin-telegram 1.0.0-alpha.58 → 1.0.0-alpha.60
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/dist/index.js +19 -12
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -43,7 +43,7 @@ ${errorMessages}`
|
|
|
43
43
|
import {
|
|
44
44
|
ChannelType,
|
|
45
45
|
EventTypes,
|
|
46
|
-
|
|
46
|
+
ModelType,
|
|
47
47
|
createUniqueUuid,
|
|
48
48
|
logger
|
|
49
49
|
} from "@elizaos/core";
|
|
@@ -108,7 +108,7 @@ var MessageManager = class {
|
|
|
108
108
|
}
|
|
109
109
|
if (imageUrl) {
|
|
110
110
|
const { title, description } = await this.runtime.useModel(
|
|
111
|
-
|
|
111
|
+
ModelType.IMAGE_DESCRIPTION,
|
|
112
112
|
imageUrl
|
|
113
113
|
);
|
|
114
114
|
return { description: `[Image: ${title}
|
|
@@ -252,7 +252,7 @@ ${description}]` };
|
|
|
252
252
|
* @returns {Promise<void>}
|
|
253
253
|
*/
|
|
254
254
|
async handleMessage(ctx) {
|
|
255
|
-
var _a, _b;
|
|
255
|
+
var _a, _b, _c, _d, _e, _f;
|
|
256
256
|
if (!ctx.message || !ctx.from) return;
|
|
257
257
|
const message = ctx.message;
|
|
258
258
|
try {
|
|
@@ -261,8 +261,7 @@ ${description}]` };
|
|
|
261
261
|
ctx.from.id.toString()
|
|
262
262
|
);
|
|
263
263
|
const userName = ctx.from.username || ctx.from.first_name || "Unknown User";
|
|
264
|
-
const
|
|
265
|
-
const roomId = chatId;
|
|
264
|
+
const roomId = createUniqueUuid(this.runtime, (_a = ctx.chat) == null ? void 0 : _a.id.toString());
|
|
266
265
|
const messageId = createUniqueUuid(
|
|
267
266
|
this.runtime,
|
|
268
267
|
(_b = message == null ? void 0 : message.message_id) == null ? void 0 : _b.toString()
|
|
@@ -278,9 +277,12 @@ ${description}]` };
|
|
|
278
277
|
if (!fullText) return;
|
|
279
278
|
const chat = message.chat;
|
|
280
279
|
const channelType = getChannelType(chat);
|
|
280
|
+
const worldId = createUniqueUuid(
|
|
281
|
+
this.runtime,
|
|
282
|
+
chat.type === "private" ? `private_${chat.id}` : chat.id.toString()
|
|
283
|
+
);
|
|
281
284
|
const worldName = chat.type === "supergroup" ? chat.title : chat.type === "channel" ? chat.title : chat.type === "private" ? `Chat with ${chat.first_name || "Unknown"}` : "Telegram";
|
|
282
285
|
const roomName = chat.type === "private" ? chat.first_name : chat.type === "supergroup" ? chat.title : chat.type === "channel" ? chat.title : chat.type === "group" ? chat.title : "Unknown Group";
|
|
283
|
-
const worldId = createUniqueUuid(this.runtime, chat.id.toString());
|
|
284
286
|
await this.runtime.ensureConnection({
|
|
285
287
|
entityId,
|
|
286
288
|
roomId,
|
|
@@ -288,7 +290,8 @@ ${description}]` };
|
|
|
288
290
|
name: userName,
|
|
289
291
|
source: "telegram",
|
|
290
292
|
channelId: ctx.chat.id.toString(),
|
|
291
|
-
serverId: chat.id.toString(),
|
|
293
|
+
serverId: chat.type === "private" ? void 0 : chat.id.toString(),
|
|
294
|
+
// Only set serverId for non-private chats
|
|
292
295
|
type: channelType,
|
|
293
296
|
worldId
|
|
294
297
|
});
|
|
@@ -298,7 +301,7 @@ ${description}]` };
|
|
|
298
301
|
source: "telegram",
|
|
299
302
|
type: channelType,
|
|
300
303
|
channelId: ctx.chat.id.toString(),
|
|
301
|
-
serverId:
|
|
304
|
+
serverId: chat.type === "private" ? void 0 : chat.id.toString(),
|
|
302
305
|
worldId
|
|
303
306
|
};
|
|
304
307
|
await this.runtime.ensureRoomExists(room);
|
|
@@ -346,7 +349,7 @@ ${description}]` };
|
|
|
346
349
|
},
|
|
347
350
|
createdAt: sentMessage.date * 1e3
|
|
348
351
|
};
|
|
349
|
-
await this.runtime.
|
|
352
|
+
await this.runtime.createMemory(responseMemory, "messages");
|
|
350
353
|
memories.push(responseMemory);
|
|
351
354
|
}
|
|
352
355
|
return memories;
|
|
@@ -376,8 +379,12 @@ ${description}]` };
|
|
|
376
379
|
}
|
|
377
380
|
);
|
|
378
381
|
} catch (error) {
|
|
379
|
-
logger.error("
|
|
380
|
-
|
|
382
|
+
logger.error("Error handling Telegram message:", {
|
|
383
|
+
error,
|
|
384
|
+
chatId: (_c = ctx.chat) == null ? void 0 : _c.id,
|
|
385
|
+
messageId: (_d = ctx.message) == null ? void 0 : _d.message_id,
|
|
386
|
+
from: ((_e = ctx.from) == null ? void 0 : _e.username) || ((_f = ctx.from) == null ? void 0 : _f.id)
|
|
387
|
+
});
|
|
381
388
|
throw error;
|
|
382
389
|
}
|
|
383
390
|
}
|
|
@@ -505,7 +512,7 @@ ${description}]` };
|
|
|
505
512
|
},
|
|
506
513
|
createdAt: sentMessage.date * 1e3
|
|
507
514
|
};
|
|
508
|
-
await this.runtime.
|
|
515
|
+
await this.runtime.createMemory(memory, "messages");
|
|
509
516
|
memories.push(memory);
|
|
510
517
|
}
|
|
511
518
|
this.runtime.emitEvent(
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/constants.ts","../src/service.ts","../src/environment.ts","../src/messageManager.ts","../src/utils.ts","../src/tests.ts","../src/index.ts"],"sourcesContent":["export const MESSAGE_CONSTANTS = {\n\tMAX_MESSAGES: 50,\n\tRECENT_MESSAGE_COUNT: 5,\n\tCHAT_HISTORY_COUNT: 10,\n\tDEFAULT_SIMILARITY_THRESHOLD: 0.6,\n\tDEFAULT_SIMILARITY_THRESHOLD_FOLLOW_UPS: 0.4,\n\tINTEREST_DECAY_TIME: 5 * 60 * 1000, // 5 minutes\n\tPARTIAL_INTEREST_DECAY: 3 * 60 * 1000, // 3 minutes\n} as const;\n\nexport const TELEGRAM_SERVICE_NAME = \"telegram\";\n","import { ChannelType, type Entity, EventTypes, type IAgentRuntime, Role, type Room, Service, type UUID, type World, createUniqueUuid, logger } from \"@elizaos/core\";\nimport { type Context, Telegraf } from \"telegraf\";\nimport { TELEGRAM_SERVICE_NAME } from \"./constants\";\nimport { validateTelegramConfig } from \"./environment\";\nimport { MessageManager } from \"./messageManager\";\nimport { TelegramEventTypes } from \"./types\";\n\n/**\n * Class representing a Telegram service that allows the agent to send and receive messages on Telegram.\n * @extends Service\n */\n\nexport class TelegramService extends Service {\n\tstatic serviceType = TELEGRAM_SERVICE_NAME;\n\tcapabilityDescription = \"The agent is able to send and receive messages on telegram\";\n\tprivate bot: Telegraf<Context>;\n\tpublic messageManager: MessageManager;\n\tprivate options;\n\tprivate knownChats: Map<string, any> = new Map();\n\n\t/**\n\t * Constructor for TelegramService class.\n\t * @param {IAgentRuntime} runtime - The runtime object for the agent.\n\t */\n\tconstructor(runtime: IAgentRuntime) {\n\t\tsuper(runtime);\n\t\tlogger.log(\"📱 Constructing new TelegramService...\");\n\t\tthis.options = {\n\t\t\ttelegram: {\n\t\t\t\tapiRoot: runtime.getSetting(\"TELEGRAM_API_ROOT\") ||\n\t\t\t\t\tprocess.env.TELEGRAM_API_ROOT ||\n\t\t\t\t\t\"https://api.telegram.org\",\n\t\t\t},\n\t\t};\n\t\tconst botToken = runtime.getSetting(\"TELEGRAM_BOT_TOKEN\");\n\t\tthis.bot = new Telegraf(botToken, this.options);\n\t\tthis.messageManager = new MessageManager(this.bot, this.runtime);\n\t\tlogger.log(\"✅ TelegramService constructor completed\");\n\t}\n\n\t/**\n\t * Starts the Telegram service for the given runtime.\n\t *\n\t * @param {IAgentRuntime} runtime - The agent runtime to start the Telegram service for.\n\t * @returns {Promise<TelegramService>} A promise that resolves with the initialized TelegramService.\n\t */\n\tstatic async start(runtime: IAgentRuntime): Promise<TelegramService> {\n\t\tawait validateTelegramConfig(runtime);\n\n\t\tconst maxRetries = 5;\n\t\tlet retryCount = 0;\n\t\tlet lastError: Error | null = null;\n\n\t\twhile (retryCount < maxRetries) {\n\t\t\ttry {\n\t\t\t\tconst service = new TelegramService(runtime);\n\n\t\t\t\tlogger.success(\n\t\t\t\t\t`✅ Telegram client successfully started for character ${runtime.character.name}`\n\t\t\t\t);\n\n\t\t\t\tlogger.log(\"🚀 Starting Telegram bot...\");\n\t\t\t\tawait service.initializeBot();\n\t\t\t\tservice.setupMessageHandlers();\n\n\t\t\t\t// Wait for bot to be ready by testing getMe()\n\t\t\t\tawait service.bot.telegram.getMe();\n\n\t\t\t\treturn service;\n\t\t\t} catch (error) {\n\t\t\t\tlastError = error instanceof Error ? error : new Error(String(error));\n\t\t\t\tlogger.error(`Telegram initialization attempt ${retryCount + 1} failed: ${lastError.message}`);\n\t\t\t\tretryCount++;\n\n\t\t\t\tif (retryCount < maxRetries) {\n\t\t\t\t\tconst delay = 2 ** retryCount * 1000; // Exponential backoff\n\t\t\t\t\tlogger.info(`Retrying Telegram initialization in ${delay / 1000} seconds...`);\n\t\t\t\t\tawait new Promise(resolve => setTimeout(resolve, delay));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthrow new Error(`Telegram initialization failed after ${maxRetries} attempts. Last error: ${lastError?.message}`);\n\t}\n\n\t/**\n\t * Stops the agent runtime.\n\t * @param {IAgentRuntime} runtime - The agent runtime to stop\n\t */\n\tstatic async stop(runtime: IAgentRuntime) {\n\t\t// Implement shutdown if necessary\n\t\tconst tgClient = runtime.getService(TELEGRAM_SERVICE_NAME);\n\t\tif (tgClient) {\n\t\t\tawait tgClient.stop();\n\t\t}\n\t}\n\n\t/**\n\t * Asynchronously stops the bot.\n\t *\n\t * @returns A Promise that resolves once the bot has stopped.\n\t */\n\tasync stop(): Promise<void> {\n\t\tthis.bot.stop();\n\t}\n\n\t/**\n\t * Initializes the Telegram bot by launching it, getting bot info, and setting up message manager.\n\t * @returns {Promise<void>} A Promise that resolves when the initialization is complete.\n\t */\n\tprivate async initializeBot(): Promise<void> {\n\t\tthis.bot.launch({\n\t\t\tdropPendingUpdates: true,\n\t\t\tallowedUpdates: [\"message\", \"message_reaction\"],\n\t\t});\n\n\t\t// Get bot info for identification purposes\n\t\tconst botInfo = await this.bot.telegram.getMe();\n\t\tlogger.log(`Bot info: ${JSON.stringify(botInfo)}`);\n\n\t\t// Handle sigint and sigterm signals to gracefully stop the bot\n\t\tprocess.once(\"SIGINT\", () => this.bot.stop(\"SIGINT\"));\n\t\tprocess.once(\"SIGTERM\", () => this.bot.stop(\"SIGTERM\"));\n\t}\n\n\t/**\n\t * Checks if a group is authorized, based on the TELEGRAM_ALLOWED_CHATS setting.\n\t * @param {Context} ctx - The context of the incoming update.\n\t * @returns {Promise<boolean>} A Promise that resolves with a boolean indicating if the group is authorized.\n\t */\n\tprivate async isGroupAuthorized(ctx: Context): Promise<boolean> {\n\t\tconst chatId = ctx.chat?.id.toString();\n\t\tif (!chatId) return false;\n\n\t\t// If this is a chat we haven't seen before, emit WORLD_JOINED event\n\t\tif (!this.knownChats.has(chatId)) {\n\t\t\tawait this.handleNewChat(ctx);\n\t\t}\n\n\t\tconst allowedChats = this.runtime.getSetting(\"TELEGRAM_ALLOWED_CHATS\");\n\t\tif (!allowedChats) {\n\t\t\treturn true; // All chats are allowed if no restriction is set\n\t\t}\n\n\t\ttry {\n\t\t\tconst allowedChatsList = JSON.parse(allowedChats as string);\n\t\t\treturn allowedChatsList.includes(chatId);\n\t\t} catch (error) {\n\t\t\tlogger.error(\"Error parsing TELEGRAM_ALLOWED_CHATS:\", error);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Handles new chat discovery and emits WORLD_JOINED event\n\t * @param {Context} ctx - The context of the incoming update\n\t */\n\tprivate async handleNewChat(ctx: Context): Promise<void> {\n\t\tif (!ctx.chat) return;\n\n\t\tconst chat = ctx.chat;\n\t\tconst chatId = chat.id.toString();\n\n\t\t// Mark this chat as known\n\t\tthis.knownChats.set(chatId, chat);\n\n\t\t// Get chat title based on type\n\t\tlet chatTitle: string;\n\t\tlet channelType: ChannelType;\n\n\t\tswitch (chat.type) {\n\t\t\tcase 'private':\n\t\t\t\tchatTitle = `Chat with ${chat.first_name || 'Unknown User'}`;\n\t\t\t\tchannelType = ChannelType.DM;\n\t\t\t\tbreak;\n\t\t\tcase 'group':\n\t\t\t\tchatTitle = chat.title || 'Unknown Group';\n\t\t\t\tchannelType = ChannelType.GROUP;\n\t\t\t\tbreak;\n\t\t\tcase 'supergroup':\n\t\t\t\tchatTitle = chat.title || 'Unknown Supergroup';\n\t\t\t\tchannelType = ChannelType.GROUP;\n\t\t\t\tbreak;\n\t\t\tcase 'channel':\n\t\t\t\tchatTitle = chat.title || 'Unknown Channel';\n\t\t\t\tchannelType = ChannelType.FEED;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tchatTitle = 'Unknown Chat';\n\t\t\t\tchannelType = ChannelType.GROUP;\n\t\t}\n\n\t\t// Create standardized world data\n\t\tconst worldId = createUniqueUuid(this.runtime, chatId) as UUID;\n\t\tconst roomId = createUniqueUuid(this.runtime, chatId) as UUID;\n\n\t\t// Build world representation\n\t\tconst world: World = {\n\t\t\tid: worldId,\n\t\t\tname: chatTitle,\n\t\t\tagentId: this.runtime.agentId,\n\t\t\tserverId: chatId,\n\t\t\tmetadata: {\n\t\t\t\tsource: \"telegram\",\n\t\t\t\townership: { ownerId: chatId },\n\t\t\t\troles: {\n\t\t\t\t\t[chatId]: Role.OWNER,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\n\t\t// Build room representation\n\t\tconst room: Room = {\n\t\t\tid: roomId,\n\t\t\tname: chatTitle,\n\t\t\tsource: \"telegram\",\n\t\t\ttype: channelType,\n\t\t\tchannelId: chatId,\n\t\t\tserverId: chatId,\n\t\t\tworldId: worldId,\n\t\t};\n\n\t\t// Build users list\n\t\tconst users: Entity[] = [];\n\t\t// For private chats, add the user\n\t\tif (chat.type === 'private' && chat.id) {\n\t\t\tconst userId = createUniqueUuid(this.runtime, chat.id.toString()) as UUID;\n\t\t\tusers.push({\n\t\t\t\tid: userId,\n\t\t\t\tnames: [chat.first_name || 'Unknown User'],\n\t\t\t\tagentId: this.runtime.agentId,\n\t\t\t\tmetadata: {\n\t\t\t\t\ttelegram: {\n\t\t\t\t\t\tid: chat.id.toString(),\n\t\t\t\t\t\tusername: chat.username || 'unknown',\n\t\t\t\t\t\tname: chat.first_name || 'Unknown User',\n\t\t\t\t\t},\n\t\t\t\t\tsource: \"telegram\"\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (chat.type === 'group' || chat.type === 'supergroup') {\n\t\t\t// For groups and supergroups, try to get member information\n\t\t\ttry {\n\t\t\t\t// Get chat administrators (this is what's available through the Bot API)\n\t\t\t\tconst admins = await this.bot.telegram.getChatAdministrators(chat.id);\n\n\t\t\t\tif (admins && admins.length > 0) {\n\t\t\t\t\tfor (const admin of admins) {\n\t\t\t\t\t\tconst userId = createUniqueUuid(this.runtime, admin.user.id.toString()) as UUID;\n\t\t\t\t\t\tusers.push({\n\t\t\t\t\t\t\tid: userId,\n\t\t\t\t\t\t\tnames: [admin.user.first_name || admin.user.username || 'Unknown Admin'],\n\t\t\t\t\t\t\tagentId: this.runtime.agentId,\n\t\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\t\ttelegram: {\n\t\t\t\t\t\t\t\t\tid: admin.user.id.toString(),\n\t\t\t\t\t\t\t\t\tusername: admin.user.username || 'unknown',\n\t\t\t\t\t\t\t\t\tname: admin.user.first_name || 'Unknown Admin',\n\t\t\t\t\t\t\t\t\tisAdmin: true,\n\t\t\t\t\t\t\t\t\tadminTitle: admin.custom_title || (admin.status === 'creator' ? 'Owner' : 'Admin')\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tsource: \"telegram\",\n\t\t\t\t\t\t\t\troles: [admin.status === 'creator' ? Role.OWNER : Role.ADMIN]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Additionally, we can estimate member count\n\t\t\t\ttry {\n\t\t\t\t\tconst chatInfo = await this.bot.telegram.getChat(chat.id);\n\t\t\t\t\tif (chatInfo && 'member_count' in chatInfo) {\n\t\t\t\t\t\t// Store this information in the world metadata\n\t\t\t\t\t\tworld.metadata.memberCount = chatInfo.member_count;\n\t\t\t\t\t}\n\t\t\t\t} catch (countError) {\n\t\t\t\t\tlogger.warn(`Could not get member count for chat ${chatId}: ${countError}`);\n\t\t\t\t}\n\n\t\t\t} catch (error) {\n\t\t\t\tlogger.warn(`Could not fetch administrators for chat ${chatId}: ${error}`);\n\t\t\t}\n\t\t}\n\n\t\t// Create payload for world events\n\t\tconst worldPayload = {\n\t\t\truntime: this.runtime,\n\t\t\tworld,\n\t\t\trooms: [room],\n\t\t\tentities: users,\n\t\t\tsource: \"telegram\"\n\t\t};\n\n\t\t// Create Telegram-specific payload\n\t\tconst telegramWorldPayload = {\n\t\t\t...worldPayload,\n\t\t\tchat\n\t\t};\n\n\t\t// Emit generic WORLD_JOINED event\n\t\tthis.runtime.emitEvent(\n\t\t\tEventTypes.WORLD_JOINED,\n\t\t\tworldPayload\n\t\t);\n\n\t\t// Emit platform-specific WORLD_JOINED event\n\t\tthis.runtime.emitEvent(\n\t\t\tTelegramEventTypes.WORLD_JOINED,\n\t\t\ttelegramWorldPayload\n\t\t);\n\n\t\t// Set up a handler to track new entities as they interact with the chat\n\t\tif (chat.type === 'group' || chat.type === 'supergroup') {\n\t\t\tthis.setupEntityTracking(chat.id);\n\t\t}\n\t}\n\n\t/**\n\t * Sets up message and reaction handlers for the bot.\n\t *\n\t * @private\n\t * @returns {void}\n\t */\n\tprivate setupMessageHandlers(): void {\n\t\t// Regular message handler\n\t\tthis.bot.on(\"message\", async (ctx) => {\n\t\t\ttry {\n\t\t\t\tif (!(await this.isGroupAuthorized(ctx))) return;\n\t\t\t\tawait this.messageManager.handleMessage(ctx);\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error(\"Error handling message:\", error);\n\t\t\t}\n\t\t});\n\n\t\t// Reaction handler\n\t\tthis.bot.on(\"message_reaction\", async (ctx) => {\n\t\t\ttry {\n\t\t\t\tif (!(await this.isGroupAuthorized(ctx))) return;\n\t\t\t\tawait this.messageManager.handleReaction(ctx);\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error(\"Error handling reaction:\", error);\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Sets up tracking for new entities in a group chat to sync them as entities\n\t * @param {number} chatId - The Telegram chat ID to track entities for\n\t */\n\tprivate setupEntityTracking(chatId: number): void {\n\t\t// We'll maintain a set of entity IDs we've already synced\n\t\tconst syncedEntityIds = new Set<string>();\n\n\t\t// Add handler to track new message authors\n\t\tthis.bot.on('message', async (ctx) => {\n\t\t\tif (!ctx.chat || ctx.chat.id !== chatId || !ctx.from) return;\n\n\t\t\tconst entityId = ctx.from.id.toString();\n\t\t\tif (syncedEntityIds.has(entityId)) return;\n\n\t\t\t// Add to synced set to avoid duplicate processing\n\t\t\tsyncedEntityIds.add(entityId);\n\n\t\t\t// Sync this entity\n\t\t\tconst entityUuid = createUniqueUuid(this.runtime, entityId) as UUID;\n\t\t\tconst worldId = createUniqueUuid(this.runtime, chatId.toString()) as UUID;\n\t\t\tconst chatIdStr = chatId.toString();\n\n\t\t\ttry {\n\t\t\t\t// Create entity\n\t\t\t\tawait this.runtime.ensureConnection({\n\t\t\t\t\tentityId: entityUuid,\n\t\t\t\t\troomId: createUniqueUuid(this.runtime, chatIdStr),\n\t\t\t\t\tuserName: ctx.from.username || ctx.from.first_name || 'Unknown Entity',\n\t\t\t\t\tname: ctx.from.first_name || ctx.from.username || 'Unknown Entity',\n\t\t\t\t\tsource: \"telegram\",\n\t\t\t\t\tchannelId: chatIdStr,\n\t\t\t\t\tserverId: chatIdStr,\n\t\t\t\t\ttype: ChannelType.GROUP,\n\t\t\t\t\tworldId,\n\t\t\t\t});\n\n\t\t\t\t// Create entity joined payload\n\t\t\t\tconst entityJoinedPayload = {\n\t\t\t\t\truntime: this.runtime,\n\t\t\t\t\tentityId: entityUuid,\n\t\t\t\t\tentity: {\n\t\t\t\t\t\tid: entityId,\n\t\t\t\t\t\tusername: ctx.from.username || ctx.from.first_name || 'Unknown Entity',\n\t\t\t\t\t\tdisplayName: ctx.from.first_name || ctx.from.username || 'Unknown Entity'\n\t\t\t\t\t},\n\t\t\t\t\tworldId,\n\t\t\t\t\tsource: \"telegram\",\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tjoinedAt: Date.now()\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\t// Create Telegram-specific payload\n\t\t\t\tconst telegramEntityJoinedPayload = {\n\t\t\t\t\t...entityJoinedPayload,\n\t\t\t\t\ttelegramUser: {\n\t\t\t\t\t\tid: ctx.from.id,\n\t\t\t\t\t\tusername: ctx.from.username,\n\t\t\t\t\t\tfirst_name: ctx.from.first_name\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\t// Emit generic ENTITY_JOINED event\n\t\t\t\tthis.runtime.emitEvent(\n\t\t\t\t\tEventTypes.ENTITY_JOINED,\n\t\t\t\t\tentityJoinedPayload\n\t\t\t\t);\n\n\t\t\t\t// Emit platform-specific ENTITY_JOINED event\n\t\t\t\tthis.runtime.emitEvent(\n\t\t\t\t\tTelegramEventTypes.ENTITY_JOINED,\n\t\t\t\t\ttelegramEntityJoinedPayload\n\t\t\t\t);\n\n\t\t\t\tlogger.info(`Tracked new Telegram entity: ${ctx.from.username || ctx.from.first_name || entityId}`);\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error(`Error syncing new Telegram entity ${entityId} from chat ${chatId}:`, error);\n\t\t\t}\n\t\t});\n\n\t\t// Track when entities leave chat (from service message)\n\t\tthis.bot.on('left_chat_member', async (ctx) => {\n\t\t\tif (!ctx.message?.left_chat_member || ctx.chat?.id !== chatId) return;\n\n\t\t\tconst leftUser = ctx.message.left_chat_member;\n\t\t\tconst entityId = createUniqueUuid(this.runtime, leftUser.id.toString()) as UUID;\n\t\t\tconst chatIdStr = chatId.toString();\n\t\t\tconst worldId = createUniqueUuid(this.runtime, chatIdStr);\n\n\t\t\ttry {\n\t\t\t\t// Get the entity\n\t\t\t\tconst entity = await this.runtime.getEntityById(entityId);\n\t\t\t\tif (entity) {\n\t\t\t\t\t// Update entity metadata to show as inactive\n\t\t\t\t\tentity.metadata = {\n\t\t\t\t\t\t...entity.metadata,\n\t\t\t\t\t\tstatus: \"INACTIVE\",\n\t\t\t\t\t\tleftAt: Date.now(),\n\t\t\t\t\t};\n\t\t\t\t\tawait this.runtime.updateEntity(entity);\n\n\t\t\t\t\t// Create entity left payload\n\t\t\t\t\tconst entityLeftPayload = {\n\t\t\t\t\t\truntime: this.runtime,\n\t\t\t\t\t\tentityId,\n\t\t\t\t\t\tentity: {\n\t\t\t\t\t\t\tid: leftUser.id.toString(),\n\t\t\t\t\t\t\tusername: leftUser.username || leftUser.first_name || 'Unknown Entity',\n\t\t\t\t\t\t\tdisplayName: leftUser.first_name || leftUser.username || 'Unknown Entity'\n\t\t\t\t\t\t},\n\t\t\t\t\t\tworldId,\n\t\t\t\t\t\tsource: \"telegram\",\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\tleftAt: Date.now()\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\n\t\t\t\t\t// Create Telegram-specific payload\n\t\t\t\t\tconst telegramEntityLeftPayload = {\n\t\t\t\t\t\t...entityLeftPayload,\n\t\t\t\t\t\ttelegramUser: {\n\t\t\t\t\t\t\tid: leftUser.id,\n\t\t\t\t\t\t\tusername: leftUser.username,\n\t\t\t\t\t\t\tfirst_name: leftUser.first_name\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\n\t\t\t\t\t// Emit generic ENTITY_LEFT event\n\t\t\t\t\tthis.runtime.emitEvent(\n\t\t\t\t\t\tEventTypes.ENTITY_LEFT,\n\t\t\t\t\t\tentityLeftPayload\n\t\t\t\t\t);\n\n\t\t\t\t\t// Emit platform-specific ENTITY_LEFT event\n\t\t\t\t\tthis.runtime.emitEvent(\n\t\t\t\t\t\tTelegramEventTypes.ENTITY_LEFT,\n\t\t\t\t\t\ttelegramEntityLeftPayload\n\t\t\t\t\t);\n\n\t\t\t\t\tlogger.info(`Entity ${leftUser.username || leftUser.first_name || leftUser.id} left chat ${chatId}`);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error(`Error handling Telegram entity leaving chat ${chatId}:`, error);\n\t\t\t}\n\t\t});\n\t}\n}\n","import type { IAgentRuntime } from \"@elizaos/core\";\nimport { z } from \"zod\";\n\nexport const telegramEnvSchema = z.object({\n\tTELEGRAM_BOT_TOKEN: z.string().min(1, \"Telegram bot token is required\"),\n});\n\n/**\n * Represents the type definition for configuring a Telegram bot based on the inferred schema.\n */\nexport type TelegramConfig = z.infer<typeof telegramEnvSchema>;\n\n/**\n * Validates the Telegram configuration by retrieving the Telegram bot token from the runtime settings or environment variables.\n *\n * @param {IAgentRuntime} runtime - The agent runtime used to get the setting.\n * @returns {Promise<TelegramConfig>} A promise that resolves with the validated Telegram configuration.\n */\nexport async function validateTelegramConfig(\n\truntime: IAgentRuntime,\n): Promise<TelegramConfig> {\n\ttry {\n\t\tconst config = {\n\t\t\tTELEGRAM_BOT_TOKEN:\n\t\t\t\truntime.getSetting(\"TELEGRAM_BOT_TOKEN\") ||\n\t\t\t\tprocess.env.TELEGRAM_BOT_TOKEN,\n\t\t};\n\n\t\treturn telegramEnvSchema.parse(config);\n\t} catch (error) {\n\t\tif (error instanceof z.ZodError) {\n\t\t\tconst errorMessages = error.errors\n\t\t\t\t.map((err) => `${err.path.join(\".\")}: ${err.message}`)\n\t\t\t\t.join(\"\\n\");\n\t\t\tthrow new Error(\n\t\t\t\t`Telegram configuration validation failed:\\n${errorMessages}`,\n\t\t\t);\n\t\t}\n\t\tthrow error;\n\t}\n}\n","import {\n\tChannelType,\n\ttype Content,\n\tEventTypes,\n\ttype HandlerCallback,\n\ttype IAgentRuntime,\n\ttype Media,\n\ttype Memory,\n\tModelTypes,\n\ttype UUID,\n\tcreateUniqueUuid,\n\tlogger,\n} from \"@elizaos/core\";\nimport type { Chat, Message, ReactionType, Update } from \"@telegraf/types\";\nimport type { Context, NarrowedContext, Telegraf } from \"telegraf\";\nimport { TelegramEventTypes, type TelegramMessageReceivedPayload, type TelegramMessageSentPayload, type TelegramReactionReceivedPayload } from \"./types\";\nimport { escapeMarkdown } from \"./utils\";\n\nimport fs from \"node:fs\";\n\n/**\n * Enum representing different types of media.\n * @enum { string }\n * @readonly\n */\nexport enum MediaType {\n\tPHOTO = \"photo\",\n\tVIDEO = \"video\",\n\tDOCUMENT = \"document\",\n\tAUDIO = \"audio\",\n\tANIMATION = \"animation\",\n}\n\nconst MAX_MESSAGE_LENGTH = 4096; // Telegram's max message length\n\nconst getChannelType = (chat: Chat): ChannelType => {\n\tif (chat.type === \"private\") return ChannelType.DM;\n\tif (chat.type === \"supergroup\") return ChannelType.GROUP;\n\tif (chat.type === \"channel\") return ChannelType.GROUP;\n\tif (chat.type === \"group\") return ChannelType.GROUP;\n};\n\n/**\n * Class representing a message manager.\n * @class\n */\nexport class MessageManager {\n\tpublic bot: Telegraf<Context>;\n\tprotected runtime: IAgentRuntime;\n\n\t/**\n\t * Constructor for creating a new instance of a BotAgent.\n\t *\n\t * @param {Telegraf<Context>} bot - The Telegraf instance used for interacting with the bot platform.\n\t * @param {IAgentRuntime} runtime - The runtime environment for the agent.\n\t */\n\tconstructor(bot: Telegraf<Context>, runtime: IAgentRuntime) {\n\t\tthis.bot = bot;\n\t\tthis.runtime = runtime;\n\t}\n\n\t// Process image messages and generate descriptions\n\t/**\n\t * Process an image from a Telegram message to extract the image URL and description.\n\t *\n\t * @param {Message} message - The Telegram message object containing the image.\n\t * @returns {Promise<{ description: string } | null>} The description of the processed image or null if no image found.\n\t */\n\tasync processImage(\n\t\tmessage: Message,\n\t): Promise<{ description: string } | null> {\n\t\ttry {\n\t\t\tlet imageUrl: string | null = null;\n\n\t\t\tlogger.info(`Telegram Message: ${message}`);\n\n\t\t\tif (\"photo\" in message && message.photo?.length > 0) {\n\t\t\t\tconst photo = message.photo[message.photo.length - 1];\n\t\t\t\tconst fileLink = await this.bot.telegram.getFileLink(photo.file_id);\n\t\t\t\timageUrl = fileLink.toString();\n\t\t\t} else if (\n\t\t\t\t\"document\" in message &&\n\t\t\t\tmessage.document?.mime_type?.startsWith(\"image/\")\n\t\t\t) {\n\t\t\t\tconst fileLink = await this.bot.telegram.getFileLink(\n\t\t\t\t\tmessage.document.file_id,\n\t\t\t\t);\n\t\t\t\timageUrl = fileLink.toString();\n\t\t\t}\n\n\t\t\tif (imageUrl) {\n\t\t\t\tconst { title, description } = await this.runtime.useModel(\n\t\t\t\t\tModelTypes.IMAGE_DESCRIPTION,\n\t\t\t\t\timageUrl,\n\t\t\t\t);\n\t\t\t\treturn { description: `[Image: ${title}\\n${description}]` };\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error(\"❌ Error processing image:\", error);\n\t\t}\n\n\t\treturn null;\n\t}\n\n\t// Send long messages in chunks\n\t/**\n\t * Sends a message in chunks, handling attachments and splitting the message if necessary\n\t *\n\t * @param {Context} ctx - The context object representing the current state of the bot\n\t * @param {Content} content - The content of the message to be sent\n\t * @param {number} [replyToMessageId] - The ID of the message to reply to, if any\n\t * @returns {Promise<Message.TextMessage[]>} - An array of TextMessage objects representing the messages sent\n\t */\n\tasync sendMessageInChunks(\n\t\tctx: Context,\n\t\tcontent: Content,\n\t\treplyToMessageId?: number,\n\t): Promise<Message.TextMessage[]> {\n\t\tif (content.attachments && content.attachments.length > 0) {\n\t\t\tcontent.attachments.map(async (attachment: Media) => {\n\t\t\t\tconst typeMap: { [key: string]: MediaType } = {\n\t\t\t\t\t\"image/gif\": MediaType.ANIMATION,\n\t\t\t\t\timage: MediaType.PHOTO,\n\t\t\t\t\tdoc: MediaType.DOCUMENT,\n\t\t\t\t\tvideo: MediaType.VIDEO,\n\t\t\t\t\taudio: MediaType.AUDIO,\n\t\t\t\t};\n\n\t\t\t\tlet mediaType: MediaType | undefined = undefined;\n\n\t\t\t\tfor (const prefix in typeMap) {\n\t\t\t\t\tif (attachment.contentType.startsWith(prefix)) {\n\t\t\t\t\t\tmediaType = typeMap[prefix];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!mediaType) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Unsupported Telegram attachment content type: ${attachment.contentType}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tawait this.sendMedia(\n\t\t\t\t\tctx,\n\t\t\t\t\tattachment.url,\n\t\t\t\t\tmediaType,\n\t\t\t\t\tattachment.description,\n\t\t\t\t);\n\t\t\t});\n\t\t} else {\n\t\t\tconst chunks = this.splitMessage(content.text);\n\t\t\tconst sentMessages: Message.TextMessage[] = [];\n\n\t\t\tfor (let i = 0; i < chunks.length; i++) {\n\t\t\t\tconst chunk = escapeMarkdown(chunks[i]);\n\t\t\t\tconst sentMessage = (await ctx.telegram.sendMessage(\n\t\t\t\t\tctx.chat.id,\n\t\t\t\t\tchunk,\n\t\t\t\t\t{\n\t\t\t\t\t\treply_parameters:\n\t\t\t\t\t\t\ti === 0 && replyToMessageId\n\t\t\t\t\t\t\t\t? { message_id: replyToMessageId }\n\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\tparse_mode: \"Markdown\",\n\t\t\t\t\t},\n\t\t\t\t)) as Message.TextMessage;\n\n\t\t\t\tsentMessages.push(sentMessage);\n\t\t\t}\n\n\t\t\treturn sentMessages;\n\t\t}\n\t}\n\n\t/**\n\t * Sends media to a chat using the Telegram API.\n\t *\n\t * @param {Context} ctx - The context object containing information about the current chat.\n\t * @param {string} mediaPath - The path to the media to be sent, either a URL or a local file path.\n\t * @param {MediaType} type - The type of media being sent (PHOTO, VIDEO, DOCUMENT, AUDIO, or ANIMATION).\n\t * @param {string} [caption] - Optional caption for the media being sent.\n\t *\n\t * @returns {Promise<void>} A Promise that resolves when the media is successfully sent.\n\t */\n\tasync sendMedia(\n\t\tctx: Context,\n\t\tmediaPath: string,\n\t\ttype: MediaType,\n\t\tcaption?: string,\n\t): Promise<void> {\n\t\ttry {\n\t\t\tconst isUrl = /^(http|https):\\/\\//.test(mediaPath);\n\t\t\t// biome-ignore lint/complexity/noBannedTypes: <explanation>\n\t\t\tconst sendFunctionMap: Record<MediaType, Function> = {\n\t\t\t\t[MediaType.PHOTO]: ctx.telegram.sendPhoto.bind(ctx.telegram),\n\t\t\t\t[MediaType.VIDEO]: ctx.telegram.sendVideo.bind(ctx.telegram),\n\t\t\t\t[MediaType.DOCUMENT]: ctx.telegram.sendDocument.bind(ctx.telegram),\n\t\t\t\t[MediaType.AUDIO]: ctx.telegram.sendAudio.bind(ctx.telegram),\n\t\t\t\t[MediaType.ANIMATION]: ctx.telegram.sendAnimation.bind(ctx.telegram),\n\t\t\t};\n\n\t\t\tconst sendFunction = sendFunctionMap[type];\n\n\t\t\tif (!sendFunction) {\n\t\t\t\tthrow new Error(`Unsupported media type: ${type}`);\n\t\t\t}\n\n\t\t\tif (isUrl) {\n\t\t\t\t// Handle HTTP URLs\n\t\t\t\tawait sendFunction(ctx.chat.id, mediaPath, { caption });\n\t\t\t} else {\n\t\t\t\t// Handle local file paths\n\t\t\t\tif (!fs.existsSync(mediaPath)) {\n\t\t\t\t\tthrow new Error(`File not found at path: ${mediaPath}`);\n\t\t\t\t}\n\n\t\t\t\tconst fileStream = fs.createReadStream(mediaPath);\n\n\t\t\t\ttry {\n\t\t\t\t\tawait sendFunction(ctx.chat.id, { source: fileStream }, { caption });\n\t\t\t\t} finally {\n\t\t\t\t\tfileStream.destroy();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlogger.info(\n\t\t\t\t`${\n\t\t\t\t\ttype.charAt(0).toUpperCase() + type.slice(1)\n\t\t\t\t} sent successfully: ${mediaPath}`,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tlogger.error(\n\t\t\t\t`Failed to send ${type}. Path: ${mediaPath}. Error: ${error.message}`,\n\t\t\t);\n\t\t\tlogger.debug(error.stack);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t// Split message into smaller parts\n\t/**\n\t * Splits a given text into an array of strings based on the maximum message length.\n\t *\n\t * @param {string} text - The text to split into chunks.\n\t * @returns {string[]} An array of strings with each element representing a chunk of the original text.\n\t */\n\tprivate splitMessage(text: string): string[] {\n\t\tconst chunks: string[] = [];\n\t\tlet currentChunk = \"\";\n\n\t\tconst lines = text.split(\"\\n\");\n\t\tfor (const line of lines) {\n\t\t\tif (currentChunk.length + line.length + 1 <= MAX_MESSAGE_LENGTH) {\n\t\t\t\tcurrentChunk += (currentChunk ? \"\\n\" : \"\") + line;\n\t\t\t} else {\n\t\t\t\tif (currentChunk) chunks.push(currentChunk);\n\t\t\t\tcurrentChunk = line;\n\t\t\t}\n\t\t}\n\n\t\tif (currentChunk) chunks.push(currentChunk);\n\t\treturn chunks;\n\t}\n\n\t// Main handler for incoming messages\n\t/**\n\t * Handle incoming messages from Telegram and process them accordingly.\n\t * @param {Context} ctx - The context object containing information about the message.\n\t * @returns {Promise<void>}\n\t */\n\tpublic async handleMessage(ctx: Context): Promise<void> {\n\t\t// Type guard to ensure message exists\n\t\tif (!ctx.message || !ctx.from) return;\n\n\t\tconst message = ctx.message as Message.TextMessage;\n\n\t\ttry {\n\t\t\t// Convert IDs to UUIDs\n\t\t\tconst entityId = createUniqueUuid(\n\t\t\t\tthis.runtime,\n\t\t\t\tctx.from.id.toString(),\n\t\t\t) as UUID;\n\t\t\tconst userName =\n\t\t\t\tctx.from.username || ctx.from.first_name || \"Unknown User\";\n\t\t\tconst chatId = createUniqueUuid(this.runtime, ctx.chat?.id.toString());\n\t\t\tconst roomId = chatId;\n\n\t\t\t// Get message ID\n\t\t\tconst messageId = createUniqueUuid(\n\t\t\t\tthis.runtime,\n\t\t\t\tmessage?.message_id?.toString(),\n\t\t\t);\n\n\t\t\t// Handle images\n\t\t\tconst imageInfo = await this.processImage(message);\n\n\t\t\t// Get message text - use type guards for safety\n\t\t\tlet messageText = \"\";\n\t\t\tif (\"text\" in message && message.text) {\n\t\t\t\tmessageText = message.text;\n\t\t\t} else if (\"caption\" in message && message.caption) {\n\t\t\t\tmessageText = message.caption as string;\n\t\t\t}\n\n\t\t\t// Combine text and image description\n\t\t\tconst fullText = imageInfo\n\t\t\t\t? `${messageText} ${imageInfo.description}`\n\t\t\t\t: messageText;\n\t\t\tif (!fullText) return;\n\n\t\t\t// Get chat type and determine channel type\n\t\t\tconst chat = message.chat as Chat;\n\t\t\tconst channelType = getChannelType(chat);\n\n\t\t\t// Get world and room names\n\t\t\tconst worldName =\n\t\t\t\tchat.type === \"supergroup\"\n\t\t\t\t\t? (chat as Chat.SupergroupChat).title\n\t\t\t\t\t: chat.type === \"channel\"\n\t\t\t\t\t\t? (chat as Chat.ChannelChat).title\n\t\t\t\t\t\t: chat.type === \"private\"\n\t\t\t\t\t\t\t? `Chat with ${(chat as Chat.PrivateChat).first_name || 'Unknown'}`\n\t\t\t\t\t\t\t: \"Telegram\";\n\n\t\t\tconst roomName =\n\t\t\t\tchat.type === \"private\"\n\t\t\t\t\t? (chat as Chat.PrivateChat).first_name\n\t\t\t\t\t: chat.type === \"supergroup\"\n\t\t\t\t\t\t? (chat as Chat.SupergroupChat).title\n\t\t\t\t\t\t: chat.type === \"channel\"\n\t\t\t\t\t\t\t? (chat as Chat.ChannelChat).title\n\t\t\t\t\t\t\t: chat.type === \"group\"\n\t\t\t\t\t\t\t\t? (chat as Chat.GroupChat).title\n\t\t\t\t\t\t\t\t: \"Unknown Group\";\n\n\t\t\t// Create the standardized world ID for this chat\n\t\t\tconst worldId = createUniqueUuid(this.runtime, chat.id.toString());\n\n\t\t\t// Ensure entity connection\n\t\t\tawait this.runtime.ensureConnection({\n\t\t\t\tentityId,\n\t\t\t\troomId,\n\t\t\t\tuserName,\n\t\t\t\tname: userName,\n\t\t\t\tsource: \"telegram\",\n\t\t\t\tchannelId: ctx.chat.id.toString(),\n\t\t\t\tserverId: chat.id.toString(),\n\t\t\t\ttype: channelType,\n\t\t\t\tworldId: worldId\n\t\t\t});\n\n\t\t\t// Ensure room exists\n\t\t\tconst room = {\n\t\t\t\tid: roomId,\n\t\t\t\tname: roomName,\n\t\t\t\tsource: \"telegram\",\n\t\t\t\ttype: channelType,\n\t\t\t\tchannelId: ctx.chat.id.toString(),\n\t\t\t\tserverId: ctx.chat.id.toString(),\n\t\t\t\tworldId: worldId,\n\t\t\t};\n\t\t\t\n\t\t\tawait this.runtime.ensureRoomExists(room);\n\n\t\t\t// Create the memory object\n\t\t\tconst memory: Memory = {\n\t\t\t\tid: messageId,\n\t\t\t\tentityId,\n\t\t\t\tagentId: this.runtime.agentId,\n\t\t\t\troomId,\n\t\t\t\tcontent: {\n\t\t\t\t\ttext: fullText,\n\t\t\t\t\tsource: \"telegram\",\n\t\t\t\t\tchannelType: channelType,\n\t\t\t\t\tinReplyTo:\n\t\t\t\t\t\t\"reply_to_message\" in message && message.reply_to_message\n\t\t\t\t\t\t\t? createUniqueUuid(\n\t\t\t\t\t\t\t\t\tthis.runtime,\n\t\t\t\t\t\t\t\t\tmessage.reply_to_message.message_id.toString(),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t},\n\t\t\t\tcreatedAt: message.date * 1000,\n\t\t\t};\n\n\t\t\t// Create callback for handling responses\n\t\t\tconst callback: HandlerCallback = async (\n\t\t\t\tcontent: Content,\n\t\t\t\t_files?: string[],\n\t\t\t) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst sentMessages = await this.sendMessageInChunks(\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tcontent,\n\t\t\t\t\t\tmessage.message_id,\n\t\t\t\t\t);\n\n\t\t\t\t\tif (!sentMessages) return [];\n\n\t\t\t\t\tconst memories: Memory[] = [];\n\t\t\t\t\tfor (let i = 0; i < sentMessages.length; i++) {\n\t\t\t\t\t\tconst sentMessage = sentMessages[i];\n\t\t\t\t\t\tconst _isLastMessage = i === sentMessages.length - 1;\n\n\t\t\t\t\t\tconst responseMemory: Memory = {\n\t\t\t\t\t\t\tid: createUniqueUuid(\n\t\t\t\t\t\t\t\tthis.runtime,\n\t\t\t\t\t\t\t\tsentMessage.message_id.toString(),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tentityId: this.runtime.agentId,\n\t\t\t\t\t\t\tagentId: this.runtime.agentId,\n\t\t\t\t\t\t\troomId,\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t...content,\n\t\t\t\t\t\t\t\ttext: sentMessage.text,\n\t\t\t\t\t\t\t\tinReplyTo: messageId,\n\t\t\t\t\t\t\t\tchannelType: channelType,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tcreatedAt: sentMessage.date * 1000,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tawait this.runtime\n\t\t\t\t\t\t\t.getMemoryManager(\"messages\")\n\t\t\t\t\t\t\t.createMemory(responseMemory);\n\t\t\t\t\t\tmemories.push(responseMemory);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn memories;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tlogger.error(\"Error in message callback:\", error);\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t// Let the bootstrap plugin handle the message\n\t\t\tthis.runtime.emitEvent(\n\t\t\t\tEventTypes.MESSAGE_RECEIVED,\n\t\t\t\t{\n\t\t\t\t\truntime: this.runtime,\n\t\t\t\t\tmessage: memory,\n\t\t\t\t\tcallback,\n\t\t\t\t\tsource: \"telegram\"\n\t\t\t\t},\n\t\t\t);\n\t\t\t\n\t\t\t// Also emit the platform-specific event\n\t\t\tthis.runtime.emitEvent(\n\t\t\t\tTelegramEventTypes.MESSAGE_RECEIVED,\n\t\t\t\t{\n\t\t\t\t\truntime: this.runtime,\n\t\t\t\t\tmessage: memory,\n\t\t\t\t\tcallback,\n\t\t\t\t\tsource: \"telegram\",\n\t\t\t\t\tctx,\n\t\t\t\t\toriginalMessage: message\n\t\t\t\t} as TelegramMessageReceivedPayload\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tlogger.error(\"❌ Error handling message:\", error);\n\t\t\tlogger.error(\"Error sending message:\", error);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Handles the reaction event triggered by a user reacting to a message.\n\t * * @param {NarrowedContext<Context<Update>, Update.MessageReactionUpdate>} ctx The context of the message reaction update\n\t * @returns {Promise<void>} A Promise that resolves when the reaction handling is complete\n\t */\n\tpublic async handleReaction(\n\t\tctx: NarrowedContext<Context<Update>, Update.MessageReactionUpdate>,\n\t): Promise<void> {\n\t\t// Ensure we have the necessary data\n\t\tif (!ctx.update.message_reaction || !ctx.from) return;\n\n\t\tconst reaction = ctx.update.message_reaction;\n\t\tconst reactionType = reaction.new_reaction[0].type;\n\t\tconst reactionEmoji = (reaction.new_reaction[0] as ReactionType).type;\n\n\t\ttry {\n\t\t\tconst entityId = createUniqueUuid(\n\t\t\t\tthis.runtime,\n\t\t\t\tctx.from.id.toString(),\n\t\t\t) as UUID;\n\t\t\tconst roomId = createUniqueUuid(this.runtime, ctx.chat.id.toString());\n\t\t\tconst worldId = createUniqueUuid(this.runtime, ctx.chat.id.toString());\n\n\t\t\tconst reactionId = createUniqueUuid(\n\t\t\t\tthis.runtime,\n\t\t\t\t`${reaction.message_id}-${ctx.from.id}-${Date.now()}`,\n\t\t\t);\n\n\t\t\t// Create reaction memory\n\t\t\tconst memory: Memory = {\n\t\t\t\tid: reactionId,\n\t\t\t\tentityId,\n\t\t\t\tagentId: this.runtime.agentId,\n\t\t\t\troomId,\n\t\t\t\tcontent: {\n\t\t\t\t\tchannelType: getChannelType(reaction.chat as Chat),\n\t\t\t\t\ttext: `Reacted with: ${reactionType === \"emoji\" ? reactionEmoji : reactionType}`,\n\t\t\t\t\tsource: \"telegram\",\n\t\t\t\t\tinReplyTo: createUniqueUuid(\n\t\t\t\t\t\tthis.runtime,\n\t\t\t\t\t\treaction.message_id.toString(),\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t\tcreatedAt: Date.now(),\n\t\t\t};\n\n\t\t\t// Create callback for handling reaction responses\n\t\t\tconst callback: HandlerCallback = async (content: Content) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst sentMessage = await ctx.reply(content.text);\n\t\t\t\t\tconst responseMemory: Memory = {\n\t\t\t\t\t\tid: createUniqueUuid(\n\t\t\t\t\t\t\tthis.runtime,\n\t\t\t\t\t\t\tsentMessage.message_id.toString(),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tentityId: this.runtime.agentId,\n\t\t\t\t\t\tagentId: this.runtime.agentId,\n\t\t\t\t\t\troomId,\n\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t...content,\n\t\t\t\t\t\t\tinReplyTo: reactionId,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcreatedAt: sentMessage.date * 1000,\n\t\t\t\t\t};\n\t\t\t\t\treturn [responseMemory];\n\t\t\t\t} catch (error) {\n\t\t\t\t\tlogger.error(\"Error in reaction callback:\", error);\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t// Let the bootstrap plugin handle the reaction\n\t\t\tthis.runtime.emitEvent(\n\t\t\t\tEventTypes.REACTION_RECEIVED,\n\t\t\t\t{\n\t\t\t\t\truntime: this.runtime,\n\t\t\t\t\tmessage: memory,\n\t\t\t\t\tcallback,\n\t\t\t\t\tsource: \"telegram\"\n\t\t\t\t},\n\t\t\t);\n\t\t\t\n\t\t\t// Also emit the platform-specific event\n\t\t\tthis.runtime.emitEvent(\n\t\t\t\tTelegramEventTypes.REACTION_RECEIVED,\n\t\t\t\t{\n\t\t\t\t\truntime: this.runtime,\n\t\t\t\t\tmessage: memory,\n\t\t\t\t\tcallback,\n\t\t\t\t\tsource: \"telegram\",\n\t\t\t\t\tctx,\n\t\t\t\t\treactionString: reactionType === \"emoji\" ? reactionEmoji : reactionType,\n\t\t\t\t\toriginalReaction: reaction.new_reaction[0] as ReactionType\n\t\t\t\t} as TelegramReactionReceivedPayload\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tlogger.error(\"Error handling reaction:\", error);\n\t\t}\n\t}\n\n\t/**\n\t * Sends a message to a Telegram chat and emits appropriate events\n\t * @param {number | string} chatId - The Telegram chat ID to send the message to\n\t * @param {Content} content - The content to send\n\t * @param {number} [replyToMessageId] - Optional message ID to reply to\n\t * @returns {Promise<Message.TextMessage[]>} The sent messages\n\t */\n\tpublic async sendMessage(\n\t\tchatId: number | string,\n\t\tcontent: Content,\n\t\treplyToMessageId?: number\n\t): Promise<Message.TextMessage[]> {\n\t\ttry {\n\t\t\t// Create a context-like object for sending\n\t\t\tconst ctx = { \n\t\t\t\tchat: { id: chatId },\n\t\t\t\ttelegram: this.bot.telegram\n\t\t\t};\n\t\t\t\n\t\t\tconst sentMessages = await this.sendMessageInChunks(\n\t\t\t\tctx as Context,\n\t\t\t\tcontent,\n\t\t\t\treplyToMessageId\n\t\t\t);\n\n\t\t\tif (!sentMessages?.length) return [];\n\n\t\t\t// Create room ID\n\t\t\tconst roomId = createUniqueUuid(this.runtime, chatId.toString());\n\t\t\t\n\t\t\t// Create memories for the sent messages\n\t\t\tconst memories: Memory[] = [];\n\t\t\tfor (const sentMessage of sentMessages) {\n\t\t\t\tconst memory: Memory = {\n\t\t\t\t\tid: createUniqueUuid(this.runtime, sentMessage.message_id.toString()),\n\t\t\t\t\tentityId: this.runtime.agentId,\n\t\t\t\t\tagentId: this.runtime.agentId,\n\t\t\t\t\troomId,\n\t\t\t\t\tcontent: {\n\t\t\t\t\t\t...content,\n\t\t\t\t\t\ttext: sentMessage.text,\n\t\t\t\t\t\tsource: \"telegram\",\n\t\t\t\t\t\tchannelType: getChannelType({ \n\t\t\t\t\t\t\tid: typeof chatId === 'string' ? Number.parseInt(chatId, 10) : chatId,\n\t\t\t\t\t\t\ttype: \"private\" // Default to private, will be overridden if in context\n\t\t\t\t\t\t} as Chat)\n\t\t\t\t\t},\n\t\t\t\t\tcreatedAt: sentMessage.date * 1000\n\t\t\t\t};\n\t\t\t\t\n\t\t\t\tawait this.runtime.getMemoryManager(\"messages\").createMemory(memory);\n\t\t\t\tmemories.push(memory);\n\t\t\t}\n\n\t\t\t// Emit both generic and platform-specific message sent events\n\t\t\tthis.runtime.emitEvent(\n\t\t\t\tEventTypes.MESSAGE_SENT,\n\t\t\t\t{\n\t\t\t\t\truntime: this.runtime,\n\t\t\t\t\tmessages: memories,\n\t\t\t\t\troomId,\n\t\t\t\t\tsource: \"telegram\"\n\t\t\t\t},\n\t\t\t);\n\t\t\t\n\t\t\t// Also emit platform-specific event\n\t\t\tthis.runtime.emitEvent(\n\t\t\t\tTelegramEventTypes.MESSAGE_SENT,\n\t\t\t\t{\n\t\t\t\t\toriginalMessages: sentMessages,\n\t\t\t\t\tchatId\n\t\t\t\t} as TelegramMessageSentPayload\n\t\t\t);\n\t\t\t\n\t\t\treturn sentMessages;\n\t\t} catch (error) {\n\t\t\tlogger.error(\"Error sending message to Telegram:\", error);\n\t\t\treturn [];\n\t\t}\n\t}\n}\n","/**\n * Escapes Markdown special characters in the given text, excluding code blocks.\n * @param {string} text - The text to escape Markdown characters from.\n * @returns {string} The text with escaped Markdown characters.\n */\nexport function escapeMarkdown(text: string): string {\n\t// Don't escape if it's a code block\n\tif (text.startsWith(\"```\") && text.endsWith(\"```\")) {\n\t\treturn text;\n\t}\n\n\t// Split the text by code blocks\n\tconst parts = text.split(/(```[\\s\\S]*?```)/g);\n\n\treturn parts\n\t\t.map((part, index) => {\n\t\t\t// If it's a code block (odd indices in the split result will be code blocks)\n\t\t\tif (index % 2 === 1) {\n\t\t\t\treturn part;\n\t\t\t}\n\t\t\t// For regular text, only escape characters that need escaping in Markdown\n\t\t\treturn (\n\t\t\t\tpart\n\t\t\t\t\t// First preserve any intended inline code spans\n\t\t\t\t\t.replace(/`.*?`/g, (match) => match)\n\t\t\t\t\t// Then only escape the minimal set of special characters that need escaping in Markdown mode\n\t\t\t\t\t.replace(/([*_`\\\\])/g, \"\\\\$1\")\n\t\t\t);\n\t\t})\n\t\t.join(\"\");\n}\n\n/**\n * Splits a message into chunks that fit within Telegram's message length limit\n */\n/**\n * Splits a text message into chunks based on a maximum length for each chunk.\n *\n * @param {string} text - The text message to split.\n * @param {number} maxLength - The maximum length for each chunk (default is 4096).\n * @returns {string[]} An array containing the text message split into chunks.\n */\nexport function splitMessage(text: string, maxLength = 4096): string[] {\n\tconst chunks: string[] = [];\n\tlet currentChunk = \"\";\n\n\tconst lines = text.split(\"\\n\");\n\tfor (const line of lines) {\n\t\tif (currentChunk.length + line.length + 1 <= maxLength) {\n\t\t\tcurrentChunk += (currentChunk ? \"\\n\" : \"\") + line;\n\t\t} else {\n\t\t\tif (currentChunk) chunks.push(currentChunk);\n\t\t\tcurrentChunk = line;\n\t\t}\n\t}\n\n\tif (currentChunk) chunks.push(currentChunk);\n\treturn chunks;\n}\n","import { type IAgentRuntime, type TestSuite, logger } from \"@elizaos/core\";\nimport type { Chat, User } from \"@telegraf/types\";\nimport type { Telegraf } from \"telegraf\";\nimport type { Context } from \"telegraf\";\nimport type { MessageManager } from \"./messageManager\";\nimport type { TelegramService } from \"./service\";\n\nconst TEST_IMAGE_URL =\n\t\"https://github.com/elizaOS/awesome-eliza/blob/main/assets/eliza-logo.jpg?raw=true\";\n\n/**\n * Represents a test suite for testing Telegram functionality.\n *\n * This test suite includes methods to initialize and validate a Telegram bot connection,\n * send basic text messages to a Telegram chat, send text messages with image attachments,\n * handle and process incoming Telegram messages, and process and validate image attachments\n * in incoming messages.\n *\n * @implements {TestSuite}\n */\n\nexport class TelegramTestSuite implements TestSuite {\n\tname = \"telegram\";\n\tprivate telegramClient: TelegramService = null;\n\tprivate bot: Telegraf<Context> | null = null;\n\tprivate messageManager: MessageManager | null = null;\n\ttests: { name: string; fn: (runtime: IAgentRuntime) => Promise<void> }[];\n\n\t/**\n\t * Constructor for initializing a set of test cases for a Telegram bot.\n\t *\n\t * @constructor\n\t * @property {Array<Object>} tests - An array of test cases with name and corresponding test functions.\n\t * @property {string} tests.name - The name of the test case.\n\t * @property {function} tests.fn - The test function to be executed.\n\t */\n\tconstructor() {\n\t\tthis.tests = [\n\t\t\t{\n\t\t\t\tname: \"Initialize and Validate Telegram Bot Connection\",\n\t\t\t\tfn: this.testCreatingTelegramBot.bind(this),\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: \"Send Basic Text Message to Telegram Chat\",\n\t\t\t\tfn: this.testSendingTextMessage.bind(this),\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: \"Send Text Message with an Image Attachment\",\n\t\t\t\tfn: this.testSendingMessageWithAttachment.bind(this),\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: \"Handle and Process Incoming Telegram Messages\",\n\t\t\t\tfn: this.testHandlingMessage.bind(this),\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: \"Process and Validate Image Attachments in Incoming Messages\",\n\t\t\t\tfn: this.testProcessingImages.bind(this),\n\t\t\t},\n\t\t];\n\t}\n\n\t/**\n\t * Retrieves the Telegram test chat ID from environment variables.\n\t *\n\t * Reference on getting the Telegram chat ID:\n\t * https://stackoverflow.com/a/32572159\n\t */\n\t/**\n\t * Validates the chat ID by checking if it is set in the runtime settings or environment variables.\n\t * If not set, an error is thrown with a message instructing to provide a valid chat ID.\n\t * @param {IAgentRuntime} runtime - The runtime object that provides access to the settings and environment variables.\n\t * @throws {Error} If TELEGRAM_TEST_CHAT_ID is not set in the runtime settings or environment variables.\n\t * @returns {string} The validated chat ID.\n\t */\n\tvalidateChatId(runtime: IAgentRuntime) {\n\t\tconst testChatId =\n\t\t\truntime.getSetting(\"TELEGRAM_TEST_CHAT_ID\") ||\n\t\t\tprocess.env.TELEGRAM_TEST_CHAT_ID;\n\t\tif (!testChatId) {\n\t\t\tthrow new Error(\n\t\t\t\t\"TELEGRAM_TEST_CHAT_ID is not set. Please provide a valid chat ID in the environment variables.\",\n\t\t\t);\n\t\t}\n\t\treturn testChatId;\n\t}\n\n\tasync getChatInfo(runtime: IAgentRuntime): Promise<Context[\"chat\"]> {\n\t\ttry {\n\t\t\tconst chatId = this.validateChatId(runtime);\n\t\t\tconst chat = await this.bot.telegram.getChat(chatId);\n\t\t\tlogger.log(`Fetched real chat: ${JSON.stringify(chat)}`);\n\t\t\treturn chat;\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Error fetching real Telegram chat: ${error}`);\n\t\t}\n\t}\n\n\tasync testCreatingTelegramBot(runtime: IAgentRuntime) {\n\t\tthis.telegramClient = runtime.getService(\"telegram\") as TelegramService;\n\t\tthis.bot = this.telegramClient.messageManager.bot;\n\t\tthis.messageManager = this.telegramClient.messageManager;\n\t\tlogger.success(\"Telegram bot initialized successfully.\");\n\t}\n\n\tasync testSendingTextMessage(runtime: IAgentRuntime) {\n\t\ttry {\n\t\t\tif (!this.bot) throw new Error(\"Bot not initialized.\");\n\n\t\t\tconst chatId = this.validateChatId(runtime);\n\t\t\tawait this.bot.telegram.sendMessage(chatId, \"Testing Telegram message!\");\n\t\t\tlogger.success(\"Message sent successfully.\");\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Error sending Telegram message: ${error}`);\n\t\t}\n\t}\n\n\tasync testSendingMessageWithAttachment(runtime: IAgentRuntime) {\n\t\ttry {\n\t\t\tif (!this.messageManager)\n\t\t\t\tthrow new Error(\"MessageManager not initialized.\");\n\n\t\t\tconst chat = await this.getChatInfo(runtime);\n\t\t\tconst mockContext: Partial<Context> = {\n\t\t\t\tchat,\n\t\t\t\tfrom: { id: 123, username: \"TestUser\" } as User,\n\t\t\t\ttelegram: this.bot.telegram,\n\t\t\t};\n\n\t\t\tconst messageContent = {\n\t\t\t\ttext: \"Here is an image attachment:\",\n\t\t\t\tattachments: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"123\",\n\t\t\t\t\t\ttitle: \"Sample Image\",\n\t\t\t\t\t\tsource: TEST_IMAGE_URL,\n\t\t\t\t\t\ttext: \"Sample Image\",\n\t\t\t\t\t\turl: TEST_IMAGE_URL,\n\t\t\t\t\t\tcontentType: \"image/png\",\n\t\t\t\t\t\tdescription: \"Sample Image\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\n\t\t\tawait this.messageManager.sendMessageInChunks(\n\t\t\t\tmockContext as Context,\n\t\t\t\tmessageContent,\n\t\t\t);\n\n\t\t\tlogger.success(\"Message with image attachment sent successfully.\");\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t`Error sending Telegram message with attachment: ${error}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tasync testHandlingMessage(runtime: IAgentRuntime) {\n\t\ttry {\n\t\t\tconst chat = await this.getChatInfo(runtime);\n\t\t\tconst mockContext: Partial<Context> = {\n\t\t\t\tchat,\n\t\t\t\tfrom: {\n\t\t\t\t\tid: 123,\n\t\t\t\t\tusername: \"TestUser\",\n\t\t\t\t\tis_bot: false,\n\t\t\t\t\tfirst_name: \"Test\",\n\t\t\t\t\tlast_name: \"User\",\n\t\t\t\t} as User,\n\t\t\t\tmessage: {\n\t\t\t\t\tmessage_id: undefined,\n\t\t\t\t\ttext: `@${this.bot.botInfo?.username}! Hello!`,\n\t\t\t\t\tdate: Math.floor(Date.now() / 1000),\n\t\t\t\t\tchat,\n\t\t\t\t\t// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n\t\t\t\t} as any,\n\t\t\t\ttelegram: this.bot.telegram,\n\t\t\t};\n\n\t\t\ttry {\n\t\t\t\tawait this.messageManager.handleMessage(mockContext as Context);\n\t\t\t} catch (error) {\n\t\t\t\tthrow new Error(`Error handling Telegram message: ${error}`);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Error handling Telegram message: ${error}`);\n\t\t}\n\t}\n\n\tasync testProcessingImages(runtime: IAgentRuntime) {\n\t\ttry {\n\t\t\tconst chatId = this.validateChatId(runtime);\n\t\t\tconst fileId = await this.getFileId(chatId, TEST_IMAGE_URL);\n\n\t\t\tconst mockMessage = {\n\t\t\t\tmessage_id: undefined,\n\t\t\t\tchat: { id: chatId } as Chat,\n\t\t\t\tdate: Math.floor(Date.now() / 1000),\n\t\t\t\tphoto: [{ file_id: fileId }],\n\t\t\t\ttext: `@${this.bot.botInfo?.username}!`,\n\t\t\t};\n\n\t\t\tconst { description } =\n\t\t\t\tawait this.messageManager.processImage(mockMessage);\n\t\t\tif (!description) {\n\t\t\t\tthrow new Error(\"Error processing Telegram image\");\n\t\t\t}\n\t\t\tlogger.log(`Processing Telegram image successfully: ${description}`);\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Error processing Telegram image: ${error}`);\n\t\t}\n\t}\n\n\tasync getFileId(chatId: string, imageUrl: string) {\n\t\ttry {\n\t\t\tconst message = await this.bot.telegram.sendPhoto(chatId, imageUrl);\n\t\t\treturn message.photo[message.photo.length - 1].file_id;\n\t\t} catch (error) {\n\t\t\tlogger.error(`Error sending image: ${error}`);\n\t\t\tthrow error;\n\t\t}\n\t}\n}\n","import type { Plugin } from \"@elizaos/core\";\nimport { TELEGRAM_SERVICE_NAME } from \"./constants\";\nimport { TelegramService } from \"./service\";\nimport { TelegramTestSuite } from \"./tests\";\n\nconst telegramPlugin: Plugin = {\n\tname: TELEGRAM_SERVICE_NAME,\n\tdescription: \"Telegram client plugin\",\n\tservices: [TelegramService],\n\ttests: [new TelegramTestSuite()],\n};\nexport default telegramPlugin;\n"],"mappings":";AAAO,IAAM,oBAAoB;AAAA,EAChC,cAAc;AAAA,EACd,sBAAsB;AAAA,EACtB,oBAAoB;AAAA,EACpB,8BAA8B;AAAA,EAC9B,yCAAyC;AAAA,EACzC,qBAAqB,IAAI,KAAK;AAAA;AAAA,EAC9B,wBAAwB,IAAI,KAAK;AAAA;AAClC;AAEO,IAAM,wBAAwB;;;ACVrC,SAAS,eAAAA,cAA0B,cAAAC,aAAgC,MAAiB,SAAgC,oBAAAC,mBAAkB,UAAAC,eAAc;AACpJ,SAAuB,gBAAgB;;;ACAvC,SAAS,SAAS;AAEX,IAAM,oBAAoB,EAAE,OAAO;AAAA,EACzC,oBAAoB,EAAE,OAAO,EAAE,IAAI,GAAG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","createUniqueUuid","EventTypes","logger"]}
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts","../src/service.ts","../src/environment.ts","../src/messageManager.ts","../src/utils.ts","../src/tests.ts","../src/index.ts"],"sourcesContent":["export const MESSAGE_CONSTANTS = {\n\tMAX_MESSAGES: 50,\n\tRECENT_MESSAGE_COUNT: 5,\n\tCHAT_HISTORY_COUNT: 10,\n\tDEFAULT_SIMILARITY_THRESHOLD: 0.6,\n\tDEFAULT_SIMILARITY_THRESHOLD_FOLLOW_UPS: 0.4,\n\tINTEREST_DECAY_TIME: 5 * 60 * 1000, // 5 minutes\n\tPARTIAL_INTEREST_DECAY: 3 * 60 * 1000, // 3 minutes\n} as const;\n\nexport const TELEGRAM_SERVICE_NAME = \"telegram\";\n","import { ChannelType, type Entity, EventTypes, type IAgentRuntime, Role, type Room, Service, type UUID, type World, createUniqueUuid, logger } from \"@elizaos/core\";\nimport { type Context, Telegraf } from \"telegraf\";\nimport { TELEGRAM_SERVICE_NAME } from \"./constants\";\nimport { validateTelegramConfig } from \"./environment\";\nimport { MessageManager } from \"./messageManager\";\nimport { TelegramEventTypes } from \"./types\";\n\n/**\n * Class representing a Telegram service that allows the agent to send and receive messages on Telegram.\n * @extends Service\n */\n\nexport class TelegramService extends Service {\n\tstatic serviceType = TELEGRAM_SERVICE_NAME;\n\tcapabilityDescription = \"The agent is able to send and receive messages on telegram\";\n\tprivate bot: Telegraf<Context>;\n\tpublic messageManager: MessageManager;\n\tprivate options;\n\tprivate knownChats: Map<string, any> = new Map();\n\n\t/**\n\t * Constructor for TelegramService class.\n\t * @param {IAgentRuntime} runtime - The runtime object for the agent.\n\t */\n\tconstructor(runtime: IAgentRuntime) {\n\t\tsuper(runtime);\n\t\tlogger.log(\"📱 Constructing new TelegramService...\");\n\t\tthis.options = {\n\t\t\ttelegram: {\n\t\t\t\tapiRoot: runtime.getSetting(\"TELEGRAM_API_ROOT\") ||\n\t\t\t\t\tprocess.env.TELEGRAM_API_ROOT ||\n\t\t\t\t\t\"https://api.telegram.org\",\n\t\t\t},\n\t\t};\n\t\tconst botToken = runtime.getSetting(\"TELEGRAM_BOT_TOKEN\");\n\t\tthis.bot = new Telegraf(botToken, this.options);\n\t\tthis.messageManager = new MessageManager(this.bot, this.runtime);\n\t\tlogger.log(\"✅ TelegramService constructor completed\");\n\t}\n\n\t/**\n\t * Starts the Telegram service for the given runtime.\n\t *\n\t * @param {IAgentRuntime} runtime - The agent runtime to start the Telegram service for.\n\t * @returns {Promise<TelegramService>} A promise that resolves with the initialized TelegramService.\n\t */\n\tstatic async start(runtime: IAgentRuntime): Promise<TelegramService> {\n\t\tawait validateTelegramConfig(runtime);\n\n\t\tconst maxRetries = 5;\n\t\tlet retryCount = 0;\n\t\tlet lastError: Error | null = null;\n\n\t\twhile (retryCount < maxRetries) {\n\t\t\ttry {\n\t\t\t\tconst service = new TelegramService(runtime);\n\n\t\t\t\tlogger.success(\n\t\t\t\t\t`✅ Telegram client successfully started for character ${runtime.character.name}`\n\t\t\t\t);\n\n\t\t\t\tlogger.log(\"🚀 Starting Telegram bot...\");\n\t\t\t\tawait service.initializeBot();\n\t\t\t\tservice.setupMessageHandlers();\n\n\t\t\t\t// Wait for bot to be ready by testing getMe()\n\t\t\t\tawait service.bot.telegram.getMe();\n\n\t\t\t\treturn service;\n\t\t\t} catch (error) {\n\t\t\t\tlastError = error instanceof Error ? error : new Error(String(error));\n\t\t\t\tlogger.error(`Telegram initialization attempt ${retryCount + 1} failed: ${lastError.message}`);\n\t\t\t\tretryCount++;\n\n\t\t\t\tif (retryCount < maxRetries) {\n\t\t\t\t\tconst delay = 2 ** retryCount * 1000; // Exponential backoff\n\t\t\t\t\tlogger.info(`Retrying Telegram initialization in ${delay / 1000} seconds...`);\n\t\t\t\t\tawait new Promise(resolve => setTimeout(resolve, delay));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthrow new Error(`Telegram initialization failed after ${maxRetries} attempts. Last error: ${lastError?.message}`);\n\t}\n\n\t/**\n\t * Stops the agent runtime.\n\t * @param {IAgentRuntime} runtime - The agent runtime to stop\n\t */\n\tstatic async stop(runtime: IAgentRuntime) {\n\t\t// Implement shutdown if necessary\n\t\tconst tgClient = runtime.getService(TELEGRAM_SERVICE_NAME);\n\t\tif (tgClient) {\n\t\t\tawait tgClient.stop();\n\t\t}\n\t}\n\n\t/**\n\t * Asynchronously stops the bot.\n\t *\n\t * @returns A Promise that resolves once the bot has stopped.\n\t */\n\tasync stop(): Promise<void> {\n\t\tthis.bot.stop();\n\t}\n\n\t/**\n\t * Initializes the Telegram bot by launching it, getting bot info, and setting up message manager.\n\t * @returns {Promise<void>} A Promise that resolves when the initialization is complete.\n\t */\n\tprivate async initializeBot(): Promise<void> {\n\t\tthis.bot.launch({\n\t\t\tdropPendingUpdates: true,\n\t\t\tallowedUpdates: [\"message\", \"message_reaction\"],\n\t\t});\n\n\t\t// Get bot info for identification purposes\n\t\tconst botInfo = await this.bot.telegram.getMe();\n\t\tlogger.log(`Bot info: ${JSON.stringify(botInfo)}`);\n\n\t\t// Handle sigint and sigterm signals to gracefully stop the bot\n\t\tprocess.once(\"SIGINT\", () => this.bot.stop(\"SIGINT\"));\n\t\tprocess.once(\"SIGTERM\", () => this.bot.stop(\"SIGTERM\"));\n\t}\n\n\t/**\n\t * Checks if a group is authorized, based on the TELEGRAM_ALLOWED_CHATS setting.\n\t * @param {Context} ctx - The context of the incoming update.\n\t * @returns {Promise<boolean>} A Promise that resolves with a boolean indicating if the group is authorized.\n\t */\n\tprivate async isGroupAuthorized(ctx: Context): Promise<boolean> {\n\t\tconst chatId = ctx.chat?.id.toString();\n\t\tif (!chatId) return false;\n\n\t\t// If this is a chat we haven't seen before, emit WORLD_JOINED event\n\t\tif (!this.knownChats.has(chatId)) {\n\t\t\tawait this.handleNewChat(ctx);\n\t\t}\n\n\t\tconst allowedChats = this.runtime.getSetting(\"TELEGRAM_ALLOWED_CHATS\");\n\t\tif (!allowedChats) {\n\t\t\treturn true; // All chats are allowed if no restriction is set\n\t\t}\n\n\t\ttry {\n\t\t\tconst allowedChatsList = JSON.parse(allowedChats as string);\n\t\t\treturn allowedChatsList.includes(chatId);\n\t\t} catch (error) {\n\t\t\tlogger.error(\"Error parsing TELEGRAM_ALLOWED_CHATS:\", error);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Handles new chat discovery and emits WORLD_JOINED event\n\t * @param {Context} ctx - The context of the incoming update\n\t */\n\tprivate async handleNewChat(ctx: Context): Promise<void> {\n\t\tif (!ctx.chat) return;\n\n\t\tconst chat = ctx.chat;\n\t\tconst chatId = chat.id.toString();\n\n\t\t// Mark this chat as known\n\t\tthis.knownChats.set(chatId, chat);\n\n\t\t// Get chat title based on type\n\t\tlet chatTitle: string;\n\t\tlet channelType: ChannelType;\n\n\t\tswitch (chat.type) {\n\t\t\tcase 'private':\n\t\t\t\tchatTitle = `Chat with ${chat.first_name || 'Unknown User'}`;\n\t\t\t\tchannelType = ChannelType.DM;\n\t\t\t\tbreak;\n\t\t\tcase 'group':\n\t\t\t\tchatTitle = chat.title || 'Unknown Group';\n\t\t\t\tchannelType = ChannelType.GROUP;\n\t\t\t\tbreak;\n\t\t\tcase 'supergroup':\n\t\t\t\tchatTitle = chat.title || 'Unknown Supergroup';\n\t\t\t\tchannelType = ChannelType.GROUP;\n\t\t\t\tbreak;\n\t\t\tcase 'channel':\n\t\t\t\tchatTitle = chat.title || 'Unknown Channel';\n\t\t\t\tchannelType = ChannelType.FEED;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tchatTitle = 'Unknown Chat';\n\t\t\t\tchannelType = ChannelType.GROUP;\n\t\t}\n\n\t\t// Create standardized world data\n\t\tconst worldId = createUniqueUuid(this.runtime, chatId) as UUID;\n\t\tconst roomId = createUniqueUuid(this.runtime, chatId) as UUID;\n\n\t\t// Build world representation\n\t\tconst world: World = {\n\t\t\tid: worldId,\n\t\t\tname: chatTitle,\n\t\t\tagentId: this.runtime.agentId,\n\t\t\tserverId: chatId,\n\t\t\tmetadata: {\n\t\t\t\tsource: \"telegram\",\n\t\t\t\townership: { ownerId: chatId },\n\t\t\t\troles: {\n\t\t\t\t\t[chatId]: Role.OWNER,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\n\t\t// Build room representation\n\t\tconst room: Room = {\n\t\t\tid: roomId,\n\t\t\tname: chatTitle,\n\t\t\tsource: \"telegram\",\n\t\t\ttype: channelType,\n\t\t\tchannelId: chatId,\n\t\t\tserverId: chatId,\n\t\t\tworldId: worldId,\n\t\t};\n\n\t\t// Build users list\n\t\tconst users: Entity[] = [];\n\t\t// For private chats, add the user\n\t\tif (chat.type === 'private' && chat.id) {\n\t\t\tconst userId = createUniqueUuid(this.runtime, chat.id.toString()) as UUID;\n\t\t\tusers.push({\n\t\t\t\tid: userId,\n\t\t\t\tnames: [chat.first_name || 'Unknown User'],\n\t\t\t\tagentId: this.runtime.agentId,\n\t\t\t\tmetadata: {\n\t\t\t\t\ttelegram: {\n\t\t\t\t\t\tid: chat.id.toString(),\n\t\t\t\t\t\tusername: chat.username || 'unknown',\n\t\t\t\t\t\tname: chat.first_name || 'Unknown User',\n\t\t\t\t\t},\n\t\t\t\t\tsource: \"telegram\"\n\t\t\t\t}\n\t\t\t});\n\t\t} else if (chat.type === 'group' || chat.type === 'supergroup') {\n\t\t\t// For groups and supergroups, try to get member information\n\t\t\ttry {\n\t\t\t\t// Get chat administrators (this is what's available through the Bot API)\n\t\t\t\tconst admins = await this.bot.telegram.getChatAdministrators(chat.id);\n\n\t\t\t\tif (admins && admins.length > 0) {\n\t\t\t\t\tfor (const admin of admins) {\n\t\t\t\t\t\tconst userId = createUniqueUuid(this.runtime, admin.user.id.toString()) as UUID;\n\t\t\t\t\t\tusers.push({\n\t\t\t\t\t\t\tid: userId,\n\t\t\t\t\t\t\tnames: [admin.user.first_name || admin.user.username || 'Unknown Admin'],\n\t\t\t\t\t\t\tagentId: this.runtime.agentId,\n\t\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\t\ttelegram: {\n\t\t\t\t\t\t\t\t\tid: admin.user.id.toString(),\n\t\t\t\t\t\t\t\t\tusername: admin.user.username || 'unknown',\n\t\t\t\t\t\t\t\t\tname: admin.user.first_name || 'Unknown Admin',\n\t\t\t\t\t\t\t\t\tisAdmin: true,\n\t\t\t\t\t\t\t\t\tadminTitle: admin.custom_title || (admin.status === 'creator' ? 'Owner' : 'Admin')\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tsource: \"telegram\",\n\t\t\t\t\t\t\t\troles: [admin.status === 'creator' ? Role.OWNER : Role.ADMIN]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Additionally, we can estimate member count\n\t\t\t\ttry {\n\t\t\t\t\tconst chatInfo = await this.bot.telegram.getChat(chat.id);\n\t\t\t\t\tif (chatInfo && 'member_count' in chatInfo) {\n\t\t\t\t\t\t// Store this information in the world metadata\n\t\t\t\t\t\tworld.metadata.memberCount = chatInfo.member_count;\n\t\t\t\t\t}\n\t\t\t\t} catch (countError) {\n\t\t\t\t\tlogger.warn(`Could not get member count for chat ${chatId}: ${countError}`);\n\t\t\t\t}\n\n\t\t\t} catch (error) {\n\t\t\t\tlogger.warn(`Could not fetch administrators for chat ${chatId}: ${error}`);\n\t\t\t}\n\t\t}\n\n\t\t// Create payload for world events\n\t\tconst worldPayload = {\n\t\t\truntime: this.runtime,\n\t\t\tworld,\n\t\t\trooms: [room],\n\t\t\tentities: users,\n\t\t\tsource: \"telegram\"\n\t\t};\n\n\t\t// Create Telegram-specific payload\n\t\tconst telegramWorldPayload = {\n\t\t\t...worldPayload,\n\t\t\tchat\n\t\t};\n\n\t\t// Emit generic WORLD_JOINED event\n\t\tthis.runtime.emitEvent(\n\t\t\tEventTypes.WORLD_JOINED,\n\t\t\tworldPayload\n\t\t);\n\n\t\t// Emit platform-specific WORLD_JOINED event\n\t\tthis.runtime.emitEvent(\n\t\t\tTelegramEventTypes.WORLD_JOINED,\n\t\t\ttelegramWorldPayload\n\t\t);\n\n\t\t// Set up a handler to track new entities as they interact with the chat\n\t\tif (chat.type === 'group' || chat.type === 'supergroup') {\n\t\t\tthis.setupEntityTracking(chat.id);\n\t\t}\n\t}\n\n\t/**\n\t * Sets up message and reaction handlers for the bot.\n\t *\n\t * @private\n\t * @returns {void}\n\t */\n\tprivate setupMessageHandlers(): void {\n\t\t// Regular message handler\n\t\tthis.bot.on(\"message\", async (ctx) => {\n\t\t\ttry {\n\t\t\t\tif (!(await this.isGroupAuthorized(ctx))) return;\n\t\t\t\tawait this.messageManager.handleMessage(ctx);\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error(\"Error handling message:\", error);\n\t\t\t}\n\t\t});\n\n\t\t// Reaction handler\n\t\tthis.bot.on(\"message_reaction\", async (ctx) => {\n\t\t\ttry {\n\t\t\t\tif (!(await this.isGroupAuthorized(ctx))) return;\n\t\t\t\tawait this.messageManager.handleReaction(ctx);\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error(\"Error handling reaction:\", error);\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Sets up tracking for new entities in a group chat to sync them as entities\n\t * @param {number} chatId - The Telegram chat ID to track entities for\n\t */\n\tprivate setupEntityTracking(chatId: number): void {\n\t\t// We'll maintain a set of entity IDs we've already synced\n\t\tconst syncedEntityIds = new Set<string>();\n\n\t\t// Add handler to track new message authors\n\t\tthis.bot.on('message', async (ctx) => {\n\t\t\tif (!ctx.chat || ctx.chat.id !== chatId || !ctx.from) return;\n\n\t\t\tconst entityId = ctx.from.id.toString();\n\t\t\tif (syncedEntityIds.has(entityId)) return;\n\n\t\t\t// Add to synced set to avoid duplicate processing\n\t\t\tsyncedEntityIds.add(entityId);\n\n\t\t\t// Sync this entity\n\t\t\tconst entityUuid = createUniqueUuid(this.runtime, entityId) as UUID;\n\t\t\tconst worldId = createUniqueUuid(this.runtime, chatId.toString()) as UUID;\n\t\t\tconst chatIdStr = chatId.toString();\n\n\t\t\ttry {\n\t\t\t\t// Create entity\n\t\t\t\tawait this.runtime.ensureConnection({\n\t\t\t\t\tentityId: entityUuid,\n\t\t\t\t\troomId: createUniqueUuid(this.runtime, chatIdStr),\n\t\t\t\t\tuserName: ctx.from.username || ctx.from.first_name || 'Unknown Entity',\n\t\t\t\t\tname: ctx.from.first_name || ctx.from.username || 'Unknown Entity',\n\t\t\t\t\tsource: \"telegram\",\n\t\t\t\t\tchannelId: chatIdStr,\n\t\t\t\t\tserverId: chatIdStr,\n\t\t\t\t\ttype: ChannelType.GROUP,\n\t\t\t\t\tworldId,\n\t\t\t\t});\n\n\t\t\t\t// Create entity joined payload\n\t\t\t\tconst entityJoinedPayload = {\n\t\t\t\t\truntime: this.runtime,\n\t\t\t\t\tentityId: entityUuid,\n\t\t\t\t\tentity: {\n\t\t\t\t\t\tid: entityId,\n\t\t\t\t\t\tusername: ctx.from.username || ctx.from.first_name || 'Unknown Entity',\n\t\t\t\t\t\tdisplayName: ctx.from.first_name || ctx.from.username || 'Unknown Entity'\n\t\t\t\t\t},\n\t\t\t\t\tworldId,\n\t\t\t\t\tsource: \"telegram\",\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tjoinedAt: Date.now()\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\t// Create Telegram-specific payload\n\t\t\t\tconst telegramEntityJoinedPayload = {\n\t\t\t\t\t...entityJoinedPayload,\n\t\t\t\t\ttelegramUser: {\n\t\t\t\t\t\tid: ctx.from.id,\n\t\t\t\t\t\tusername: ctx.from.username,\n\t\t\t\t\t\tfirst_name: ctx.from.first_name\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\t// Emit generic ENTITY_JOINED event\n\t\t\t\tthis.runtime.emitEvent(\n\t\t\t\t\tEventTypes.ENTITY_JOINED,\n\t\t\t\t\tentityJoinedPayload\n\t\t\t\t);\n\n\t\t\t\t// Emit platform-specific ENTITY_JOINED event\n\t\t\t\tthis.runtime.emitEvent(\n\t\t\t\t\tTelegramEventTypes.ENTITY_JOINED,\n\t\t\t\t\ttelegramEntityJoinedPayload\n\t\t\t\t);\n\n\t\t\t\tlogger.info(`Tracked new Telegram entity: ${ctx.from.username || ctx.from.first_name || entityId}`);\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error(`Error syncing new Telegram entity ${entityId} from chat ${chatId}:`, error);\n\t\t\t}\n\t\t});\n\n\t\t// Track when entities leave chat (from service message)\n\t\tthis.bot.on('left_chat_member', async (ctx) => {\n\t\t\tif (!ctx.message?.left_chat_member || ctx.chat?.id !== chatId) return;\n\n\t\t\tconst leftUser = ctx.message.left_chat_member;\n\t\t\tconst entityId = createUniqueUuid(this.runtime, leftUser.id.toString()) as UUID;\n\t\t\tconst chatIdStr = chatId.toString();\n\t\t\tconst worldId = createUniqueUuid(this.runtime, chatIdStr);\n\n\t\t\ttry {\n\t\t\t\t// Get the entity\n\t\t\t\tconst entity = await this.runtime.getEntityById(entityId);\n\t\t\t\tif (entity) {\n\t\t\t\t\t// Update entity metadata to show as inactive\n\t\t\t\t\tentity.metadata = {\n\t\t\t\t\t\t...entity.metadata,\n\t\t\t\t\t\tstatus: \"INACTIVE\",\n\t\t\t\t\t\tleftAt: Date.now(),\n\t\t\t\t\t};\n\t\t\t\t\tawait this.runtime.updateEntity(entity);\n\n\t\t\t\t\t// Create entity left payload\n\t\t\t\t\tconst entityLeftPayload = {\n\t\t\t\t\t\truntime: this.runtime,\n\t\t\t\t\t\tentityId,\n\t\t\t\t\t\tentity: {\n\t\t\t\t\t\t\tid: leftUser.id.toString(),\n\t\t\t\t\t\t\tusername: leftUser.username || leftUser.first_name || 'Unknown Entity',\n\t\t\t\t\t\t\tdisplayName: leftUser.first_name || leftUser.username || 'Unknown Entity'\n\t\t\t\t\t\t},\n\t\t\t\t\t\tworldId,\n\t\t\t\t\t\tsource: \"telegram\",\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\tleftAt: Date.now()\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\n\t\t\t\t\t// Create Telegram-specific payload\n\t\t\t\t\tconst telegramEntityLeftPayload = {\n\t\t\t\t\t\t...entityLeftPayload,\n\t\t\t\t\t\ttelegramUser: {\n\t\t\t\t\t\t\tid: leftUser.id,\n\t\t\t\t\t\t\tusername: leftUser.username,\n\t\t\t\t\t\t\tfirst_name: leftUser.first_name\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\n\t\t\t\t\t// Emit generic ENTITY_LEFT event\n\t\t\t\t\tthis.runtime.emitEvent(\n\t\t\t\t\t\tEventTypes.ENTITY_LEFT,\n\t\t\t\t\t\tentityLeftPayload\n\t\t\t\t\t);\n\n\t\t\t\t\t// Emit platform-specific ENTITY_LEFT event\n\t\t\t\t\tthis.runtime.emitEvent(\n\t\t\t\t\t\tTelegramEventTypes.ENTITY_LEFT,\n\t\t\t\t\t\ttelegramEntityLeftPayload\n\t\t\t\t\t);\n\n\t\t\t\t\tlogger.info(`Entity ${leftUser.username || leftUser.first_name || leftUser.id} left chat ${chatId}`);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error(`Error handling Telegram entity leaving chat ${chatId}:`, error);\n\t\t\t}\n\t\t});\n\t}\n}\n","import type { IAgentRuntime } from \"@elizaos/core\";\nimport { z } from \"zod\";\n\nexport const telegramEnvSchema = z.object({\n\tTELEGRAM_BOT_TOKEN: z.string().min(1, \"Telegram bot token is required\"),\n});\n\n/**\n * Represents the type definition for configuring a Telegram bot based on the inferred schema.\n */\nexport type TelegramConfig = z.infer<typeof telegramEnvSchema>;\n\n/**\n * Validates the Telegram configuration by retrieving the Telegram bot token from the runtime settings or environment variables.\n *\n * @param {IAgentRuntime} runtime - The agent runtime used to get the setting.\n * @returns {Promise<TelegramConfig>} A promise that resolves with the validated Telegram configuration.\n */\nexport async function validateTelegramConfig(\n\truntime: IAgentRuntime,\n): Promise<TelegramConfig> {\n\ttry {\n\t\tconst config = {\n\t\t\tTELEGRAM_BOT_TOKEN:\n\t\t\t\truntime.getSetting(\"TELEGRAM_BOT_TOKEN\") ||\n\t\t\t\tprocess.env.TELEGRAM_BOT_TOKEN,\n\t\t};\n\n\t\treturn telegramEnvSchema.parse(config);\n\t} catch (error) {\n\t\tif (error instanceof z.ZodError) {\n\t\t\tconst errorMessages = error.errors\n\t\t\t\t.map((err) => `${err.path.join(\".\")}: ${err.message}`)\n\t\t\t\t.join(\"\\n\");\n\t\t\tthrow new Error(\n\t\t\t\t`Telegram configuration validation failed:\\n${errorMessages}`,\n\t\t\t);\n\t\t}\n\t\tthrow error;\n\t}\n}\n","import {\n\tChannelType,\n\ttype Content,\n\tEventTypes,\n\ttype HandlerCallback,\n\ttype IAgentRuntime,\n\ttype Media,\n\ttype Memory,\n\tModelType,\n\ttype UUID,\n\tcreateUniqueUuid,\n\tlogger,\n} from \"@elizaos/core\";\nimport type { Chat, Message, ReactionType, Update } from \"@telegraf/types\";\nimport type { Context, NarrowedContext, Telegraf } from \"telegraf\";\nimport { TelegramEventTypes, type TelegramMessageReceivedPayload, type TelegramMessageSentPayload, type TelegramReactionReceivedPayload } from \"./types\";\nimport { escapeMarkdown } from \"./utils\";\n\nimport fs from \"node:fs\";\n\n/**\n * Enum representing different types of media.\n * @enum { string }\n * @readonly\n */\nexport enum MediaType {\n\tPHOTO = \"photo\",\n\tVIDEO = \"video\",\n\tDOCUMENT = \"document\",\n\tAUDIO = \"audio\",\n\tANIMATION = \"animation\",\n}\n\nconst MAX_MESSAGE_LENGTH = 4096; // Telegram's max message length\n\nconst getChannelType = (chat: Chat): ChannelType => {\n\tif (chat.type === \"private\") return ChannelType.DM;\n\tif (chat.type === \"supergroup\") return ChannelType.GROUP;\n\tif (chat.type === \"channel\") return ChannelType.GROUP;\n\tif (chat.type === \"group\") return ChannelType.GROUP;\n};\n\n/**\n * Class representing a message manager.\n * @class\n */\nexport class MessageManager {\n\tpublic bot: Telegraf<Context>;\n\tprotected runtime: IAgentRuntime;\n\n\t/**\n\t * Constructor for creating a new instance of a BotAgent.\n\t *\n\t * @param {Telegraf<Context>} bot - The Telegraf instance used for interacting with the bot platform.\n\t * @param {IAgentRuntime} runtime - The runtime environment for the agent.\n\t */\n\tconstructor(bot: Telegraf<Context>, runtime: IAgentRuntime) {\n\t\tthis.bot = bot;\n\t\tthis.runtime = runtime;\n\t}\n\n\t// Process image messages and generate descriptions\n\t/**\n\t * Process an image from a Telegram message to extract the image URL and description.\n\t *\n\t * @param {Message} message - The Telegram message object containing the image.\n\t * @returns {Promise<{ description: string } | null>} The description of the processed image or null if no image found.\n\t */\n\tasync processImage(\n\t\tmessage: Message,\n\t): Promise<{ description: string } | null> {\n\t\ttry {\n\t\t\tlet imageUrl: string | null = null;\n\n\t\t\tlogger.info(`Telegram Message: ${message}`);\n\n\t\t\tif (\"photo\" in message && message.photo?.length > 0) {\n\t\t\t\tconst photo = message.photo[message.photo.length - 1];\n\t\t\t\tconst fileLink = await this.bot.telegram.getFileLink(photo.file_id);\n\t\t\t\timageUrl = fileLink.toString();\n\t\t\t} else if (\n\t\t\t\t\"document\" in message &&\n\t\t\t\tmessage.document?.mime_type?.startsWith(\"image/\")\n\t\t\t) {\n\t\t\t\tconst fileLink = await this.bot.telegram.getFileLink(\n\t\t\t\t\tmessage.document.file_id,\n\t\t\t\t);\n\t\t\t\timageUrl = fileLink.toString();\n\t\t\t}\n\n\t\t\tif (imageUrl) {\n\t\t\t\tconst { title, description } = await this.runtime.useModel(\n\t\t\t\t\tModelType.IMAGE_DESCRIPTION,\n\t\t\t\t\timageUrl,\n\t\t\t\t);\n\t\t\t\treturn { description: `[Image: ${title}\\n${description}]` };\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error(\"❌ Error processing image:\", error);\n\t\t}\n\n\t\treturn null;\n\t}\n\n\t// Send long messages in chunks\n\t/**\n\t * Sends a message in chunks, handling attachments and splitting the message if necessary\n\t *\n\t * @param {Context} ctx - The context object representing the current state of the bot\n\t * @param {Content} content - The content of the message to be sent\n\t * @param {number} [replyToMessageId] - The ID of the message to reply to, if any\n\t * @returns {Promise<Message.TextMessage[]>} - An array of TextMessage objects representing the messages sent\n\t */\n\tasync sendMessageInChunks(\n\t\tctx: Context,\n\t\tcontent: Content,\n\t\treplyToMessageId?: number,\n\t): Promise<Message.TextMessage[]> {\n\t\tif (content.attachments && content.attachments.length > 0) {\n\t\t\tcontent.attachments.map(async (attachment: Media) => {\n\t\t\t\tconst typeMap: { [key: string]: MediaType } = {\n\t\t\t\t\t\"image/gif\": MediaType.ANIMATION,\n\t\t\t\t\timage: MediaType.PHOTO,\n\t\t\t\t\tdoc: MediaType.DOCUMENT,\n\t\t\t\t\tvideo: MediaType.VIDEO,\n\t\t\t\t\taudio: MediaType.AUDIO,\n\t\t\t\t};\n\n\t\t\t\tlet mediaType: MediaType | undefined = undefined;\n\n\t\t\t\tfor (const prefix in typeMap) {\n\t\t\t\t\tif (attachment.contentType.startsWith(prefix)) {\n\t\t\t\t\t\tmediaType = typeMap[prefix];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!mediaType) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Unsupported Telegram attachment content type: ${attachment.contentType}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tawait this.sendMedia(\n\t\t\t\t\tctx,\n\t\t\t\t\tattachment.url,\n\t\t\t\t\tmediaType,\n\t\t\t\t\tattachment.description,\n\t\t\t\t);\n\t\t\t});\n\t\t} else {\n\t\t\tconst chunks = this.splitMessage(content.text);\n\t\t\tconst sentMessages: Message.TextMessage[] = [];\n\n\t\t\tfor (let i = 0; i < chunks.length; i++) {\n\t\t\t\tconst chunk = escapeMarkdown(chunks[i]);\n\t\t\t\tconst sentMessage = (await ctx.telegram.sendMessage(\n\t\t\t\t\tctx.chat.id,\n\t\t\t\t\tchunk,\n\t\t\t\t\t{\n\t\t\t\t\t\treply_parameters:\n\t\t\t\t\t\t\ti === 0 && replyToMessageId\n\t\t\t\t\t\t\t\t? { message_id: replyToMessageId }\n\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\tparse_mode: \"Markdown\",\n\t\t\t\t\t},\n\t\t\t\t)) as Message.TextMessage;\n\n\t\t\t\tsentMessages.push(sentMessage);\n\t\t\t}\n\n\t\t\treturn sentMessages;\n\t\t}\n\t}\n\n\t/**\n\t * Sends media to a chat using the Telegram API.\n\t *\n\t * @param {Context} ctx - The context object containing information about the current chat.\n\t * @param {string} mediaPath - The path to the media to be sent, either a URL or a local file path.\n\t * @param {MediaType} type - The type of media being sent (PHOTO, VIDEO, DOCUMENT, AUDIO, or ANIMATION).\n\t * @param {string} [caption] - Optional caption for the media being sent.\n\t *\n\t * @returns {Promise<void>} A Promise that resolves when the media is successfully sent.\n\t */\n\tasync sendMedia(\n\t\tctx: Context,\n\t\tmediaPath: string,\n\t\ttype: MediaType,\n\t\tcaption?: string,\n\t): Promise<void> {\n\t\ttry {\n\t\t\tconst isUrl = /^(http|https):\\/\\//.test(mediaPath);\n\t\t\t// biome-ignore lint/complexity/noBannedTypes: <explanation>\n\t\t\tconst sendFunctionMap: Record<MediaType, Function> = {\n\t\t\t\t[MediaType.PHOTO]: ctx.telegram.sendPhoto.bind(ctx.telegram),\n\t\t\t\t[MediaType.VIDEO]: ctx.telegram.sendVideo.bind(ctx.telegram),\n\t\t\t\t[MediaType.DOCUMENT]: ctx.telegram.sendDocument.bind(ctx.telegram),\n\t\t\t\t[MediaType.AUDIO]: ctx.telegram.sendAudio.bind(ctx.telegram),\n\t\t\t\t[MediaType.ANIMATION]: ctx.telegram.sendAnimation.bind(ctx.telegram),\n\t\t\t};\n\n\t\t\tconst sendFunction = sendFunctionMap[type];\n\n\t\t\tif (!sendFunction) {\n\t\t\t\tthrow new Error(`Unsupported media type: ${type}`);\n\t\t\t}\n\n\t\t\tif (isUrl) {\n\t\t\t\t// Handle HTTP URLs\n\t\t\t\tawait sendFunction(ctx.chat.id, mediaPath, { caption });\n\t\t\t} else {\n\t\t\t\t// Handle local file paths\n\t\t\t\tif (!fs.existsSync(mediaPath)) {\n\t\t\t\t\tthrow new Error(`File not found at path: ${mediaPath}`);\n\t\t\t\t}\n\n\t\t\t\tconst fileStream = fs.createReadStream(mediaPath);\n\n\t\t\t\ttry {\n\t\t\t\t\tawait sendFunction(ctx.chat.id, { source: fileStream }, { caption });\n\t\t\t\t} finally {\n\t\t\t\t\tfileStream.destroy();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlogger.info(\n\t\t\t\t`${\n\t\t\t\t\ttype.charAt(0).toUpperCase() + type.slice(1)\n\t\t\t\t} sent successfully: ${mediaPath}`,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tlogger.error(\n\t\t\t\t`Failed to send ${type}. Path: ${mediaPath}. Error: ${error.message}`,\n\t\t\t);\n\t\t\tlogger.debug(error.stack);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t// Split message into smaller parts\n\t/**\n\t * Splits a given text into an array of strings based on the maximum message length.\n\t *\n\t * @param {string} text - The text to split into chunks.\n\t * @returns {string[]} An array of strings with each element representing a chunk of the original text.\n\t */\n\tprivate splitMessage(text: string): string[] {\n\t\tconst chunks: string[] = [];\n\t\tlet currentChunk = \"\";\n\n\t\tconst lines = text.split(\"\\n\");\n\t\tfor (const line of lines) {\n\t\t\tif (currentChunk.length + line.length + 1 <= MAX_MESSAGE_LENGTH) {\n\t\t\t\tcurrentChunk += (currentChunk ? \"\\n\" : \"\") + line;\n\t\t\t} else {\n\t\t\t\tif (currentChunk) chunks.push(currentChunk);\n\t\t\t\tcurrentChunk = line;\n\t\t\t}\n\t\t}\n\n\t\tif (currentChunk) chunks.push(currentChunk);\n\t\treturn chunks;\n\t}\n\n\t// Main handler for incoming messages\n\t/**\n\t * Handle incoming messages from Telegram and process them accordingly.\n\t * @param {Context} ctx - The context object containing information about the message.\n\t * @returns {Promise<void>}\n\t */\n\tpublic async handleMessage(ctx: Context): Promise<void> {\n\t\t// Type guard to ensure message exists\n\t\tif (!ctx.message || !ctx.from) return;\n\n\t\tconst message = ctx.message as Message.TextMessage;\n\n\t\ttry {\n\t\t\t// Convert IDs to UUIDs\n\t\t\tconst entityId = createUniqueUuid(\n\t\t\t\tthis.runtime,\n\t\t\t\tctx.from.id.toString(),\n\t\t\t) as UUID;\n\t\t\tconst userName =\n\t\t\t\tctx.from.username || ctx.from.first_name || \"Unknown User\";\n\t\t\tconst roomId = createUniqueUuid(this.runtime, ctx.chat?.id.toString());\n\n\t\t\t// Get message ID\n\t\t\tconst messageId = createUniqueUuid(\n\t\t\t\tthis.runtime,\n\t\t\t\tmessage?.message_id?.toString(),\n\t\t\t);\n\n\t\t\t// Handle images\n\t\t\tconst imageInfo = await this.processImage(message);\n\n\t\t\t// Get message text - use type guards for safety\n\t\t\tlet messageText = \"\";\n\t\t\tif (\"text\" in message && message.text) {\n\t\t\t\tmessageText = message.text;\n\t\t\t} else if (\"caption\" in message && message.caption) {\n\t\t\t\tmessageText = message.caption as string;\n\t\t\t}\n\n\t\t\t// Combine text and image description\n\t\t\tconst fullText = imageInfo\n\t\t\t\t? `${messageText} ${imageInfo.description}`\n\t\t\t\t: messageText;\n\t\t\tif (!fullText) return;\n\n\t\t\t// Get chat type and determine channel type\n\t\t\tconst chat = message.chat as Chat;\n\t\t\tconst channelType = getChannelType(chat);\n\n\t\t\t// Get world and room IDs\n\t\t\t// For private chats, the world is the chat itself\n\t\t\t// For groups/channels, the world is the supergroup/channel\n\t\t\tconst worldId = createUniqueUuid(\n\t\t\t\tthis.runtime,\n\t\t\t\tchat.type === \"private\" ? `private_${chat.id}` : chat.id.toString()\n\t\t\t);\n\n\t\t\t// Get world and room names\n\t\t\tconst worldName =\n\t\t\t\tchat.type === \"supergroup\"\n\t\t\t\t\t? (chat as Chat.SupergroupChat).title\n\t\t\t\t\t: chat.type === \"channel\"\n\t\t\t\t\t\t? (chat as Chat.ChannelChat).title\n\t\t\t\t\t\t: chat.type === \"private\"\n\t\t\t\t\t\t\t? `Chat with ${(chat as Chat.PrivateChat).first_name || 'Unknown'}`\n\t\t\t\t\t\t\t: \"Telegram\";\n\n\t\t\tconst roomName =\n\t\t\t\tchat.type === \"private\"\n\t\t\t\t\t? (chat as Chat.PrivateChat).first_name\n\t\t\t\t\t: chat.type === \"supergroup\"\n\t\t\t\t\t\t? (chat as Chat.SupergroupChat).title\n\t\t\t\t\t\t: chat.type === \"channel\"\n\t\t\t\t\t\t\t? (chat as Chat.ChannelChat).title\n\t\t\t\t\t\t\t: chat.type === \"group\"\n\t\t\t\t\t\t\t\t? (chat as Chat.GroupChat).title\n\t\t\t\t\t\t\t\t: \"Unknown Group\";\n\n\t\t\t// Ensure entity connection with proper world/server ID handling\n\t\t\tawait this.runtime.ensureConnection({\n\t\t\t\tentityId,\n\t\t\t\troomId,\n\t\t\t\tuserName,\n\t\t\t\tname: userName,\n\t\t\t\tsource: \"telegram\",\n\t\t\t\tchannelId: ctx.chat.id.toString(),\n\t\t\t\tserverId: chat.type === \"private\" ? undefined : chat.id.toString(), // Only set serverId for non-private chats\n\t\t\t\ttype: channelType,\n\t\t\t\tworldId: worldId\n\t\t\t});\n\n\t\t\t// Ensure room exists\n\t\t\tconst room = {\n\t\t\t\tid: roomId,\n\t\t\t\tname: roomName,\n\t\t\t\tsource: \"telegram\",\n\t\t\t\ttype: channelType,\n\t\t\t\tchannelId: ctx.chat.id.toString(),\n\t\t\t\tserverId: chat.type === \"private\" ? undefined : chat.id.toString(),\n\t\t\t\tworldId: worldId,\n\t\t\t};\n\t\t\t\n\t\t\tawait this.runtime.ensureRoomExists(room);\n\n\t\t\t// Create the memory object\n\t\t\tconst memory: Memory = {\n\t\t\t\tid: messageId,\n\t\t\t\tentityId,\n\t\t\t\tagentId: this.runtime.agentId,\n\t\t\t\troomId,\n\t\t\t\tcontent: {\n\t\t\t\t\ttext: fullText,\n\t\t\t\t\tsource: \"telegram\",\n\t\t\t\t\tchannelType: channelType,\n\t\t\t\t\tinReplyTo:\n\t\t\t\t\t\t\"reply_to_message\" in message && message.reply_to_message\n\t\t\t\t\t\t\t? createUniqueUuid(\n\t\t\t\t\t\t\t\t\tthis.runtime,\n\t\t\t\t\t\t\t\t\tmessage.reply_to_message.message_id.toString(),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t},\n\t\t\t\tcreatedAt: message.date * 1000,\n\t\t\t};\n\n\t\t\t// Create callback for handling responses\n\t\t\tconst callback: HandlerCallback = async (\n\t\t\t\tcontent: Content,\n\t\t\t\t_files?: string[],\n\t\t\t) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst sentMessages = await this.sendMessageInChunks(\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tcontent,\n\t\t\t\t\t\tmessage.message_id,\n\t\t\t\t\t);\n\n\t\t\t\t\tif (!sentMessages) return [];\n\n\t\t\t\t\tconst memories: Memory[] = [];\n\t\t\t\t\tfor (let i = 0; i < sentMessages.length; i++) {\n\t\t\t\t\t\tconst sentMessage = sentMessages[i];\n\t\t\t\t\t\tconst _isLastMessage = i === sentMessages.length - 1;\n\n\t\t\t\t\t\tconst responseMemory: Memory = {\n\t\t\t\t\t\t\tid: createUniqueUuid(\n\t\t\t\t\t\t\t\tthis.runtime,\n\t\t\t\t\t\t\t\tsentMessage.message_id.toString(),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tentityId: this.runtime.agentId,\n\t\t\t\t\t\t\tagentId: this.runtime.agentId,\n\t\t\t\t\t\t\troomId,\n\t\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t\t...content,\n\t\t\t\t\t\t\t\ttext: sentMessage.text,\n\t\t\t\t\t\t\t\tinReplyTo: messageId,\n\t\t\t\t\t\t\t\tchannelType: channelType,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tcreatedAt: sentMessage.date * 1000,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tawait this.runtime.createMemory(responseMemory, \"messages\");\n\t\t\t\t\t\tmemories.push(responseMemory);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn memories;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tlogger.error(\"Error in message callback:\", error);\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t// Let the bootstrap plugin handle the message\n\t\t\tthis.runtime.emitEvent(\n\t\t\t\tEventTypes.MESSAGE_RECEIVED,\n\t\t\t\t{\n\t\t\t\t\truntime: this.runtime,\n\t\t\t\t\tmessage: memory,\n\t\t\t\t\tcallback,\n\t\t\t\t\tsource: \"telegram\"\n\t\t\t\t},\n\t\t\t);\n\t\t\t\n\t\t\t// Also emit the platform-specific event\n\t\t\tthis.runtime.emitEvent(\n\t\t\t\tTelegramEventTypes.MESSAGE_RECEIVED,\n\t\t\t\t{\n\t\t\t\t\truntime: this.runtime,\n\t\t\t\t\tmessage: memory,\n\t\t\t\t\tcallback,\n\t\t\t\t\tsource: \"telegram\",\n\t\t\t\t\tctx,\n\t\t\t\t\toriginalMessage: message\n\t\t\t\t} as TelegramMessageReceivedPayload\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tlogger.error(\"Error handling Telegram message:\", {\n\t\t\t\terror,\n\t\t\t\tchatId: ctx.chat?.id,\n\t\t\t\tmessageId: ctx.message?.message_id,\n\t\t\t\tfrom: ctx.from?.username || ctx.from?.id\n\t\t\t});\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Handles the reaction event triggered by a user reacting to a message.\n\t * * @param {NarrowedContext<Context<Update>, Update.MessageReactionUpdate>} ctx The context of the message reaction update\n\t * @returns {Promise<void>} A Promise that resolves when the reaction handling is complete\n\t */\n\tpublic async handleReaction(\n\t\tctx: NarrowedContext<Context<Update>, Update.MessageReactionUpdate>,\n\t): Promise<void> {\n\t\t// Ensure we have the necessary data\n\t\tif (!ctx.update.message_reaction || !ctx.from) return;\n\n\t\tconst reaction = ctx.update.message_reaction;\n\t\tconst reactionType = reaction.new_reaction[0].type;\n\t\tconst reactionEmoji = (reaction.new_reaction[0] as ReactionType).type;\n\n\t\ttry {\n\t\t\tconst entityId = createUniqueUuid(\n\t\t\t\tthis.runtime,\n\t\t\t\tctx.from.id.toString(),\n\t\t\t) as UUID;\n\t\t\tconst roomId = createUniqueUuid(this.runtime, ctx.chat.id.toString());\n\t\t\tconst worldId = createUniqueUuid(this.runtime, ctx.chat.id.toString());\n\n\t\t\tconst reactionId = createUniqueUuid(\n\t\t\t\tthis.runtime,\n\t\t\t\t`${reaction.message_id}-${ctx.from.id}-${Date.now()}`,\n\t\t\t);\n\n\t\t\t// Create reaction memory\n\t\t\tconst memory: Memory = {\n\t\t\t\tid: reactionId,\n\t\t\t\tentityId,\n\t\t\t\tagentId: this.runtime.agentId,\n\t\t\t\troomId,\n\t\t\t\tcontent: {\n\t\t\t\t\tchannelType: getChannelType(reaction.chat as Chat),\n\t\t\t\t\ttext: `Reacted with: ${reactionType === \"emoji\" ? reactionEmoji : reactionType}`,\n\t\t\t\t\tsource: \"telegram\",\n\t\t\t\t\tinReplyTo: createUniqueUuid(\n\t\t\t\t\t\tthis.runtime,\n\t\t\t\t\t\treaction.message_id.toString(),\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t\tcreatedAt: Date.now(),\n\t\t\t};\n\n\t\t\t// Create callback for handling reaction responses\n\t\t\tconst callback: HandlerCallback = async (content: Content) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst sentMessage = await ctx.reply(content.text);\n\t\t\t\t\tconst responseMemory: Memory = {\n\t\t\t\t\t\tid: createUniqueUuid(\n\t\t\t\t\t\t\tthis.runtime,\n\t\t\t\t\t\t\tsentMessage.message_id.toString(),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tentityId: this.runtime.agentId,\n\t\t\t\t\t\tagentId: this.runtime.agentId,\n\t\t\t\t\t\troomId,\n\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\t...content,\n\t\t\t\t\t\t\tinReplyTo: reactionId,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcreatedAt: sentMessage.date * 1000,\n\t\t\t\t\t};\n\t\t\t\t\treturn [responseMemory];\n\t\t\t\t} catch (error) {\n\t\t\t\t\tlogger.error(\"Error in reaction callback:\", error);\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t// Let the bootstrap plugin handle the reaction\n\t\t\tthis.runtime.emitEvent(\n\t\t\t\tEventTypes.REACTION_RECEIVED,\n\t\t\t\t{\n\t\t\t\t\truntime: this.runtime,\n\t\t\t\t\tmessage: memory,\n\t\t\t\t\tcallback,\n\t\t\t\t\tsource: \"telegram\"\n\t\t\t\t},\n\t\t\t);\n\t\t\t\n\t\t\t// Also emit the platform-specific event\n\t\t\tthis.runtime.emitEvent(\n\t\t\t\tTelegramEventTypes.REACTION_RECEIVED,\n\t\t\t\t{\n\t\t\t\t\truntime: this.runtime,\n\t\t\t\t\tmessage: memory,\n\t\t\t\t\tcallback,\n\t\t\t\t\tsource: \"telegram\",\n\t\t\t\t\tctx,\n\t\t\t\t\treactionString: reactionType === \"emoji\" ? reactionEmoji : reactionType,\n\t\t\t\t\toriginalReaction: reaction.new_reaction[0] as ReactionType\n\t\t\t\t} as TelegramReactionReceivedPayload\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tlogger.error(\"Error handling reaction:\", error);\n\t\t}\n\t}\n\n\t/**\n\t * Sends a message to a Telegram chat and emits appropriate events\n\t * @param {number | string} chatId - The Telegram chat ID to send the message to\n\t * @param {Content} content - The content to send\n\t * @param {number} [replyToMessageId] - Optional message ID to reply to\n\t * @returns {Promise<Message.TextMessage[]>} The sent messages\n\t */\n\tpublic async sendMessage(\n\t\tchatId: number | string,\n\t\tcontent: Content,\n\t\treplyToMessageId?: number\n\t): Promise<Message.TextMessage[]> {\n\t\ttry {\n\t\t\t// Create a context-like object for sending\n\t\t\tconst ctx = { \n\t\t\t\tchat: { id: chatId },\n\t\t\t\ttelegram: this.bot.telegram\n\t\t\t};\n\t\t\t\n\t\t\tconst sentMessages = await this.sendMessageInChunks(\n\t\t\t\tctx as Context,\n\t\t\t\tcontent,\n\t\t\t\treplyToMessageId\n\t\t\t);\n\n\t\t\tif (!sentMessages?.length) return [];\n\n\t\t\t// Create room ID\n\t\t\tconst roomId = createUniqueUuid(this.runtime, chatId.toString());\n\t\t\t\n\t\t\t// Create memories for the sent messages\n\t\t\tconst memories: Memory[] = [];\n\t\t\tfor (const sentMessage of sentMessages) {\n\t\t\t\tconst memory: Memory = {\n\t\t\t\t\tid: createUniqueUuid(this.runtime, sentMessage.message_id.toString()),\n\t\t\t\t\tentityId: this.runtime.agentId,\n\t\t\t\t\tagentId: this.runtime.agentId,\n\t\t\t\t\troomId,\n\t\t\t\t\tcontent: {\n\t\t\t\t\t\t...content,\n\t\t\t\t\t\ttext: sentMessage.text,\n\t\t\t\t\t\tsource: \"telegram\",\n\t\t\t\t\t\tchannelType: getChannelType({ \n\t\t\t\t\t\t\tid: typeof chatId === 'string' ? Number.parseInt(chatId, 10) : chatId,\n\t\t\t\t\t\t\ttype: \"private\" // Default to private, will be overridden if in context\n\t\t\t\t\t\t} as Chat)\n\t\t\t\t\t},\n\t\t\t\t\tcreatedAt: sentMessage.date * 1000\n\t\t\t\t};\n\t\t\t\t\n\t\t\t\tawait this.runtime.createMemory(memory, \"messages\");\n\t\t\t\tmemories.push(memory);\n\t\t\t}\n\n\t\t\t// Emit both generic and platform-specific message sent events\n\t\t\tthis.runtime.emitEvent(\n\t\t\t\tEventTypes.MESSAGE_SENT,\n\t\t\t\t{\n\t\t\t\t\truntime: this.runtime,\n\t\t\t\t\tmessages: memories,\n\t\t\t\t\troomId,\n\t\t\t\t\tsource: \"telegram\"\n\t\t\t\t},\n\t\t\t);\n\t\t\t\n\t\t\t// Also emit platform-specific event\n\t\t\tthis.runtime.emitEvent(\n\t\t\t\tTelegramEventTypes.MESSAGE_SENT,\n\t\t\t\t{\n\t\t\t\t\toriginalMessages: sentMessages,\n\t\t\t\t\tchatId\n\t\t\t\t} as TelegramMessageSentPayload\n\t\t\t);\n\t\t\t\n\t\t\treturn sentMessages;\n\t\t} catch (error) {\n\t\t\tlogger.error(\"Error sending message to Telegram:\", error);\n\t\t\treturn [];\n\t\t}\n\t}\n}\n","/**\n * Escapes Markdown special characters in the given text, excluding code blocks.\n * @param {string} text - The text to escape Markdown characters from.\n * @returns {string} The text with escaped Markdown characters.\n */\nexport function escapeMarkdown(text: string): string {\n\t// Don't escape if it's a code block\n\tif (text.startsWith(\"```\") && text.endsWith(\"```\")) {\n\t\treturn text;\n\t}\n\n\t// Split the text by code blocks\n\tconst parts = text.split(/(```[\\s\\S]*?```)/g);\n\n\treturn parts\n\t\t.map((part, index) => {\n\t\t\t// If it's a code block (odd indices in the split result will be code blocks)\n\t\t\tif (index % 2 === 1) {\n\t\t\t\treturn part;\n\t\t\t}\n\t\t\t// For regular text, only escape characters that need escaping in Markdown\n\t\t\treturn (\n\t\t\t\tpart\n\t\t\t\t\t// First preserve any intended inline code spans\n\t\t\t\t\t.replace(/`.*?`/g, (match) => match)\n\t\t\t\t\t// Then only escape the minimal set of special characters that need escaping in Markdown mode\n\t\t\t\t\t.replace(/([*_`\\\\])/g, \"\\\\$1\")\n\t\t\t);\n\t\t})\n\t\t.join(\"\");\n}\n\n/**\n * Splits a message into chunks that fit within Telegram's message length limit\n */\n/**\n * Splits a text message into chunks based on a maximum length for each chunk.\n *\n * @param {string} text - The text message to split.\n * @param {number} maxLength - The maximum length for each chunk (default is 4096).\n * @returns {string[]} An array containing the text message split into chunks.\n */\nexport function splitMessage(text: string, maxLength = 4096): string[] {\n\tconst chunks: string[] = [];\n\tlet currentChunk = \"\";\n\n\tconst lines = text.split(\"\\n\");\n\tfor (const line of lines) {\n\t\tif (currentChunk.length + line.length + 1 <= maxLength) {\n\t\t\tcurrentChunk += (currentChunk ? \"\\n\" : \"\") + line;\n\t\t} else {\n\t\t\tif (currentChunk) chunks.push(currentChunk);\n\t\t\tcurrentChunk = line;\n\t\t}\n\t}\n\n\tif (currentChunk) chunks.push(currentChunk);\n\treturn chunks;\n}\n","import { type IAgentRuntime, type TestSuite, logger } from \"@elizaos/core\";\nimport type { Chat, User } from \"@telegraf/types\";\nimport type { Telegraf } from \"telegraf\";\nimport type { Context } from \"telegraf\";\nimport type { MessageManager } from \"./messageManager\";\nimport type { TelegramService } from \"./service\";\n\nconst TEST_IMAGE_URL =\n\t\"https://github.com/elizaOS/awesome-eliza/blob/main/assets/eliza-logo.jpg?raw=true\";\n\n/**\n * Represents a test suite for testing Telegram functionality.\n *\n * This test suite includes methods to initialize and validate a Telegram bot connection,\n * send basic text messages to a Telegram chat, send text messages with image attachments,\n * handle and process incoming Telegram messages, and process and validate image attachments\n * in incoming messages.\n *\n * @implements {TestSuite}\n */\n\nexport class TelegramTestSuite implements TestSuite {\n\tname = \"telegram\";\n\tprivate telegramClient: TelegramService = null;\n\tprivate bot: Telegraf<Context> | null = null;\n\tprivate messageManager: MessageManager | null = null;\n\ttests: { name: string; fn: (runtime: IAgentRuntime) => Promise<void> }[];\n\n\t/**\n\t * Constructor for initializing a set of test cases for a Telegram bot.\n\t *\n\t * @constructor\n\t * @property {Array<Object>} tests - An array of test cases with name and corresponding test functions.\n\t * @property {string} tests.name - The name of the test case.\n\t * @property {function} tests.fn - The test function to be executed.\n\t */\n\tconstructor() {\n\t\tthis.tests = [\n\t\t\t{\n\t\t\t\tname: \"Initialize and Validate Telegram Bot Connection\",\n\t\t\t\tfn: this.testCreatingTelegramBot.bind(this),\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: \"Send Basic Text Message to Telegram Chat\",\n\t\t\t\tfn: this.testSendingTextMessage.bind(this),\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: \"Send Text Message with an Image Attachment\",\n\t\t\t\tfn: this.testSendingMessageWithAttachment.bind(this),\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: \"Handle and Process Incoming Telegram Messages\",\n\t\t\t\tfn: this.testHandlingMessage.bind(this),\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: \"Process and Validate Image Attachments in Incoming Messages\",\n\t\t\t\tfn: this.testProcessingImages.bind(this),\n\t\t\t},\n\t\t];\n\t}\n\n\t/**\n\t * Retrieves the Telegram test chat ID from environment variables.\n\t *\n\t * Reference on getting the Telegram chat ID:\n\t * https://stackoverflow.com/a/32572159\n\t */\n\t/**\n\t * Validates the chat ID by checking if it is set in the runtime settings or environment variables.\n\t * If not set, an error is thrown with a message instructing to provide a valid chat ID.\n\t * @param {IAgentRuntime} runtime - The runtime object that provides access to the settings and environment variables.\n\t * @throws {Error} If TELEGRAM_TEST_CHAT_ID is not set in the runtime settings or environment variables.\n\t * @returns {string} The validated chat ID.\n\t */\n\tvalidateChatId(runtime: IAgentRuntime) {\n\t\tconst testChatId =\n\t\t\truntime.getSetting(\"TELEGRAM_TEST_CHAT_ID\") ||\n\t\t\tprocess.env.TELEGRAM_TEST_CHAT_ID;\n\t\tif (!testChatId) {\n\t\t\tthrow new Error(\n\t\t\t\t\"TELEGRAM_TEST_CHAT_ID is not set. Please provide a valid chat ID in the environment variables.\",\n\t\t\t);\n\t\t}\n\t\treturn testChatId;\n\t}\n\n\tasync getChatInfo(runtime: IAgentRuntime): Promise<Context[\"chat\"]> {\n\t\ttry {\n\t\t\tconst chatId = this.validateChatId(runtime);\n\t\t\tconst chat = await this.bot.telegram.getChat(chatId);\n\t\t\tlogger.log(`Fetched real chat: ${JSON.stringify(chat)}`);\n\t\t\treturn chat;\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Error fetching real Telegram chat: ${error}`);\n\t\t}\n\t}\n\n\tasync testCreatingTelegramBot(runtime: IAgentRuntime) {\n\t\tthis.telegramClient = runtime.getService(\"telegram\") as TelegramService;\n\t\tthis.bot = this.telegramClient.messageManager.bot;\n\t\tthis.messageManager = this.telegramClient.messageManager;\n\t\tlogger.success(\"Telegram bot initialized successfully.\");\n\t}\n\n\tasync testSendingTextMessage(runtime: IAgentRuntime) {\n\t\ttry {\n\t\t\tif (!this.bot) throw new Error(\"Bot not initialized.\");\n\n\t\t\tconst chatId = this.validateChatId(runtime);\n\t\t\tawait this.bot.telegram.sendMessage(chatId, \"Testing Telegram message!\");\n\t\t\tlogger.success(\"Message sent successfully.\");\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Error sending Telegram message: ${error}`);\n\t\t}\n\t}\n\n\tasync testSendingMessageWithAttachment(runtime: IAgentRuntime) {\n\t\ttry {\n\t\t\tif (!this.messageManager)\n\t\t\t\tthrow new Error(\"MessageManager not initialized.\");\n\n\t\t\tconst chat = await this.getChatInfo(runtime);\n\t\t\tconst mockContext: Partial<Context> = {\n\t\t\t\tchat,\n\t\t\t\tfrom: { id: 123, username: \"TestUser\" } as User,\n\t\t\t\ttelegram: this.bot.telegram,\n\t\t\t};\n\n\t\t\tconst messageContent = {\n\t\t\t\ttext: \"Here is an image attachment:\",\n\t\t\t\tattachments: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"123\",\n\t\t\t\t\t\ttitle: \"Sample Image\",\n\t\t\t\t\t\tsource: TEST_IMAGE_URL,\n\t\t\t\t\t\ttext: \"Sample Image\",\n\t\t\t\t\t\turl: TEST_IMAGE_URL,\n\t\t\t\t\t\tcontentType: \"image/png\",\n\t\t\t\t\t\tdescription: \"Sample Image\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\n\t\t\tawait this.messageManager.sendMessageInChunks(\n\t\t\t\tmockContext as Context,\n\t\t\t\tmessageContent,\n\t\t\t);\n\n\t\t\tlogger.success(\"Message with image attachment sent successfully.\");\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t`Error sending Telegram message with attachment: ${error}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tasync testHandlingMessage(runtime: IAgentRuntime) {\n\t\ttry {\n\t\t\tconst chat = await this.getChatInfo(runtime);\n\t\t\tconst mockContext: Partial<Context> = {\n\t\t\t\tchat,\n\t\t\t\tfrom: {\n\t\t\t\t\tid: 123,\n\t\t\t\t\tusername: \"TestUser\",\n\t\t\t\t\tis_bot: false,\n\t\t\t\t\tfirst_name: \"Test\",\n\t\t\t\t\tlast_name: \"User\",\n\t\t\t\t} as User,\n\t\t\t\tmessage: {\n\t\t\t\t\tmessage_id: undefined,\n\t\t\t\t\ttext: `@${this.bot.botInfo?.username}! Hello!`,\n\t\t\t\t\tdate: Math.floor(Date.now() / 1000),\n\t\t\t\t\tchat,\n\t\t\t\t\t// biome-ignore lint/suspicious/noExplicitAny: <explanation>\n\t\t\t\t} as any,\n\t\t\t\ttelegram: this.bot.telegram,\n\t\t\t};\n\n\t\t\ttry {\n\t\t\t\tawait this.messageManager.handleMessage(mockContext as Context);\n\t\t\t} catch (error) {\n\t\t\t\tthrow new Error(`Error handling Telegram message: ${error}`);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Error handling Telegram message: ${error}`);\n\t\t}\n\t}\n\n\tasync testProcessingImages(runtime: IAgentRuntime) {\n\t\ttry {\n\t\t\tconst chatId = this.validateChatId(runtime);\n\t\t\tconst fileId = await this.getFileId(chatId, TEST_IMAGE_URL);\n\n\t\t\tconst mockMessage = {\n\t\t\t\tmessage_id: undefined,\n\t\t\t\tchat: { id: chatId } as Chat,\n\t\t\t\tdate: Math.floor(Date.now() / 1000),\n\t\t\t\tphoto: [{ file_id: fileId }],\n\t\t\t\ttext: `@${this.bot.botInfo?.username}!`,\n\t\t\t};\n\n\t\t\tconst { description } =\n\t\t\t\tawait this.messageManager.processImage(mockMessage);\n\t\t\tif (!description) {\n\t\t\t\tthrow new Error(\"Error processing Telegram image\");\n\t\t\t}\n\t\t\tlogger.log(`Processing Telegram image successfully: ${description}`);\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Error processing Telegram image: ${error}`);\n\t\t}\n\t}\n\n\tasync getFileId(chatId: string, imageUrl: string) {\n\t\ttry {\n\t\t\tconst message = await this.bot.telegram.sendPhoto(chatId, imageUrl);\n\t\t\treturn message.photo[message.photo.length - 1].file_id;\n\t\t} catch (error) {\n\t\t\tlogger.error(`Error sending image: ${error}`);\n\t\t\tthrow error;\n\t\t}\n\t}\n}\n","import type { Plugin } from \"@elizaos/core\";\nimport { TELEGRAM_SERVICE_NAME } from \"./constants\";\nimport { TelegramService } from \"./service\";\nimport { TelegramTestSuite } from \"./tests\";\n\nconst telegramPlugin: Plugin = {\n\tname: TELEGRAM_SERVICE_NAME,\n\tdescription: \"Telegram client plugin\",\n\tservices: [TelegramService],\n\ttests: [new TelegramTestSuite()],\n};\nexport default telegramPlugin;\n"],"mappings":";AAAO,IAAM,oBAAoB;AAAA,EAChC,cAAc;AAAA,EACd,sBAAsB;AAAA,EACtB,oBAAoB;AAAA,EACpB,8BAA8B;AAAA,EAC9B,yCAAyC;AAAA,EACzC,qBAAqB,IAAI,KAAK;AAAA;AAAA,EAC9B,wBAAwB,IAAI,KAAK;AAAA;AAClC;AAEO,IAAM,wBAAwB;;;ACVrC,SAAS,eAAAA,cAA0B,cAAAC,aAAgC,MAAiB,SAAgC,oBAAAC,mBAAkB,UAAAC,eAAc;AACpJ,SAAuB,gBAAgB;;;ACAvC,SAAS,SAAS;AAEX,IAAM,oBAAoB,EAAE,OAAO;AAAA,EACzC,oBAAoB,EAAE,OAAO,EAAE,IAAI,GAAG,gCAAgC;AACvE,CAAC;AAaD,eAAsB,uBACrB,SAC0B;AAC1B,MAAI;AACH,UAAM,SAAS;AAAA,MACd,oBACC,QAAQ,WAAW,oBAAoB,KACvC,QAAQ,IAAI;AAAA,IACd;AAEA,WAAO,kBAAkB,MAAM,MAAM;AAAA,EACtC,SAAS,OAAO;AACf,QAAI,iBAAiB,EAAE,UAAU;AAChC,YAAM,gBAAgB,MAAM,OAC1B,IAAI,CAAC,QAAQ,GAAG,IAAI,KAAK,KAAK,GAAG,CAAC,KAAK,IAAI,OAAO,EAAE,EACpD,KAAK,IAAI;AACX,YAAM,IAAI;AAAA,QACT;AAAA,EAA8C,aAAa;AAAA,MAC5D;AAAA,IACD;AACA,UAAM;AAAA,EACP;AACD;;;ACxCA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,QACZ,MAAM,EAAE,IAAI,OAAO;AAAA,QACnB,MAAM,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI;AAAA,QAClC,OAAO,CAAC,EAAE,SAAS,OAAO,CAAC;AAAA,QAC3B,MAAM,KAAI,UAAK,IAAI,YAAT,mBAAkB,QAAQ;AAAA,MACrC;AAEA,YAAM,EAAE,YAAY,IACnB,MAAM,KAAK,eAAe,aAAa,WAAW;AACnD,UAAI,CAAC,aAAa;AACjB,cAAM,IAAI,MAAM,iCAAiC;AAAA,MAClD;AACA,MAAAA,QAAO,IAAI,2CAA2C,WAAW,EAAE;AAAA,IACpE,SAAS,OAAO;AACf,YAAM,IAAI,MAAM,oCAAoC,KAAK,EAAE;AAAA,IAC5D;AAAA,EACD;AAAA,EAEA,MAAM,UAAU,QAAgB,UAAkB;AACjD,QAAI;AACH,YAAM,UAAU,MAAM,KAAK,IAAI,SAAS,UAAU,QAAQ,QAAQ;AAClE,aAAO,QAAQ,MAAM,QAAQ,MAAM,SAAS,CAAC,EAAE;AAAA,IAChD,SAAS,OAAO;AACf,MAAAA,QAAO,MAAM,wBAAwB,KAAK,EAAE;AAC5C,YAAM;AAAA,IACP;AAAA,EACD;AACD;;;ACxNA,IAAM,iBAAyB;AAAA,EAC9B,MAAM;AAAA,EACN,aAAa;AAAA,EACb,UAAU,CAAC,eAAe;AAAA,EAC1B,OAAO,CAAC,IAAI,kBAAkB,CAAC;AAChC;AACA,IAAO,gBAAQ;","names":["ChannelType","EventTypes","createUniqueUuid","logger","logger","ChannelType","createUniqueUuid","EventTypes","logger"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elizaos/plugin-telegram",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.60",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "5d49393471bc8f81c5d9852d6ed70875c70e1227"
|
|
42
42
|
}
|