masaruk Logo

analysis/04-functional-spec/notifications-and-messaging-module.md

Notifications & Messaging

Notifications & Messaging Module – Functional Specification

1. Purpose

The Notifications & Messaging Module enables the platform to:

  • Send system notifications to users (B2C mobile & web)
  • Allow providers and admins to send text messages directly to customers
  • Deliver transactional updates related to bookings, payments, trips, and ratings
  • Integrate with Firebase Push Notifications and SMS providers
  • Provide an in-dashboard messaging modal for contacting customers

2. Notification Channels

Push Notifications

Firebase Cloud Messaging

SMS

SMS Provider Integration

Email

SMTP / Email Service

In-App

Notification Center

4. Notification Entity Fields

FieldTypeNotes
idPK
user_idFKReceiver
titleString
bodyText
typeEnumbooking_update, payment_update, trip_status, rating_request, general
sourceEnumsystem / admin / provider
deep_linkStringURL or mobile route
read_attimestamp, nullable
created_attimestamp
updated_attimestamp

5. Message Entity Fields

FieldTypeNotes
idPK
sender_idFK
receiver_idFK
booking_idFK, nullable
subjectStringSubject
bodyTextMessage text
created_attimestamp

UI fields: 'Customer Name' (auto-filled), 'Mobile Number', 'Subject', 'Message Text'

6. Business Rules

BR-1. Users must receive booking updates

Triggered automatically upon: Successful payment, Booking confirmation, Booking cancellation, Trip completion, Rating request prompt.

BR-2. Admin/Provider can send manual messages

From UI modal: Must provide subject + body. System stores message and optionally sends SMS, Email, Push notification.

BR-3. Notifications must reflect system states

  • 'Your booking is confirmed' → when booking status = Confirmed
  • 'Your booking is cancelled' → when booking status = Cancelled
  • 'Your trip starts tomorrow' → pre-trip reminder
  • 'Please rate your trip' → rating-request after completion

BR-4. Read receipts only apply inside the app

read_at updates only when user opens notification center or specific notification deep link.

BR-5. Messaging is not a live chat

Per UI, the feature is: One-directional, Manual, Not continuous conversation.

BR-6. Notification templates must support Arabic labels exactly as in UI

  • 'Your rating has been submitted successfully'
  • 'Your booking is confirmed successfully'
  • 'Thank you for choosing MASARUK'

BR-7. Provider/Admin cannot message a user with no booking

UI modal is inside Booking Details → messaging is contextual, not global.

7. Actions & Behaviors

A-1. Send Notification (system-triggered)

Occurs on:

  • Booking completion
  • Payment update
  • Trip reminders
  • Rating request ('How was your trip?')
  • Trip cancellation

Push → Email → SMS (fallback)

A-2. Send Manual Message

  1. Opens booking
  2. Clicks 'Send message to customer'
  3. Fills: subject, body
  4. Sends
  5. User receives SMS + push

A-3. Mark Notification as Read

Triggered when user views the item.

A-4. Deep Linking

Notification may lead user to: Trip details, Booking details, Rating modal, Payment receipt.

8. Validation Rules

FieldRule
subjectrequired, max 120 chars
bodyrequired
receiver_idmust exist
booking_idmust belong to receiver (if provided)
title (notifications)required
body (notifications)required

9. Error Cases

CaseBehavior
User blocking SMSfallback to push + email
Failed push (Firebase)retry with exponential backoff
Missing phone numberblock SMS channel
Notification deep link invalidopen fallback home page
Provider tries messaging wrong userdeny action

11. Cross-Module Relations

ModuleInteraction
Bookingsbooking status changes trigger notifications
Paymentspayment success/failure → transactional notifications
Ratingsafter trip completion → rating request and thank-you messages
Tripstrip reminders and updates
RBACcontrols who can send manual messages and to whom
Reportsmay log notification delivery stats (future expansion)

12. Message Catalog (Slice 11)

SSOT: analysis/04-functional-spec/notifications-and-messaging-module.md §13

12.1 Channel Policy

ChannelStatusNotes
In-App[OFFICIAL]Wording finalized; ready for implementation
Email[PROPOSED]Future Planned — backend integration required
SMS[PROPOSED]Future Planned — SMS provider required
WhatsApp[PROPOSED]Future Planned — WhatsApp Business API required

12.2 Wording Guardrails

  • WORD-01: No provider contact info in messages (PRIV-01)
  • WORD-02: No timeline commitments (use 'estimate' + [PROPOSED])
  • WORD-03: No 'wallet/withdraw/topup' terms (Slice 5)
  • WORD-04: Arabic labels must match UI exactly (BR-6)
  • WORD-05: Amounts in SAR (ر.س) only

12.3 Notification Events

EventIn-AppEmail/SMS
Booking Confirmed[OFFICIAL] §13.3[PROPOSED]
Cancelled by User (DEC-S10-02)[OFFICIAL] §13.4[PROPOSED]
Cancelled by Trip Cascade (DEC-S10-03)[OFFICIAL] §13.5[PROPOSED]
Refund to Credit (DEC-S5-01)[OFFICIAL] §13.6[PROPOSED]
Admin Gift/Compensation (DEC-S5-02)[OFFICIAL] §13.7[PROPOSED]

12.4 Forbidden Content

  • ❌ Provider phone/email/WhatsApp (PRIV-01)
  • ❌ Timeline commitments without [PROPOSED]
  • ❌ 'Wallet/محفظة' — Use 'Credit/رصيدي'
  • ❌ 'Withdraw/سحب' or 'Top-up/شحن'

12.5 Glossary — Key Terms (UI Match)

⚠️ All notification text MUST use these exact terms

Englishالعربية❌ Forbidden
My CreditرصيديWallet/محفظة
Refundاستردادإرجاع
Confirmedمؤكدمحجوز
Cancelledملغاهملغي
SARر.سريال/SR
Masarukمسارك

13. Trigger Map (Slice 12)

SSOT: notifications-and-messaging-module.md §14

TriggerMessage IDEntityVariablesFallback
TRG-01MSG-13.3booking_idbooking_ref, trip_name, departure_date§13.3 fallbacks
TRG-02MSG-13.4booking_idbooking_ref, amount, percentage§13.4 fallbacks
TRG-03MSG-13.5booking_idtrip_name, amount§13.5 fallbacks
TRG-04MSG-13.6credit_txn_idamount, booking_ref, balance§13.6 fallbacks
TRG-05MSG-13.7-Acredit_txn_idamount, balance§13.7: amount=critical
TRG-06MSG-13.7-Bcredit_txn_idamount, balance§13.7: amount=critical
TRG-07MSG-13.8booking_idtrip_name[PROPOSED] §13.8
TRG-08MSG-13.9booking_idtrip_name[PROPOSED] §13.9

S12.5 Coverage: 8/8 triggers ✅ Message ID ✅ Entity ✅ Variables ✅ Fallback

⚠️ NC-RULE-01: Only events with valid Message ID are rendered. Unknown events = discard.

14. UI Placements (Slice 12)

SSOT: notifications-and-messaging-module.md §15

My Bookings

/bookings

Types: TRG-01, TRG-02, TRG-03
Style: Status badge + row highlight

Booking Details

/bookings/{id}

Types: TRG-01, TRG-02, TRG-03
Style: Top banner (dismissible)

My Credit

/my-credit

Types: TRG-03, TRG-04, TRG-05, TRG-06
Style: Transaction row highlight

Notification Center

/account/notifications

Types: ALL
Style: List with read/unread state