Overview
The messaging system is built around two core concepts:Chat Threads
Conversation containers linking tourists and guides
Chat Messages
Individual messages within a conversation
Chat Threads
Chat threads organize conversations between tourists and guides, typically linked to a specific trip booking.Data Model
Thread Status
ACTIVE
Thread is open for messaging
ARCHIVED
Thread is archived but messages preserved
BLOCKED
Thread is blocked, no further messages allowed
Key Features
- Trip Association: Each thread is typically linked to a
TripBookingviatrip_id - Participant Tracking: Explicit
tourist_idandguide_idfields - Last Activity:
last_message_attimestamp for sorting and notifications - Status Management: Control thread lifecycle with status enum
Threads are automatically created when a tourist books a tour or initiates conversation with a guide.
Chat Messages
Messages are the actual content sent within a chat thread.Data Model
Message Types
TEXT Messages
TEXT Messages
Standard messages sent by tourists or guides. The
body field contains the message text.Example:SYSTEM Messages
SYSTEM Messages
Automatically generated messages for events like booking confirmations, status changes, or reminders.Example:
FILE Messages
FILE Messages
Messages containing file attachments. The
body field typically contains a file URL or reference.Example:Message Features
Read Receipts
Theread_at timestamp tracks when messages are read:
null= Message is unreadLocalDateTimevalue = When the message was read
Sender Identification
Thesender_user_id field identifies who sent each message:
- Compare with
thread.touristIdto check if tourist sent it - Compare with
thread.guideIdto check if guide sent it - System messages typically have a null or special sender ID
API Endpoints
Chat Threads
?touristId={id}- Get threads for a tourist?guideId={id}- Get threads for a guide?tripId={id}- Get thread for a specific trip?status={status}- Filter by thread status
Chat Messages
?threadId={id}- Get all messages in a thread?senderUserId={id}- Get messages sent by a user?messageType={type}- Filter by message type
Usage Examples
Creating a Thread
Sending a Message
Marking Message as Read
Getting Unread Messages
Client-side filter for messages wherereadAt is null and senderUserId is not the current user.
Integration with Notifications
The messaging system integrates with the notifications module:New Message Alert
Recipient receives notification when new message arrives
Read Receipt
Sender can see when message is read
Best Practices
Thread Management
Message Handling
Real-Time Messaging
While the REST API provides basic CRUD operations, real-time messaging typically requires:- WebSocket Connection: For instant message delivery
- Presence Indicators: Show when users are online
- Typing Indicators: Show when someone is typing
These real-time features would be implemented in addition to the base REST API, typically using WebSocket protocols or server-sent events.
Common Use Cases
Pre-Booking Questions
Pre-Booking Questions
Tourists can message guides before booking to ask questions about tours, meeting points, what to bring, etc.Implementation: Create thread without
tripId, allow messaging before booking is confirmed.Trip Coordination
Trip Coordination
After booking, tourists and guides coordinate details like exact meeting location, time adjustments, special requests.Implementation: Thread with
tripId set, status ACTIVE, messages from both parties.Post-Trip Follow-up
Post-Trip Follow-up
Guides can thank tourists, tourists can ask follow-up questions, share photos.Implementation: Keep thread
ACTIVE for a period after trip completion, then archive.System Notifications
System Notifications
Automated messages for booking confirmations, reminders, cancellations.Implementation: Create messages with
messageType: SYSTEM and appropriate body text.Related Features
Bookings
See how threads are linked to trip bookings
Notifications
Learn about the notification system