forked from 0xluen/Telegram-Bot-Register
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
40 lines (30 loc) · 1006 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
32
33
34
35
36
37
38
const TelegramBot = require('node-telegram-bot-api');
const token = 'Bot Father Token';
const bot = new TelegramBot(token, { polling: true });
const registeredUsers = {};
bot.onText(/\/register/, (msg) => {
const address = msg.text
const chatId = msg.chat.id;
const userId = msg.from.id;
if (registeredUsers[userId]) {
registeredUsers[userId].canSendMessage = true;
bot.sendMessage(chatId, 'Start successful. You can send messages now.');
} else {
registeredUsers[userId] = {
canSendMessage: false
};
bot.sendMessage(chatId, 'Register successful. You can send messages now.');
}
});
bot.on('message', (msg) => {
const chatId = msg.chat.id;
const userId = msg.from.id;
console.log(chatId)
console.log(userId)
if (!registeredUsers[userId]) {
registeredUsers[userId] = {
canSendMessage: false
};
bot.sendMessage(chatId, 'Please register first. /register');
}
});