tududi/backend/services/telegramInitializer.js
Antonis Anastasiadis c24bff1882
Parallelize test running (#166)
* Allow specifying DB file explicitely.

* Export config getter/setter instead of object

Allows dynamically changing configuration

* Remove maxWorker Jest limit, parallelize tests

* Remove unnecessary slow step in Dockerfile.

* Correct error response during login

* Fix setting DB permissions in docker entrypoint

---------

Co-authored-by: antanst <>
2025-07-16 13:27:57 +03:00

32 lines
983 B
JavaScript

const telegramPoller = require('./telegramPoller');
const { User } = require('../models');
const { setConfig, getConfig } = require('../config/config');
const config = getConfig();
async function initializeTelegramPolling() {
if (config.environment === 'test' || config.disableTelegram) {
return;
}
try {
// Find users with configured Telegram tokens
const usersWithTelegram = await User.findAll({
where: {
telegram_bot_token: {
[require('sequelize').Op.ne]: null,
},
},
});
if (usersWithTelegram.length > 0) {
// Add each user to the polling list
for (const user of usersWithTelegram) {
await telegramPoller.addUser(user);
}
}
} catch (error) {
// Telegram polling will be initialized later when the database is available
}
}
module.exports = { initializeTelegramPolling };