Merge pull request #43 from reyy/master

Updated Example to use onText
experimental
Yago 10 years ago
commit 604d0ff155
  1. 23
      examples/polling.js

@ -11,14 +11,16 @@ var bot = new TelegramBot(token, options);
bot.getMe().then(function (me) { bot.getMe().then(function (me) {
console.log('Hi my name is %s!', me.username); console.log('Hi my name is %s!', me.username);
}); });
bot.on('text', function (msg) {
bot.onText(/\/photo.*/, function (msg) {
var chatId = msg.chat.id; var chatId = msg.chat.id;
if (msg.text == '/photo') {
// From file // From file
var photo = __dirname+'/../test/bot.gif'; var photo = __dirname+'/../test/bot.gif';
bot.sendPhoto(chatId, photo, {caption: "I'm a bot!"}); bot.sendPhoto(chatId, photo, {caption: "I'm a bot!"});
} });
if (msg.text == '/audio') {
bot.onText(/\/audio.*/, function (msg) {
var chatId = msg.chat.id;
var url = 'https://upload.wikimedia.org/wikipedia/commons/c/c8/Example.ogg'; var url = 'https://upload.wikimedia.org/wikipedia/commons/c/c8/Example.ogg';
// From HTTP request! // From HTTP request!
var audio = request(url); var audio = request(url);
@ -28,8 +30,10 @@ bot.on('text', function (msg) {
var messageId = resp.message_id; var messageId = resp.message_id;
bot.forwardMessage(chatId, chatId, messageId); bot.forwardMessage(chatId, chatId, messageId);
}); });
} });
if (msg.text == '/love') {
bot.onText(/\/love.*/, function (msg) {
var chatId = msg.chat.id;
var opts = { var opts = {
reply_to_message_id: msg.message_id, reply_to_message_id: msg.message_id,
reply_markup: JSON.stringify({ reply_markup: JSON.stringify({
@ -39,5 +43,10 @@ bot.on('text', function (msg) {
}) })
}; };
bot.sendMessage(chatId, 'Do you love me?', opts); bot.sendMessage(chatId, 'Do you love me?', opts);
} });
bot.onText(/\/echo (.+)/, function (msg, match) {
var chatId = msg.chat.id;
var resp = match[1];
bot.sendMessage(chatId, resp);
}); });

Loading…
Cancel
Save