refactor: make telegram config optional for non-telegram setups
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -163,6 +163,9 @@ const checkTelegram: Check = async (ctx) => {
|
|||||||
if (!ctx.config) {
|
if (!ctx.config) {
|
||||||
return { status: 'skip', label: 'Telegram bot configured', detail: '(config invalid)' };
|
return { status: 'skip', label: 'Telegram bot configured', detail: '(config invalid)' };
|
||||||
}
|
}
|
||||||
|
if (!ctx.config.telegram) {
|
||||||
|
return { status: 'skip', label: 'Telegram bot configured', detail: '(not configured)' };
|
||||||
|
}
|
||||||
if (!ctx.config.telegram.bot_token || ctx.config.telegram.bot_token.length < 10) {
|
if (!ctx.config.telegram.bot_token || ctx.config.telegram.bot_token.length < 10) {
|
||||||
return { status: 'warn', label: 'Telegram bot configured', detail: 'token looks too short' };
|
return { status: 'warn', label: 'Telegram bot configured', detail: 'token looks too short' };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ models:
|
|||||||
const result = loadConfigSafe(configPath);
|
const result = loadConfigSafe(configPath);
|
||||||
expect(result.config).toBeDefined();
|
expect(result.config).toBeDefined();
|
||||||
expect(result.error).toBeUndefined();
|
expect(result.error).toBeUndefined();
|
||||||
expect(result.config!.telegram.bot_token).toBe('test-token');
|
expect(result.config!.telegram?.bot_token).toBe('test-token');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns error when file not found', () => {
|
it('returns error when file not found', () => {
|
||||||
|
|||||||
+3
-1
@@ -29,7 +29,9 @@ export function registerStartCommand(program: Command): void {
|
|||||||
const { startDaemon } = await import('../daemon/index.js');
|
const { startDaemon } = await import('../daemon/index.js');
|
||||||
const daemon = await startDaemon(config);
|
const daemon = await startDaemon(config);
|
||||||
|
|
||||||
console.log(`Allowed Telegram chat IDs: ${config.telegram.allowed_chat_ids.join(', ')}`);
|
if (config.telegram) {
|
||||||
|
console.log(`Allowed Telegram chat IDs: ${config.telegram.allowed_chat_ids.join(', ')}`);
|
||||||
|
}
|
||||||
|
|
||||||
// Keep process alive
|
// Keep process alive
|
||||||
await new Promise<void>((resolve) => {
|
await new Promise<void>((resolve) => {
|
||||||
|
|||||||
+7
-3
@@ -154,9 +154,13 @@ export function registerTuiCommand(program: Command): void {
|
|||||||
currentLocalProvider: config.models.local?.provider,
|
currentLocalProvider: config.models.local?.provider,
|
||||||
onTransfer: (target) => {
|
onTransfer: (target) => {
|
||||||
if (target === 'telegram') {
|
if (target === 'telegram') {
|
||||||
const telegramUserId = String(config.telegram.allowed_chat_ids[0]);
|
if (config.telegram && config.telegram.allowed_chat_ids.length > 0) {
|
||||||
sessionManager.transferSession('tui', 'local', 'telegram', telegramUserId);
|
const telegramUserId = String(config.telegram.allowed_chat_ids[0]);
|
||||||
console.log(`Session transferred to Telegram (${telegramUserId})\n`);
|
sessionManager.transferSession('tui', 'local', 'telegram', telegramUserId);
|
||||||
|
console.log(`Session transferred to Telegram (${telegramUserId})\n`);
|
||||||
|
} else {
|
||||||
|
console.log('Telegram not configured\n');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log(`Unknown transfer target: ${target}\n`);
|
console.log(`Unknown transfer target: ${target}\n`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,8 +58,8 @@ models:
|
|||||||
|
|
||||||
const config = loadConfig(configPath);
|
const config = loadConfig(configPath);
|
||||||
|
|
||||||
expect(config.telegram.bot_token).toBe('test-token');
|
expect(config.telegram?.bot_token).toBe('test-token');
|
||||||
expect(config.telegram.allowed_chat_ids).toContain(123456789);
|
expect(config.telegram?.allowed_chat_ids).toContain(123456789);
|
||||||
expect(config.server.port).toBe(18800);
|
expect(config.server.port).toBe(18800);
|
||||||
expect(config.models.default.provider).toBe('anthropic');
|
expect(config.models.default.provider).toBe('anthropic');
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ models:
|
|||||||
|
|
||||||
const config = loadConfig(configPath);
|
const config = loadConfig(configPath);
|
||||||
|
|
||||||
expect(config.telegram.bot_token).toBe('env-token-value');
|
expect(config.telegram?.bot_token).toBe('env-token-value');
|
||||||
|
|
||||||
delete process.env.TEST_BOT_TOKEN;
|
delete process.env.TEST_BOT_TOKEN;
|
||||||
rmSync(testDir, { recursive: true });
|
rmSync(testDir, { recursive: true });
|
||||||
@@ -137,7 +137,7 @@ server:
|
|||||||
|
|
||||||
const config = loadConfig(basePath, overlayPath);
|
const config = loadConfig(basePath, overlayPath);
|
||||||
expect(config.server.port).toBe(9999);
|
expect(config.server.port).toBe(9999);
|
||||||
expect(config.telegram.bot_token).toBe('base-token');
|
expect(config.telegram?.bot_token).toBe('base-token');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('loads base-only when no overlay provided', () => {
|
it('loads base-only when no overlay provided', () => {
|
||||||
@@ -157,7 +157,7 @@ models:
|
|||||||
`);
|
`);
|
||||||
|
|
||||||
const config = loadConfig(basePath);
|
const config = loadConfig(basePath);
|
||||||
expect(config.telegram.bot_token).toBe('base-only-token');
|
expect(config.telegram?.bot_token).toBe('base-only-token');
|
||||||
expect(config.server.port).toBe(18800);
|
expect(config.server.port).toBe(18800);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -186,7 +186,7 @@ models:
|
|||||||
`);
|
`);
|
||||||
|
|
||||||
const config = loadConfig(basePath, overlayPath);
|
const config = loadConfig(basePath, overlayPath);
|
||||||
expect(config.telegram.bot_token).toBe('expanded-token');
|
expect(config.telegram?.bot_token).toBe('expanded-token');
|
||||||
expect(config.models.default.model).toBe('gpt-4o');
|
expect(config.models.default.model).toBe('gpt-4o');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -349,7 +349,7 @@ const logLevelSchema = z.enum(['debug', 'info', 'warn', 'error', 'silent']).defa
|
|||||||
|
|
||||||
export const configSchema = z.object({
|
export const configSchema = z.object({
|
||||||
log_level: logLevelSchema,
|
log_level: logLevelSchema,
|
||||||
telegram: telegramSchema,
|
telegram: telegramSchema.optional(),
|
||||||
discord: discordSchema,
|
discord: discordSchema,
|
||||||
slack: slackSchema,
|
slack: slackSchema,
|
||||||
whatsapp: whatsappSchema,
|
whatsapp: whatsappSchema,
|
||||||
|
|||||||
+11
-9
@@ -21,15 +21,17 @@ export interface ChannelsResult {
|
|||||||
export function registerChannels(deps: ChannelsDeps): ChannelsResult {
|
export function registerChannels(deps: ChannelsDeps): ChannelsResult {
|
||||||
const { config, channelRegistry, hookEngine, pairingManager, gateway } = deps;
|
const { config, channelRegistry, hookEngine, pairingManager, gateway } = deps;
|
||||||
|
|
||||||
// Register Telegram adapter
|
// Register Telegram adapter (if configured)
|
||||||
const telegramAdapter = new TelegramAdapter({
|
if (config.telegram) {
|
||||||
botToken: config.telegram.bot_token,
|
const telegramAdapter = new TelegramAdapter({
|
||||||
allowedChatIds: config.telegram.allowed_chat_ids,
|
botToken: config.telegram.bot_token,
|
||||||
requireMention: config.telegram.require_mention,
|
allowedChatIds: config.telegram.allowed_chat_ids,
|
||||||
hookEngine,
|
requireMention: config.telegram.require_mention,
|
||||||
pairingManager,
|
hookEngine,
|
||||||
});
|
pairingManager,
|
||||||
channelRegistry.register(telegramAdapter);
|
});
|
||||||
|
channelRegistry.register(telegramAdapter);
|
||||||
|
}
|
||||||
|
|
||||||
// Register Discord adapter (if configured)
|
// Register Discord adapter (if configured)
|
||||||
if (config.discord) {
|
if (config.discord) {
|
||||||
|
|||||||
Reference in New Issue
Block a user