feat: Add Telegram bot integration and .env configuration

This commit is contained in:
uxname committed 2025-05-24 16:55:42 +03:00
1 parent e9320e438f
commit 4b672efa41
6 files changed
+222 -58

No files matched your search

+25 -51
View File
@@ -1,13 +1,19 @@
import dotenv from 'dotenv';
import { Pipeline } from './models/pipeline';
import { PipelineExecutor } from './pipelines/pipeline-executor';
import { TelegramBot } from './bot/telegram-bot';
dotenv.config();
async function main() {
const telegramToken = process.env.TELEGRAM_BOT_TOKEN;
const openAIApiKey = process.env.OPENAI_API_KEY;
const mcpServerUrl =
process.env.MCP_SERVER_URL || 'https://santiment-mcp.dev.mind-dev.com/sse';
const mcpServerUrl = process.env.MCP_SERVER_URL;
if (!telegramToken) {
console.error(
'Ошибка: Переменная окружения TELEGRAM_BOT_TOKEN не установлена.',
);
process.exit(1);
}
if (!openAIApiKey) {
console.error(
@@ -16,53 +22,21 @@ async function main() {
process.exit(1);
}
const pipelineExecutor = new PipelineExecutor(mcpServerUrl);
const testPipeline: Pipeline = {
description: 'Тестовый пайплайн',
systemPrompt:
'Ты полезный ассистент, который всегда отвечает на русском языке.',
steps: [
{
name: 'Приветствие',
prompt: 'Скажи привет пользователю, его имя - {{username}}.',
},
{
name: 'Использование инструмента',
prompt:
'Напиши какие инструменты тебе доступны? (Очень кратко напиши суть и входящие параметры).',
},
{
name: 'Использование инструмента',
prompt: 'Вызови **top_gainers** с pageSize=2 и покажи что получилось.',
},
{
name: 'Итог',
prompt:
'Отлично, теперь давай подытожим всё что мы сделали, соберём информацию вместе и оформим её как telegram пост.',
},
],
};
const variables = {
username: 'Вася',
};
const systemPrompts = ['Отвечай кратко и по существу.'];
try {
const results = await pipelineExecutor.executeChain({
pipeline: testPipeline,
variables: variables,
systemPrompts: systemPrompts,
openAIApiKey: openAIApiKey,
});
console.log('Результаты выполнения пайплайна:', results);
} catch (error) {
console.error('Ошибка при выполнении пайплайна:', error);
} finally {
await pipelineExecutor.mcpToolsService.disconnect();
if (!mcpServerUrl) {
console.error(
'Ошибка: Переменная окружения MCP_SERVER_URL не установлена.',
);
process.exit(1);
}
// Initialize and start the Telegram bot
const bot = new TelegramBot(telegramToken, mcpServerUrl);
bot.launch();
console.log('Бот запущен и готов к работе!');
}
main().catch(console.error);
main().catch((error) => {
console.error('Произошла ошибка:', error);
process.exit(1);
});