bostrot / telegram-support-bot

A Telegram ticketing/supporting system.
https://botspace.bostrot.com
GNU General Public License v3.0
447 stars 152 forks source link

Messages are lost on Exception #52

Closed 2naive closed 3 years ago

2naive commented 3 years ago

Describe the bug If any error happens on sending message from/to user -> message just got lost and moderator/users receives reply that everything is fine https://github.com/bostrot/telegram-support-bot/blob/master/src/text.ts#L19

To Reproduce Steps to reproduce the behavior:

  1. Send < to bot
  2. You will get Thank you for contacting us. We will answer as soon as possible.
  3. No message would be sent to support group due to error
  4. Send 1 to bot
  5. Reply to 1 with < from support group
  6. You will get Message sent to user Alexander but no message would be sent due to error

Expected behavior

  1. If ANY error happens -> catch it, reply with "Error happend" to sender, notify support group about an error.
  2. Special chars should be escaped
greensms_bot    | === UNHANDLED REJECTION ===
greensms_bot    | "Fri Apr 23 2021 00:31:56 GMT+0000 (Coordinated Universal Time): Error: 400: Bad Request: can't parse entities: Unclosed start tag at byte offset 60\n" +
greensms_bot    |   '    at /bot/node_modules/telegraf/core/network/client.js:281:17\n' +
greensms_bot    |   '    at processTicksAndRejections (node:internal/process/task_queues:94:5)'
2naive commented 3 years ago

I've lost so many messages from/to my clients this year because of this :(

2naive commented 3 years ago

And bot.catch() https://github.com/bostrot/telegram-support-bot/blob/master/src/index.ts#L91 is not working due to: https://github.com/telegraf/telegraf/issues/491 or could be solved just with


bot.catch((err, ctx) => {
  console.log('Error: ', err)
  ctx.reply('Message is not sent due to an error')
});
bostrot commented 3 years ago

The code you posted doesn't work with unhandled rejections. For now I escaped some HTML characters as a quick fix and made the error handler send a message to the staffchat in case anything happens.

See 9f44bd6d19272a8bb0bc5aae08d507e5c1526c22.