2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-29 05:17:41 +00:00

Replace msg.from.id with msg.chat.id

This commit is contained in:
Rey 2015-10-20 01:01:16 +08:00
parent 59d47f1fba
commit d03134e667

View File

@ -13,27 +13,27 @@ bot.getMe().then(function (me) {
}); });
bot.onText(/\/photo.*/, function (msg) { bot.onText(/\/photo.*/, function (msg) {
var fromId = msg.from.id; var chatId = msg.chat.id;
// From file // From file
var photo = __dirname+'/../test/bot.gif'; var photo = __dirname+'/../test/bot.gif';
bot.sendPhoto(fromId, photo, {caption: "I'm a bot!"}); bot.sendPhoto(chatId, photo, {caption: "I'm a bot!"});
}); });
bot.onText(/\/audio.*/, function (msg) { bot.onText(/\/audio.*/, function (msg) {
var fromId = msg.from.id; 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);
bot.sendAudio(fromId, audio) bot.sendAudio(chatId, audio)
.then(function (resp) { .then(function (resp) {
// Forward the msg // Forward the msg
var messageId = resp.message_id; var messageId = resp.message_id;
bot.forwardMessage(fromId, fromId, messageId); bot.forwardMessage(chatId, chatId, messageId);
}); });
}); });
bot.onText(/\/love.*/, function (msg) { bot.onText(/\/love.*/, function (msg) {
var fromId = msg.from.id; 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({
@ -42,11 +42,11 @@ bot.onText(/\/love.*/, function (msg) {
['No, sorry there is another one...']] ['No, sorry there is another one...']]
}) })
}; };
bot.sendMessage(fromId, 'Do you love me?', opts); bot.sendMessage(chatId, 'Do you love me?', opts);
}); });
bot.onText(/\/echo (.+)/, function (msg, match) { bot.onText(/\/echo (.+)/, function (msg, match) {
var fromId = msg.from.id; var chatId = msg.chat.id;
var resp = match[1]; var resp = match[1];
bot.sendMessage(fromId, resp); bot.sendMessage(chatId, resp);
}); });