Logging Only the Selected Inline Result in Python Telegram Bot

My Telegram bot logs all inline queries, including non-selected ones. How can I log solely the chosen result? Example code:


def process_chosen_inline(bot_service, update_obj):
    user_handle = update_obj.inline_query.from_user.username
    query_str = update_obj.inline_query.query
    if not query_str:
        return
    articles = [
        InlineQueryResultArticle(
            id=query_str[::-1],
            title="Reverse Text",
            input_message_content=InputTextMessageContent(query_str[::-1])
        )
    ]
    bot_service.answerInlineQuery(update_obj.inline_query.id, articles)
    custom_logger.info(f"{user_handle} selected an inline option")

try registering a chosen_inline_result handler instead. its only fired once a result is picked so you log just that call instead of each inline query. it worked for my bot, so give it a go

The solution may lie in using the chosen inline result update rather than processing during the inline query. From my experience, setting up a separate handler for the chosen_inline_result event simplifies logging since it triggers after a user selects an option. This method ensures that only valid, selected results are logged. It is advisable to update the underlying library if needed and verify compatibility with the event types mentioned in the documentation. Adopting this approach has helped me manage logging without capturing unnecessary data.