From d948fc1f367ee8aff825b50f5d768c1f39f01d27 Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Sat, 5 Mar 2022 22:48:24 +0300 Subject: [PATCH] Fix reply message not found --- src/bots/factory/bots/approved/errors_utils.ts | 6 ++++++ src/bots/factory/bots/approved/index.ts | 16 +++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/bots/factory/bots/approved/errors_utils.ts b/src/bots/factory/bots/approved/errors_utils.ts index 1d96c29..165afd7 100644 --- a/src/bots/factory/bots/approved/errors_utils.ts +++ b/src/bots/factory/bots/approved/errors_utils.ts @@ -6,3 +6,9 @@ export function isNotModifiedMessage(e: any): boolean { return e.description === 'Bad Request: message is not modified: specified new message content and reply markup are exactly the same as a current content and reply markup of the message'; } + +export function isReplyMessageNotFound(e: any): boolean { + if (!(e instanceof TelegramError)) return false; + + return e.description === 'Bad Request: replied message not found'; +} diff --git a/src/bots/factory/bots/approved/index.ts b/src/bots/factory/bots/approved/index.ts index 840eb3b..681af2a 100644 --- a/src/bots/factory/bots/approved/index.ts +++ b/src/bots/factory/bots/approved/index.ts @@ -20,7 +20,7 @@ import { getRandomKeyboard, getTextPaginationData, getUpdateLogKeyboard, getUser import { sendFile } from './hooks/downloading'; import { setCommands } from './hooks/setCommands'; import { downloadImage } from './services/downloader'; -import { isNotModifiedMessage } from './errors_utils'; +import { isNotModifiedMessage, isReplyMessageNotFound } from './errors_utils'; Sentry.init({ @@ -378,10 +378,16 @@ export async function createApprovedBot(token: string, state: BotState): Promise ] ]); - await ctx.telegram.sendMessage(ctx.message.chat.id, Messages.SEARCH_MESSAGE, { - reply_to_message_id: ctx.message.message_id, - reply_markup: keyboard.reply_markup, - }); + try { + await ctx.telegram.sendMessage(ctx.message.chat.id, Messages.SEARCH_MESSAGE, { + reply_to_message_id: ctx.message.message_id, + reply_markup: keyboard.reply_markup, + }); + } catch (e) { + if (!isReplyMessageNotFound(e)) { + Sentry.captureException(e); + } + } }); bot.catch((err) => {