require('dotenv').config();
const { Framework } = require('../src');

async function main() {
  const framework = new Framework({ debug: false });

  await framework.bootstrap({
    agentDir: process.cwd() + '/.agent',
    aiConfig: {
      provider: process.env.FOLIKO_PROVIDER || 'minimax',
      model: process.env.FOLIKO_MODEL || 'MiniMax-M2.7',
      baseURL: process.env.FOLIKO_BASE_URL || 'https://api.minimaxi.com/v1',
      apiKey: process.env.MINIMAX_API_KEY || process.env.DEEPSEEK_API_KEY,
    },
  });

  // 检查 telegram 插件
  const tgPlugin = framework.pluginManager.get('telegram');
  console.log('Telegram plugin loaded:', !!tgPlugin);

  if (tgPlugin) {
    const status = tgPlugin.getStatus();
    console.log('Telegram status:', status);

    // 检查 Bot 状态
    if (tgPlugin._bot) {
      console.log('Bot is running');

      // 添加一个测试处理器来查看接收到的消息
      tgPlugin._bot.on('message', (msg) => {
        console.log('=== Received message ===');
        console.log('Chat ID:', msg.chat?.id);
        console.log('Chat type:', msg.chat?.type);
        console.log('From:', msg.from?.username);
        console.log('Text:', msg.text);
        console.log('=========================');
      });
    } else {
      console.log('Bot is NOT running');
    }
  }

  console.log('\nBot is running. Send a message to test...');
  console.log('Press Ctrl+C to stop.\n');

  // 保持进程运行
  await new Promise(() => {});
}

main().catch(console.error);
