import { readBody } from 'h3';
import { useResponseError, useResponseSuccess } from '~/utils/response';
import { testTelegramConfig } from '~/utils/telegram-bot';

export default defineEventHandler(async (event) => {
  const body = await readBody(event);

  if (!body?.botToken || !body?.chatId) {
    return useResponseError('缺少Bot Token或Chat ID', -1);
  }

  const result = await testTelegramConfig(body.botToken, body.chatId);

  if (result.success) {
    return useResponseSuccess({ message: '测试消息发送成功' });
  } else {
    return useResponseError(result.error || '测试失败', -1);
  }
});
