All Stories
11-6-bet-outcome-notificationsReadyEpic 11.6
Story 11.6: Bet Outcome Notifications
Status: ready-for-dev
Tasks
- Task 1: Create BetOutcomeNotifier Service (AC: #1, #6, #7)
- 1.1: Create `server/app/services/notifications/bet_outcome.py` with BetOutcomeNotifier class
- 1.2: Implement `on_bet_settled(bet)` method to handle bet grading events
- 1.3: Implement `_queue_for_batch(bet)` to add bet to Redis batch queue (5 second window)
- 1.4: Implement `_process_batch_after_delay(user_id)` to wait for batch window
- 1.5: Implement `_process_batch(user_id)` to send batched or single notifications
- 1.6: Add user preference check with `should_send_notification(user_id, "bet_results")`
- 1.7: Unit test: verify batching logic groups bets within 5 second window
- Task 2: Implement Notification Message Templates (AC: #2, #4, #5)
- 2.1: Create `_build_notification(bet)` method to build notification content
- 2.2: Implement `_get_win_body(bet)` for win messages with payout amount
- 2.3: Implement `_get_loss_body(bet)` for loss messages
- 2.4: Implement win notification with green color (#22c55e) and "win" icon
- 2.5: Implement loss notification with red color (#ef4444) and "loss" icon
- 2.6: Implement push notification with gray color (#6b7280) and "push" icon
- 2.7: Add parlay leg-by-leg summary logic for parlay bets
- 2.8: Unit test: verify message templates for all bet types
- Task 3: Implement Deep Links (AC: #3)
- 3.1: Add `action_url` field to notification: `/bets/{bet_id}`
- 3.2: Add bet metadata to notification data payload (type, bet_id, status, payout)
- 3.3: Test deep link navigation from notification to bet details page
- Task 4: Create Batch Notification Logic (AC: #6)
- 4.1: Implement `_send_batch_notification(user_id, bets)` for multiple settlements
- 4.2: Calculate summary stats (wins count, losses count, pushes count, total payout)
- 4.3: Build batch notification message (e.g., "3 bets won ($150), 1 lost")
- 4.4: Add batch metadata to notification data payload (bet_ids list, summary object)
- 4.5: Set batch notification action_url to `/bets` (all bets page)
- 4.6: Unit test: verify batch summary calculation
- Task 5: Integrate with BetGraderService (AC: #1)
- 5.1: Import BetOutcomeNotifier in `server/app/services/grader/bet_grader_service.py`
- 5.2: Add `on_bet_graded` callback hook in `_update_bet_status` method
- 5.3: Pass bet data to `bet_outcome_notifier.on_bet_settled(bet)` after grading
- 5.4: Add error handling for notification failures (don't block bet grading)
- 5.5: Integration test: grade bet → verify notification sent
- Task 6: Track Notification Delivery Status
- 6.1: Create `notification_logs` table with columns: id, user_id, notification_type, bet_id, status, sent_at, delivered_at
- 6.2: Log notification send attempts to notification_logs
- 6.3: Update delivery status when confirmation received from FCM/APNs
- 6.4: Add retry logic for failed notifications (exponential backoff)
- 6.5: Unit test: verify delivery tracking
- Task 7: Error Handling & Fallback (AC: #7)
- 7.1: Handle missing user preference data (default: send notification)
- 7.2: Handle Redis connection failure (fallback to immediate notification, skip batching)
- 7.3: Handle notification dispatcher queue full (log error, continue bet grading)
- 7.4: Add comprehensive error logging for debugging
- 7.5: Unit test: verify error handling scenarios
Progress
Tasks0/7
Acceptance Criteria0
Total Tasks7