2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-23 02:17:16 +00:00

53 lines
1.4 KiB
JavaScript
Raw Normal View History

2015-06-29 00:37:40 +02:00
var TelegramBot = require('../src/telegram');
var request = require('request');
var options = {
polling: true
};
2015-08-08 12:01:52 +02:00
var token = process.env.TELEGRAM_BOT_TOKEN || 'YOUR_TELEGRAM_BOT_TOKEN';
2015-06-29 00:37:40 +02:00
var bot = new TelegramBot(token, options);
bot.getMe().then(function (me) {
console.log('Hi my name is %s!', me.username);
});
2015-10-20 00:01:02 +08:00
2015-10-19 20:44:02 +02:00
bot.onText(/\/photo/, function (msg) {
2015-10-20 01:01:16 +08:00
var chatId = msg.chat.id;
2015-10-20 00:01:02 +08:00
// From file
var photo = __dirname+'/../test/bot.gif';
2015-10-20 01:01:16 +08:00
bot.sendPhoto(chatId, photo, {caption: "I'm a bot!"});
2015-10-20 00:01:02 +08:00
});
2015-10-19 20:44:02 +02:00
bot.onText(/\/audio/, function (msg) {
2015-10-20 01:01:16 +08:00
var chatId = msg.chat.id;
2015-10-20 00:01:02 +08:00
var url = 'https://upload.wikimedia.org/wikipedia/commons/c/c8/Example.ogg';
2015-06-29 00:37:40 +02:00
// From HTTP request!
var audio = request(url);
2015-10-20 01:01:16 +08:00
bot.sendAudio(chatId, audio)
2015-06-29 00:37:40 +02:00
.then(function (resp) {
// Forward the msg
var messageId = resp.message_id;
2015-10-20 01:01:16 +08:00
bot.forwardMessage(chatId, chatId, messageId);
2015-06-29 00:37:40 +02:00
});
2015-10-20 00:01:02 +08:00
});
2015-10-19 20:44:02 +02:00
bot.onText(/\/love/, function (msg) {
2015-10-20 01:01:16 +08:00
var chatId = msg.chat.id;
2015-10-20 00:01:02 +08:00
var opts = {
2015-07-07 23:15:58 +02:00
reply_to_message_id: msg.message_id,
reply_markup: JSON.stringify({
keyboard: [
['Yes, you are the bot of my life ❤'],
['No, sorry there is another one...']]
})
};
2015-10-20 01:01:16 +08:00
bot.sendMessage(chatId, 'Do you love me?', opts);
2015-10-20 00:01:02 +08:00
});
bot.onText(/\/echo (.+)/, function (msg, match) {
2015-10-20 01:01:16 +08:00
var chatId = msg.chat.id;
2015-10-20 00:01:02 +08:00
var resp = match[1];
2015-10-20 01:01:16 +08:00
bot.sendMessage(chatId, resp);
2015-06-29 00:37:40 +02:00
});