feat(38-01): wire telegramService + telegramRoutes into app.ts

- Import telegramService, telegramRoutes, nexusSettingsService
- Mount /telegram routes under /api prefix
- Conditionally start Telegram bot on boot if telegramToken is configured
- Token route restarts bot after saving new token
This commit is contained in:
Nexus Dev 2026-04-04 03:14:08 +00:00
parent ed21eb339c
commit 34bfbe06e1

View file

@ -33,6 +33,9 @@ import { assistantHandoffRoutes } from "./routes/assistant-handoff.js";
import { chatFileRoutes } from "./routes/chat-files.js";
import { nexusSettingsRoutes } from "./routes/nexus-settings.js";
import { voiceRoutes } from "./routes/voice.js";
import { telegramService } from "./services/telegram.js";
import { telegramRoutes } from "./routes/telegram.js";
import { nexusSettingsService } from "./services/nexus-settings.js";
import { pluginRoutes } from "./routes/plugins.js";
import { pluginUiStaticRoutes } from "./routes/plugin-ui-static.js";
import { applyUiBranding } from "./ui-branding.js";
@ -183,6 +186,11 @@ export async function createApp(
api.use(chatFileRoutes(db, opts.storageService));
api.use(nexusSettingsRoutes());
api.use(voiceRoutes());
// Telegram bridge — create service instance and mount routes
const tg = telegramService(db);
api.use(telegramRoutes(db, tg));
const hostServicesDisposers = new Map<string, () => void>();
const workerManager = createPluginWorkerManager();
const pluginRegistry = pluginRegistryService(db);
@ -358,5 +366,15 @@ export async function createApp(
void flushPluginLogBuffer();
});
// Conditionally start telegram bot if token is configured
{
const settings = await nexusSettingsService().get();
if (settings.telegramToken) {
tg.start(settings.telegramToken).catch((err) => {
logger.error({ err }, "Failed to start Telegram bot");
});
}
}
return app;
}