From 96d457ab115c0b1090ebfce31da8e14328690c32 Mon Sep 17 00:00:00 2001 From: Fabian Stamm Date: Wed, 26 Apr 2023 19:53:45 +0200 Subject: [PATCH] Add small UX improvements --- package.json | 2 +- src/telegram.ts | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index f2b70a4..ef9a9e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rss-telegram-bot", - "version": "2.0.0", + "version": "2.0.1", "main": "lib/index.js", "author": "Fabian Stamm ", "license": "MIT", diff --git a/src/telegram.ts b/src/telegram.ts index ce589ed..3700f59 100644 --- a/src/telegram.ts +++ b/src/telegram.ts @@ -64,23 +64,35 @@ bot.command("delete", botHandler(async ctx => { bot.on("callback_query", botHandler(async ctx => { Logging.info("Callback Query received"); - const remove_options = () => { + const remove_options = (message: string) => { ctx.editMessageReplyMarkup({ - inline_keyboard: [] + inline_keyboard: [], }) + ctx.editMessageText(message) } let data = (ctx.callbackQuery as any).data; if (!data) { ctx.answerCbQuery("Invalid data"); - remove_options(); + remove_options("Delete failed. Invalid data received."); return } let [action, id] = data.split(":"); if (!action || !id) { ctx.answerCbQuery("Invalid data"); - remove_options(); + remove_options("Delete failed. Invalid data received."); + return + } + let feed = await AppDataSource.manager.findOne(Feed, { + where: { + id: Number(id) + } + }); + + if (!feed) { + ctx.answerCbQuery("Invalid action"); + remove_options("Delete failed. Feed not available."); return } @@ -100,12 +112,12 @@ bot.on("callback_query", botHandler(async ctx => { } } else { ctx.answerCbQuery("Invalid action"); - remove_options(); + remove_options("Delete failed. Invalid data received."); return } ctx.answerCbQuery("Success"); - remove_options(); + remove_options("Deleted feed: " + feed.url); })); bot.on(message("text", "entities"), botHandler(async ctx => {