2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-29 13:27:44 +00:00

Merge pull request #43 from reyy/master

Updated Example to use onText
This commit is contained in:
Yago 2015-10-20 02:41:51 +08:00
commit 604d0ff155

View File

@ -11,15 +11,17 @@ var bot = new TelegramBot(token, options);
bot.getMe().then(function (me) {
console.log('Hi my name is %s!', me.username);
});
bot.on('text', function (msg) {
bot.onText(/\/photo.*/, function (msg) {
var chatId = msg.chat.id;
if (msg.text == '/photo') {
// From file
var photo = __dirname+'/../test/bot.gif';
bot.sendPhoto(chatId, photo, {caption: "I'm a bot!"});
}
if (msg.text == '/audio') {
var url = 'https://upload.wikimedia.org/wikipedia/commons/c/c8/Example.ogg';
// From file
var photo = __dirname+'/../test/bot.gif';
bot.sendPhoto(chatId, photo, {caption: "I'm a bot!"});
});
bot.onText(/\/audio.*/, function (msg) {
var chatId = msg.chat.id;
var url = 'https://upload.wikimedia.org/wikipedia/commons/c/c8/Example.ogg';
// From HTTP request!
var audio = request(url);
bot.sendAudio(chatId, audio)
@ -28,9 +30,11 @@ bot.on('text', function (msg) {
var messageId = resp.message_id;
bot.forwardMessage(chatId, chatId, messageId);
});
}
if (msg.text == '/love') {
var opts = {
});
bot.onText(/\/love.*/, function (msg) {
var chatId = msg.chat.id;
var opts = {
reply_to_message_id: msg.message_id,
reply_markup: JSON.stringify({
keyboard: [
@ -39,5 +43,10 @@ bot.on('text', function (msg) {
})
};
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);
});