feat: Add detailed logging to bot initialization process

main
borja (aider) 3 months ago
parent 575b140820
commit e350252845

@ -5,6 +5,8 @@ import { startCleanupJob } from '../jobs/cleanupJob';
export const linkedGroups: Set<string> = new Set();
export async function startBot() {
console.log('Initializing bot...');
const communityId = process.env.COMMUNITY_ID;
const webhookUrl = process.env.WEBHOOK_URL;
@ -12,15 +14,45 @@ export async function startBot() {
throw new Error('Required environment variables are not defined.');
}
// Load linked groups from the database
const groups = query('SELECT id FROM groups WHERE linked_parent = ?', [communityId]);
for (const group of groups) {
linkedGroups.add(group.id);
console.log('Loading linked groups from database...');
try {
const groups = query('SELECT id FROM groups WHERE linked_parent = ?', [communityId]);
console.log(`Found ${groups.length} linked groups`);
for (const group of groups) {
linkedGroups.add(group.id);
}
} catch (error) {
console.error('Failed to load linked groups:', error);
throw error;
}
console.log('Fetching groups from API...');
try {
await fetchGroups(communityId);
console.log('Successfully fetched groups');
} catch (error) {
console.error('Failed to fetch groups:', error);
throw error;
}
await fetchGroups(communityId);
await configureWebhook(webhookUrl);
console.log('Configuring webhook...');
try {
await configureWebhook(webhookUrl);
console.log('Webhook configured successfully');
} catch (error) {
console.error('Failed to configure webhook:', error);
throw error;
}
console.log('Starting cleanup job...');
try {
startCleanupJob();
console.log('Cleanup job started');
} catch (error) {
console.error('Failed to start cleanup job:', error);
throw error;
}
// Start the cleanup job
startCleanupJob();
console.log('✅ Bot initialization complete');
}

Loading…
Cancel
Save