-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Expand file tree
/
Copy pathtelegram-agent.ts
More file actions
67 lines (55 loc) · 1.82 KB
/
telegram-agent.ts
File metadata and controls
67 lines (55 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* Telegram bot using elizaOS with full message pipeline.
*
* Required env vars: TELEGRAM_BOT_TOKEN, OPENAI_API_KEY
* Optional: POSTGRES_URL (defaults to PGLite)
*/
import { AgentRuntime, createCharacter } from "@elizaos/core";
async function main() {
const [
{ openaiPlugin },
{ default: sqlPlugin },
{ default: telegramPlugin },
] = await Promise.all([
import("@elizaos/plugin-openai"),
import("@elizaos/plugin-sql"),
import("@elizaos/plugin-telegram"),
]);
const telegramBotToken = process.env.TELEGRAM_BOT_TOKEN;
const openaiApiKey = process.env.OPENAI_API_KEY;
if (!telegramBotToken || !openaiApiKey) {
console.error("Missing TELEGRAM_BOT_TOKEN or OPENAI_API_KEY");
process.exit(1);
}
const character = createCharacter({
name: "TelegramEliza",
bio: "A helpful AI assistant on Telegram.",
system: `You are TelegramEliza, a helpful AI assistant on Telegram.
Be friendly, concise, and genuinely helpful.
Keep responses short - suitable for mobile chat.`,
settings: {
// Match how the chat example configures model selection via runtime settings
// (read by @elizaos/plugin-openai).
OPENAI_SMALL_MODEL: "gpt-5-mini",
OPENAI_LARGE_MODEL: "gpt-5-mini",
},
// Optional: pass through secrets so plugins can read via runtime.getSetting()
secrets: {
TELEGRAM_BOT_TOKEN: telegramBotToken,
OPENAI_API_KEY: openaiApiKey,
},
});
console.log("Starting TelegramEliza...");
const runtime = new AgentRuntime({
character,
plugins: [sqlPlugin, openaiPlugin, telegramPlugin],
});
await runtime.initialize();
console.log(`${character.name} is running. Press Ctrl+C to stop.`);
process.on("SIGINT", async () => {
await runtime.stop();
process.exit(0);
});
await new Promise(() => {});
}
main().catch(console.error);