Skip to content

Edited messages causes library to break #80

@fcanela

Description

@fcanela

When the server sends a message like (personal information redacted and user id modified):

{ update_id: 404781694,
  edited_message: 
   { message_id: 11,
     from: 
      { id: 152564221,
        first_name: 'REDACTED',
        last_name: 'Redacted',
        username: 'redacted' },
     chat: 
      { id: 152564221,
        first_name: 'Redacted',
        last_name: 'Redacted',
        username: 'redacted',
        type: 'private' },
     date: 1471044047,
     edit_date: 1471044102,
     text: '/asignatura ean',
     entities: [ [Object] ] } }

The following error is raised:

/home/fcanela/workspace/lab/silly_motivational_bot/node_modules/node-telegram-bot/lib/Bot.js:221
                if (msg.message.text && msg.message.text.charAt(0) === '/') {
                               ^

TypeError: Cannot read property 'text' of undefined
    at /home/fcanela/workspace/lab/silly_motivational_bot/node_modules/node-telegram-bot/lib/Bot.js:221:32
    at Array.forEach (native)
    at Request._callback (/home/fcanela/workspace/lab/silly_motivational_bot/node_modules/node-telegram-bot/lib/Bot.js:216:23)
    at Request.self.callback (/home/fcanela/workspace/lab/silly_motivational_bot/node_modules/request/request.js:187:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:191:7)
    at Request.<anonymous> (/home/fcanela/workspace/lab/silly_motivational_bot/node_modules/request/request.js:1044:10)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:188:7)
    at IncomingMessage.<anonymous> (/home/fcanela/workspace/lab/silly_motivational_bot/node_modules/request/request.js:965:12)

This behaviour can be reproduced this way:

  1. Sending a command using Linux client
  2. Pressing up key in the text area, an "Edit message" label will appear
  3. Resending the command or writing a new one

A dirty and quick fix that solved my issue was referencing msg.message to msg.edited_message. Starting from line 216:

          body.result.forEach(function (msg) {
                        if (msg.edited_message) msg.message = msg.edited_message;

There should be probably a better option, but I have no time to validate it right now. I hope this help.

Thanks for the library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions