-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot_telegram.js
27 lines (22 loc) · 945 Bytes
/
bot_telegram.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
var TelegramBot = require('node-telegram-bot-api');
var token = 'YOUR_TELEGRAM_BOT_TOKEN';
var bot = new TelegramBot(token, {polling: true});
bot.onText(//start/, function (msg) {
var chatId = msg.chat.id;
bot.sendMessage(chatId, "Hi! I am a Telegram bot. How can I help you today?");
});
bot.onText(//help/, function (msg) {
var chatId = msg.chat.id;
bot.sendMessage(chatId, "I can do the following things:\n- /start: Start the bot\n- /help: Display this help message\n- /echo [text]: Echo the text back to you\n- /weather [city]: Get the current weather for the specified city");
});
bot.onText(//echo (.+)/, function (msg, match) {
var chatId = msg.chat.id;
var text = match[1];
bot.sendMessage(chatId, text);
});
bot.onText(//weather (.+)/, function (msg, match) {
var chatId = msg.chat.id;
var city = match[1];
// code to get current weather for the specified city
// and send it back to the user via the bot
});