-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
31 lines (27 loc) · 975 Bytes
/
bot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const TelegramBot = require("node-telegram-bot-api");
const Users = require("./models/User");
const Clients = require("./models/Client")
const token = process.env.BOT_TOKEN;
const bot = new TelegramBot(token, { polling: true });
bot.onText(/\/start/, async (msg) => {
const chatId = msg.chat.id;
const username = msg.from.username;
const findUser = await Users.findOne({ username: username, bot: true });
const findClient = await Clients.findOne({ username: username, bot: true });
if(findUser) {
findUser.chatId = chatId;
await findUser.save();
bot.sendMessage(chatId, `Salom ${findUser.name} botga xush kelibsiz 👋`);
} else if (findClient) {
findClient.chatId = chatId;
await findClient.save();
bot.sendMessage(chatId, `Salom ${findClient.name} botga xush kelibsiz 👋`);
} else {
bot.sendMessage(
chatId,
"Kechirasiz sizda botdan foydalanish uchun ruxsat yoq!"
);
return;
}
});
module.exports = bot;