feat: add animated loading placeholder for AI response generation#43
Merged
Afdaan merged 2 commits intofeat/voicefrom Mar 15, 2026
Merged
feat: add animated loading placeholder for AI response generation#43Afdaan merged 2 commits intofeat/voicefrom
Afdaan merged 2 commits intofeat/voicefrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This Pull Request introduces a significant user experience improvement for the bot. Instead of only displaying the default "Typing..." status indicator, the bot now sends an initial quote block placeholder message containing an animated loading text while the AI response is being generated.
This approach provides immediate visual feedback to the user and creates a more responsive interaction pattern, similar to modern AI interfaces such as ChatGPT or Claude when generating longer responses.
The loading message dynamically updates its text at regular intervals until the final response is ready.
Key Features
Standard Chat and Conversations
Displays an animated loading message:
The placeholder text updates periodically while the model generates a response.
Media and Document Analysis (
!ask)Displays an animated loading message indicating that the content is being analyzed:
Roast Mode (
!roastand!gitroast)Displays an animated loading message before generating the roast response:
Voice Messages (TTS)
For voice responses, a loading message is displayed while the text-to-speech process runs:
The loading message is automatically deleted immediately before the generated voice message is sent by the Alya-TTS microservice.
Technical Changes and Refactoring
To comply with the project Code Standards and follow DRY and Single Responsibility principles, several structural improvements were implemented.
Centralized Animation Helper
All duplicated animation loops previously implemented inside individual handlers have been extracted into a shared helper function:
start_loading_animation()Location:
utils/telegram_helpers.pyThis centralization ensures consistent behavior across handlers and simplifies maintenance.
Garbage Collection Protection for Background Tasks
A global
setnamed:_active_animationsis used to maintain a strong reference to running asyncio animation tasks. Without this reference, Python’s garbage collector could prematurely terminate background tasks when new events arrive during the loading phase.
This ensures animation tasks remain active until explicitly cancelled.
Telegram Rate Limit Handling
The animation task now handles Telegram Flood Limit responses. When a rate limit occurs, the task reads the
Retry-Aftervalue returned by the Telegram API and dynamically adjusts the animation interval to prevent repeated API violations.TTS Microservice Payload Support
The TTS request payload now includes the following field:
loading_message_idThis allows the external Alya-TTS FastAPI microservice to directly delete the loading placeholder message before sending the final
send_voiceresponse.This ensures the user only sees the final voice message without any intermediate loading artifacts.
Files Modified
handlers/conversation.pyhandlers/voice.pyutils/analyze.pyutils/roast.pyutils/telegram_helpers.pyutils/tts_queue.pyDeployment Notes
The external Alya-TTS Microservice requires a manual restart to apply the updated FastAPI payload schema.