2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-23 18:38:01 +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
bot.onText(/\/photo.*/, function (msg) {
var fromId = msg.from.id;
// From file
var photo = __dirname+'/../test/bot.gif';
bot.sendPhoto(fromId, photo, {caption: "I'm a bot!"});
});
bot.onText(/\/audio.*/, function (msg) {
var fromId = msg.from.id;
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 00:01:02 +08:00
bot.sendAudio(fromId, audio)
2015-06-29 00:37:40 +02:00
.then(function (resp) {
// Forward the msg
var messageId = resp.message_id;
2015-10-20 00:01:02 +08:00
bot.forwardMessage(fromId, fromId, messageId);
2015-06-29 00:37:40 +02:00
});
2015-10-20 00:01:02 +08:00
});
bot.onText(/\/love.*/, function (msg) {
var fromId = msg.from.id;
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 00:01:02 +08:00
bot.sendMessage(fromId, 'Do you love me?', opts);
});
bot.onText(/\/echo (.+)/, function (msg, match) {
var fromId = msg.from.id;
var resp = match[1];
bot.sendMessage(fromId, resp);
2015-06-29 00:37:40 +02:00
});