From cef21860eb32099012aa7ab2daedd58d2d43715b Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 24 Dec 2024 13:25:59 +0100 Subject: [PATCH] feat: add _tg_info endpoint for easier information gathering --- freqtrade/rpc/telegram.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 262976d89..106659f1c 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -299,6 +299,7 @@ class Telegram(RPCHandler): CommandHandler("marketdir", self._changemarketdir), CommandHandler("order", self._order), CommandHandler("list_custom_data", self._list_custom_data), + CommandHandler("tg_info", self._tg_info), ] callbacks = [ CallbackQueryHandler(self._status_table, pattern="update_status_table"), @@ -2122,3 +2123,35 @@ class Telegram(RPCHandler): "Invalid usage of command /marketdir. \n" "Usage: */marketdir [short | long | even | none]*" ) + + async def _tg_info(self, update: Update, context: CallbackContext) -> None: + """ + Intentionally unauthenticated Handler for /tg_info. + Returns information about the current telegram chat - even if chat_id does not + correspond to this chat. + + :param update: message update + :return: None + """ + chat_id = update.message.chat_id + topic_id = update.message.message_thread_id + + msg = f"""Freqtrade Bot Info: + ```json + {{ + "enabled": true, + "token": "********", + "chat_id": "{chat_id}", + {f'"topic_id": "{topic_id}"' if topic_id else ""} + }} + ``` + """ + try: + await context.bot.send_message( + chat_id=chat_id, + text=msg, + parse_mode=ParseMode.MARKDOWN_V2, + message_thread_id=topic_id, + ) + except TelegramError as telegram_err: + logger.warning("TelegramError: %s! Giving up on that message.", telegram_err.message)