don't start telegram bot if not enabled by environment

This commit is contained in:
Dobromir Popov
2024-02-28 17:15:59 +02:00
parent c1a567cad7
commit 8f48ac2633
3 changed files with 9 additions and 0 deletions

1
.env
View File

@ -44,4 +44,5 @@ EMAIL_FROM=noreply@example.com
GMAIL_EMAIL_USERNAME=
GMAIL_EMAIL_APP_PASS=
TELEGRAM_BOT=false
TELEGRAM_BOT_TOKEN=7050075088:AAH6VRpNCyQd9x9sW6CLm6q0q4ibUgYBfnM

View File

@ -11,3 +11,5 @@ SSL_KEY=./certificates/localhost-key.pem
SSL_CERT=./certificates/localhost.pem
DATABASE_URL=mysql://root:Zelen0ku4e@192.168.0.10:3306/cart_dev
TELEGRAM_BOT=true

View File

@ -5,11 +5,17 @@ const TelegramBot = require('node-telegram-bot-api');
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 });
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);