-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
45 lines (34 loc) · 1.06 KB
/
index.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
39
40
41
42
43
44
45
const TelegramBot = require('node-telegram-bot-api');
//Telegram token from @BotFather
const token = '';
// Create a bot that uses 'polling' to fetch new updates
const bot = new TelegramBot(token, {polling: true});
// Matches "/echo [whatever]"
bot.onText(/\/echo (.+)/, (msg, match) => {
const chatId = msg.chat.id;
const resp = match[1];
let response = msg.from.first_name;
bot.sendMessage(chatId, response);
});
bot.on('message', (msg) => {
const message = msg.text;
let response = 'Response: ';
if (message === 'Who am i?') {
response = '*Your login* ' + msg.from.username;
response += '\r\n';
response += '*Your name* ' + msg.from.first_name;
response += '\r\n';
response += '*Your id* ' + msg.from.id;
}
const chatId = msg.chat.id;
let options = {
parse_mode : "Markdown",
reply_markup: {
keyboard: [
[{text:"Who am i?"}]
],
resize_keyboard : true
}
};
bot.sendMessage(chatId, response, options);
});