mirror of
https://github.com/tiennm99/tiennm99bot.git
synced 2026-10-11 03:13:46 +00:00
3.6 KiB
3.6 KiB
phase, title, status, priority, dependencies
| phase | title | status | priority | dependencies | |
|---|---|---|---|---|---|
| 2 | Command Integration And Fallback | completed | P2 |
|
Phase 2: Command Integration And Fallback
Overview
Wire /wheelofnamesbeta to try the remote API first when configured, while
preserving the existing local GIF renderer as fallback and preserving Telegram
upload behavior.
Requirements
- Functional: Keep
splitWheelOptionsandpickWheelOptionas the only winner selection source in the bot. - Functional: Use remote GIF only when API call succeeds with valid GIF bytes.
- Functional: Fall back to
renderWheelOfNamesBetaGIF(options, winner)on any remote error. - Functional: Preserve
sendAnimation,MessageThreadID, filename, and non-spoiler caption. - Non-functional: Remote failure should log enough to diagnose status/error but should not reply with stack traces or token-bearing details.
- Non-functional: Existing command behavior remains unchanged when env is unset.
Architecture
Introduce a small orchestration helper in package misc:
func renderWheelOfNamesBetaAnimation(ctx context.Context, options []string, winner int) ([]byte, int, int, int, error)
Return bytes plus Telegram metadata (duration, width, height). Suggested
metadata:
- Remote success: duration
7, width/height512. - Local fallback: existing
wheelBetaDuration,wheelBetaSize,wheelBetaSize.
Alternative: return a tiny struct:
type wheelBetaAnimation struct {
Data []byte
Duration int
Width int
Height int
}
The command handler should stay simple:
- parse options
- pick winner
- call
renderWheelOfNamesBetaAnimation - send animation
- on final render/upload failure, text fallback remains
options[winner]
Related Code Files
- Modify:
/config/workspace/tiennm99/miti99bot/internal/modules/misc/wheelofnames_beta_command.go - Modify:
/config/workspace/tiennm99/miti99bot/internal/modules/misc/wheelofnames_beta.goonly if helper placement requires it - Modify:
/config/workspace/tiennm99/miti99bot/internal/modules/misc/handlers_test.go
Implementation Steps
- Add the orchestration helper that creates the env client and attempts remote render.
- If client is unconfigured, skip remote without warning noise.
- If client is configured but fails, log warning with safe fields:
- command:
wheelofnamesbeta - status/error category
- never token or request body
- command:
- On remote success, return remote bytes and remote metadata.
- On remote failure, call current local
renderWheelOfNamesBetaGIF. - Update
wheelOfNamesBetaCommandto use returned metadata inSendAnimationParams. - Keep caption exactly
"Spinning...".
Success Criteria
- URL unset path still sends local GIF and existing tests pass.
- URL configured path calls remote service and sends remote GIF.
- Remote success path uses Telegram metadata
duration=7,width=512,height=512. - Remote failure path sends local GIF, not text, when local renderer works.
- Telegram upload failure still replies with the selected winner text.
- Caption does not contain the winner.
- Message thread forwarding remains covered.
Risk Assessment
- Risk: Remote and local metadata diverge. Mitigation: use explicit metadata struct; tests assert remote width/height and local compatibility.
- Risk: Remote API chooses a different winner.
Mitigation: always pass
winnerIndex; ignore remote winner headers for bot caption/source of truth. - Risk: A configured but down service makes the command slower. Mitigation: timeout and fallback; consider lowering timeout later only after production timing data.