freetravel/src/index.ts
Peppa a0444ce736
Some checks failed
peppa/lint lint: success за 1с
peppa/typecheck typecheck: success за 2с
peppa/test test: success за 3с
peppa/build build: success за 2с
ci / checks (pull_request) Successful in 24s
deploy / deploy (pull_request) Failing after 26s
FRTVL-13: имя бота из getMe, понятная ошибка привязки без бота
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-17 01:51:35 +05:00

48 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import "./instrument.js";
import * as Sentry from "@sentry/node";
import { Notifier } from "./notify/notifier.js";
import { JsonSettingsStore } from "./notify/settingsStore.js";
import { BotApiTelegramClient, MockTelegramClient, type TelegramClient } from "./notify/telegram.js";
import { ClaudeSearchProvider } from "./search/claudeSearchProvider.js";
import { mockSearchProvider } from "./search/mockSearchProvider.js";
import type { SearchProvider } from "./search/provider.js";
import { SearchService } from "./search/searchService.js";
import { buildServer } from "./server.js";
import { JsonCatalogStore } from "./store/catalogStore.js";
const useMock = process.env.MOCK_SEARCH === "1" || !process.env.ANTHROPIC_API_KEY;
const provider: SearchProvider = useMock ? mockSearchProvider({ delayMs: 1500 }) : new ClaudeSearchProvider();
const store = new JsonCatalogStore(process.env.DATA_DIR ?? "./data");
const search = new SearchService({ store, provider, onError: (error) => Sentry.captureException(error) });
let telegram: TelegramClient = new MockTelegramClient();
if (process.env.TELEGRAM_BOT_TOKEN) {
// Имя бота берём у самого Телеграма; TELEGRAM_BOT_USERNAME — лишь запасной вариант.
const bot = new BotApiTelegramClient(process.env.TELEGRAM_BOT_TOKEN, process.env.TELEGRAM_BOT_USERNAME ?? "");
if (!(await bot.resolveUsername())) console.error("Telegram: не удалось узнать имя бота — проверьте TELEGRAM_BOT_TOKEN");
telegram = bot;
}
const notifier = new Notifier({
settings: new JsonSettingsStore(process.env.DATA_DIR ?? "./data"),
catalog: store,
search,
telegram,
onError: (error) => Sentry.captureException(error),
});
notifier.start();
const app = await buildServer({
store,
search,
notifier,
searchToken: process.env.SEARCH_TOKEN || undefined,
providerName: provider.name,
logger: true,
setup: (instance) => Sentry.setupFastifyErrorHandler(instance),
});
const port = Number(process.env.PORT ?? 3000);
await app.listen({ port, host: "0.0.0.0" });
app.log.info(`search provider: ${provider.name}, telegram: ${telegram.name}`);