start pooling only if enabled
This commit is contained in:
@ -7,27 +7,19 @@ const filePath = path.join(__dirname, '../content/telegram_users.json');
|
|||||||
const token = process.env.TELEGRAM_BOT_TOKEN;
|
const token = process.env.TELEGRAM_BOT_TOKEN;
|
||||||
const enabled = process.env.TELEGRAM_BOT_ENABLED === 'true';
|
const enabled = process.env.TELEGRAM_BOT_ENABLED === 'true';
|
||||||
|
|
||||||
const bot = new TelegramBot(token, { polling: true });
|
let bot;
|
||||||
|
|
||||||
const telegramBot = {
|
const telegramBot = {
|
||||||
Initialize: function () {
|
Initialize: initializeBot,
|
||||||
if (!enabled) {
|
updateUserDetails: updateUserDetails
|
||||||
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
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function initializeBot() {
|
function initializeBot() {
|
||||||
|
if (!enabled) {
|
||||||
|
console.log("Telegram bot is not enabled.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bot = new TelegramBot(token, { polling: true });
|
||||||
bot.on('message', handleMessage);
|
bot.on('message', handleMessage);
|
||||||
bot.on('new_chat_members', handleNewChatMembers);
|
bot.on('new_chat_members', handleNewChatMembers);
|
||||||
bot.on('contact', handleContact);
|
bot.on('contact', handleContact);
|
||||||
|
Reference in New Issue
Block a user