Skip to content

Commit

Permalink
Merge pull request #65 from dreaminglucid/main
Browse files Browse the repository at this point in the history
Telegram Integration with shouldRespond handler + image recognition
  • Loading branch information
lalalune authored Oct 28, 2024
2 parents b5caa0b + 4f60083 commit b9fb7ff
Show file tree
Hide file tree
Showing 3 changed files with 301 additions and 175 deletions.
26 changes: 12 additions & 14 deletions src/clients/telegram/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// clients/telegram/src/index.ts

import { Context, Telegraf } from "telegraf";

import { IAgentRuntime } from "../../../core/types.ts";
Expand All @@ -19,23 +17,23 @@ export class TelegramClient {
console.log("Setting up message handler...");
this.bot.on("message", async (ctx) => {
try {
if ("text" in ctx.message) {
console.log("📥 Received message:", ctx.message.text);
await this.messageManager.handleMessage(ctx);
} else {
console.log("❌ Received non-text message");


// TODO: Handle non-text messages


}
console.log("📥 Received message:", ctx.message);
await this.messageManager.handleMessage(ctx);
} catch (error) {
console.error("❌ Error handling message:", error);
await ctx.reply("An error occurred while processing your message.");
}
});

// Handle specific message types for better logging
this.bot.on("photo", (ctx) => {
console.log("📸 Received photo message with caption:", ctx.message.caption);
});

this.bot.on("document", (ctx) => {
console.log("📎 Received document message:", ctx.message.document.file_name);
});

this.bot.catch((err, ctx) => {
console.error(`❌ Telegram Error for ${ctx.updateType}:`, err);
ctx.reply("An unexpected error occurred. Please try again later.");
Expand Down Expand Up @@ -81,4 +79,4 @@ export class TelegramClient {
await this.bot.stop();
console.log("Telegram bot stopped");
}
}
}
Loading

0 comments on commit b9fb7ff

Please sign in to comment.