Files
halobestie-clone/requirement/phase3.md
ramadhan sjamsani b0502ac92b Phase 3 testing fixes: Fastify 5, SSE→WebSocket+FCM, enums, security, session lifecycle
- Upgrade Fastify 4→5 with all plugins (@fastify/websocket 11, cors 11, sensible 6)
- Migrate all SSE endpoints to WebSocket + FCM push (mitra chat requests, customer pairing status)
- Add flutter_local_notifications for foreground push notifications with sound
- Add splash screen to both apps (hide auth loading flash)
- Introduce constants/enums across entire codebase (no raw string literals)
- Move price tiers from hardcoded array to app_config DB (data-driven, includes 1-min test tier)
- Add session ownership validation on all shared chat routes
- Add ownership checks on endSession, respondToExtension, requestExtension
- Fix session timer: auto-complete expired/stale sessions on server restart
- Add 5-min grace period for abandoned closing sessions
- Fix extension flow: proper session_resumed handling, clearExtensionRequest, closure grace timer cleanup
- Fix chat screens: ConnectChat in initState, session status check on connect
- Fix customer expired view: 5-min countdown, closure state priority over expired state
- Fix mitra extension UI: loading spinner, disable buttons, handle EXTENSION_RESOLVED error
- Fix GoRouter navigation consistency (no more Navigator.pushNamed)
- Fix goodbye view keyboard overflow (SingleChildScrollView)
- Add active session card on customer home screen with refresh on navigate back
- Fix PricingBottomSheet extension mode (RequestExtension instead of new pairing)
- Send session_resumed to both parties on extension accept

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 00:17:25 +08:00

3.5 KiB

PRD: Chat Engine

Overview

Goal: To build chat engine between Mitra and Customer

Success looks like: When paired, Mitra and Customer can chat in a chat room. Chat will be visible on active chat page. Closed chat will be listed on the chat history

Background

  • We need capability to do chat between Mitra and Customer
  • We need capability for Customer and Mitra to see their previous chat session
  • We need to be able to give closing statement from both Mitra and Customer when the chat is ended

Functional Requirement

Chat Opening

Functinal Requirement:

  • Customer Application can start request chat session
  • Customer App will shows dialog to choose selection of time and price. This phase it will be mock only. later it will be taken from Configuration of Control Center
  • If enabled, Customer App will shows free trial instead of price selection. But this free trial only shows when following logic met:
    • Free trial is enabled
    • Customer never made any transaction (including free trial)
  • When customer choose Free trial, the chat session period will be determine by Control Center
  • After selection (either paid, or free trial), Backend will start pairing process

Bi Directional Chat

Functional requirement:

  • After pairing success, both Mitra and Customer can communicate bidirectional
  • When Mitra or Customer communication interupted (either when app is killed or network is down or app is inactive), both will still able to receive message notification
  • On Mitra's App, when push notification is coming and clicked, it must be immediately goes to specific chat with specific customer. e.g. When push notif were come for chatting with Customer A, it should be redirected to exact customer A chat, not just list of chat room
  • All chat must be recorded in database in chronological order
  • When app is opened after shutdown, it must be able to populate all conversation along
  • User (both Mitra and Customer) must be able to re read all chat history
  • Each message will have sent (one check), delivered (double check) and read (double check with blue color) status
  • When one of the person type, application will shows typing indicator

Chat Closure

  • When chat is going to end (1 minutes left), shows remaining time on the chat screen
  • When chat session is finished there will be following functionality:
    • Customer Application:
      • Show dialog window whether Customer want to extend the session
      • If Customer do not want to extend, show closing message input
      • If Customer want to extend, show dialog selection of time and price. This phase it will be mock only.
      • Wait for Mitra confirmation, shows "Menunggu konfirmasi Bestie"
        • If Mitra approve, prepare for payment process in this step
        • If Mitra reject, show closing message input
    • Mitra Application
      • If customer do not want to extend, show closing message input
      • If Customer extend, send confirmation to Mitra that customer want to extend for x minutes. Mitra can do following things:
        • Accept, and session extended for x minutes
        • Reject, show closing message input

Chat History

Functional Requirement:

  • On Customer App, customer can see previous chat history, along with session information such as Mitra name (bestie name) and closure message
  • On Mitra App, mitra can see previous chat history, along with session information such as Customer name and closure message
  • Both will able to see communication history (chat message)

Tech Stack

  • Push Notification using FCM
  • Websocket