depoio / node-telegram-bot

Client wrapper for Telegram Bot API (Under heavy development)
MIT License
136 stars 30 forks source link

Quick fix for a problem with edited messages (no `msg.message`; but messages include a `msg.edited_message`) #70

Closed convexset closed 8 years ago

convexset commented 8 years ago

There is a problem with _poll when messages are edited before being read.

msg.message is missing when a message is edited, msg.edited_message is available

I've provided a very quick fix. But you might want to do something more comprehensive.

Bot.prototype._poll = function () {
  var self = this;

/* Some Code */
              if (self.parseCommand) {
////////////////////////////////////////////////////////////
// QUICK FIX HERE
////////////////////////////////////////////////////////////
// a quick fix because msg.message is missing when a message is edited, ...
// but msg.edited_message is available
// put this where you think it makes sense
if (!!msg.edited_message) {
  msg.message = msg.edited_message;
  console.log("Monkey Patch for Edited Messages:", msg);
}
////////////////////////////////////////////////////////////
                if (msg.message.text && msg.message.text.charAt(0) === '/') {
                  /**
/* Some Code */

Here's what a msg.edited_message looks like:

   { message_id: 869,
     from: { id: 179442020, first_name: 'xxx', username: 'xxxx' },
     chat: 
      { id: 0000,
        first_name: 'xxx',
        username: 'xxxx',
        type: 'private' },
     date: 1463978414,
     edit_date: 1463978429,
     text: 'f' },
theshaun commented 8 years ago

works brilliantly!

convexset commented 8 years ago

Great. Thanks for the package.

On Tuesday, 24 May 2016, Shaun Walker notifications@github.com wrote:

works brilliantly!

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/depoio/node-telegram-bot/issues/70#issuecomment-221203197

Regards, Jeremy Chen

kdemoya commented 8 years ago

Is anyone planning to do a PR for this? I'm willing to jump in if no one is working on one.

convexset commented 8 years ago

Not me. I don't know enough about the package and API. I've checked that forwarding messages to it works, receiving audio is also fine. The only strange exception I've noted is edited messages.

Waiting for a new version to replace my monkey patched one.

Regards, Jeremy Chen

On Wed, May 25, 2016 at 10:01 AM, Kelvin De Moya notifications@github.com wrote:

Is anyone planning to do a PR for this? I'm willing to jump in if no one is working on one.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/depoio/node-telegram-bot/issues/70#issuecomment-221453995

theshaun commented 8 years ago

I've created a PR that should resolve this issue, happy to make adjustments where required