start pooling only if enabled

This commit is contained in:
Dobromir Popov
2024-02-28 18:39:44 +02:00
parent 8f48ac2633
commit aa36af8615

View File

@ -7,27 +7,19 @@ const filePath = path.join(__dirname, '../content/telegram_users.json');
const token = process.env.TELEGRAM_BOT_TOKEN;
const enabled = process.env.TELEGRAM_BOT_ENABLED === 'true';
const bot = new TelegramBot(token, { polling: true });
let bot;
const telegramBot = {
Initialize: function () {
if (!enabled) {
console.log("Telegram bot is not enabled.");
return;
}
bot.on('message', handleMessage);
bot.on('new_chat_members', handleNewChatMembers);
bot.on('contact', handleContact);
bot.onText(/start/, handleStartCommand);
},
updateUserDetails: function (chatId, phoneNumber) {
// Function body remains the same
}
Initialize: initializeBot,
updateUserDetails: updateUserDetails
};
function initializeBot() {
if (!enabled) {
console.log("Telegram bot is not enabled.");
return;
}
bot = new TelegramBot(token, { polling: true });
bot.on('message', handleMessage);
bot.on('new_chat_members', handleNewChatMembers);
bot.on('contact', handleContact);