diff --git a/packages/client-telegram/package.json b/packages/client-telegram/package.json index ad29702bab..bc4fb34515 100644 --- a/packages/client-telegram/package.json +++ b/packages/client-telegram/package.json @@ -1,11 +1,11 @@ { - "name": "@ai16z/client-telegram", - "version": "0.1.6-alpha.4", + "name": "@elizaos/client-telegram", + "version": "0.1.7-alpha.1", "main": "dist/index.js", "type": "module", "types": "dist/index.d.ts", "dependencies": { - "@ai16z/eliza": "workspace:*", + "@elizaos/core": "workspace:*", "@telegraf/types": "7.1.0", "telegraf": "4.16.3", "zod": "3.23.8" diff --git a/packages/client-telegram/src/environment.ts b/packages/client-telegram/src/environment.ts index b83b9e8960..ef2739a23c 100644 --- a/packages/client-telegram/src/environment.ts +++ b/packages/client-telegram/src/environment.ts @@ -1,4 +1,4 @@ -import { IAgentRuntime } from "@ai16z/eliza"; +import { IAgentRuntime } from "@elizaos/core"; import { z } from "zod"; export const telegramEnvSchema = z.object({ diff --git a/packages/client-telegram/src/index.ts b/packages/client-telegram/src/index.ts index b38b8a5431..61e9d091ae 100644 --- a/packages/client-telegram/src/index.ts +++ b/packages/client-telegram/src/index.ts @@ -1,5 +1,5 @@ -import { elizaLogger } from "@ai16z/eliza"; -import { Client, IAgentRuntime } from "@ai16z/eliza"; +import { elizaLogger } from "@elizaos/core"; +import { Client, IAgentRuntime } from "@elizaos/core"; import { TelegramClient } from "./telegramClient.ts"; import { validateTelegramConfig } from "./environment.ts"; diff --git a/packages/client-telegram/src/messageManager.ts b/packages/client-telegram/src/messageManager.ts index 21fd87384e..850f2f3bf6 100644 --- a/packages/client-telegram/src/messageManager.ts +++ b/packages/client-telegram/src/messageManager.ts @@ -1,8 +1,8 @@ import { Message } from "@telegraf/types"; import { Context, Telegraf } from "telegraf"; -import { composeContext, elizaLogger, ServiceType } from "@ai16z/eliza"; -import { getEmbeddingZeroVector } from "@ai16z/eliza"; +import { composeContext, elizaLogger, ServiceType } from "@elizaos/core"; +import { getEmbeddingZeroVector } from "@elizaos/core"; import { Content, HandlerCallback, @@ -13,11 +13,11 @@ import { State, UUID, Media, -} from "@ai16z/eliza"; -import { stringToUuid } from "@ai16z/eliza"; +} from "@elizaos/core"; +import { stringToUuid } from "@elizaos/core"; -import { generateMessageResponse, generateShouldRespond } from "@ai16z/eliza"; -import { messageCompletionFooter, shouldRespondFooter } from "@ai16z/eliza"; +import { generateMessageResponse, generateShouldRespond } from "@elizaos/core"; +import { messageCompletionFooter, shouldRespondFooter } from "@elizaos/core"; import { cosineSimilarity } from "./utils"; import { @@ -702,7 +702,7 @@ export class MessageManager { i === 0 && replyToMessageId ? { message_id: replyToMessageId } : undefined, - parse_mode:'Markdown' + parse_mode: "Markdown", } )) as Message.TextMessage; @@ -721,21 +721,17 @@ export class MessageManager { try { if (/^(http|https):\/\//.test(imagePath)) { // Handle HTTP URLs - await ctx.telegram.sendPhoto( - ctx.chat.id, - imagePath, - { - caption, - } - ); + await ctx.telegram.sendPhoto(ctx.chat.id, imagePath, { + caption, + }); } else { - // Handle local file paths + // Handle local file paths if (!fs.existsSync(imagePath)) { throw new Error(`File not found: ${imagePath}`); } - + const fileStream = fs.createReadStream(imagePath); - + await ctx.telegram.sendPhoto( ctx.chat.id, { @@ -746,7 +742,7 @@ export class MessageManager { } ); } - + elizaLogger.info(`Image sent successfully: ${imagePath}`); } catch (error) { elizaLogger.error("Error sending image:", error); @@ -1085,7 +1081,7 @@ export class MessageManager { for (let i = 0; i < sentMessages.length; i++) { const sentMessage = sentMessages[i]; const isLastMessage = i === sentMessages.length - 1; - + const memory: Memory = { id: stringToUuid( sentMessage.message_id.toString() + @@ -1103,17 +1099,19 @@ export class MessageManager { createdAt: sentMessage.date * 1000, embedding: getEmbeddingZeroVector(), }; - + // Set action to CONTINUE for all messages except the last one // For the last message, use the original action from the response content memory.content.action = !isLastMessage ? "CONTINUE" : content.action; - - await this.runtime.messageManager.createMemory(memory); + + await this.runtime.messageManager.createMemory( + memory + ); memories.push(memory); } - + return memories; } }; @@ -1125,14 +1123,12 @@ export class MessageManager { state = await this.runtime.updateRecentMessageState(state); // Handle any resulting actions - - const actionResult: any = await this.runtime.processActions( + await this.runtime.processActions( memory, responseMessages, state, callback ); - console.log("actionResult", actionResult); } await this.runtime.evaluate(memory, state, shouldRespond); diff --git a/packages/client-telegram/src/telegramClient.ts b/packages/client-telegram/src/telegramClient.ts index 37aabbb64d..059b5ec633 100644 --- a/packages/client-telegram/src/telegramClient.ts +++ b/packages/client-telegram/src/telegramClient.ts @@ -1,6 +1,6 @@ import { Context, Telegraf } from "telegraf"; -import { message } from 'telegraf/filters'; -import { IAgentRuntime, elizaLogger } from "@ai16z/eliza"; +import { message } from "telegraf/filters"; +import { IAgentRuntime, elizaLogger } from "@elizaos/core"; import { MessageManager } from "./messageManager.ts"; import { getOrCreateRecommenderInBe } from "./getOrCreateRecommenderInBe.ts"; @@ -67,7 +67,10 @@ export class TelegramClient { await ctx.reply("Not authorized. Leaving."); await ctx.leaveChat(); } catch (error) { - elizaLogger.error(`Error leaving unauthorized group ${currentGroupId}:`, error); + elizaLogger.error( + `Error leaving unauthorized group ${currentGroupId}:`, + error + ); } return false; } @@ -78,10 +81,12 @@ export class TelegramClient { private setupMessageHandlers(): void { elizaLogger.log("Setting up message handler..."); - this.bot.on(message('new_chat_members'), async (ctx) => { + this.bot.on(message("new_chat_members"), async (ctx) => { try { const newMembers = ctx.message.new_chat_members; - const isBotAdded = newMembers.some(member => member.id === ctx.botInfo.id); + const isBotAdded = newMembers.some( + (member) => member.id === ctx.botInfo.id + ); if (isBotAdded && !(await this.isGroupAuthorized(ctx))) { return; @@ -129,9 +134,14 @@ export class TelegramClient { // Don't try to reply if we've left the group or been kicked if (error?.response?.error_code !== 403) { try { - await ctx.reply("An error occurred while processing your message."); + await ctx.reply( + "An error occurred while processing your message." + ); } catch (replyError) { - elizaLogger.error("Failed to send error message:", replyError); + elizaLogger.error( + "Failed to send error message:", + replyError + ); } } }