Message Service
Service that processes WhatsApp messages through the AI agent, managing conversations and generating responses
Service
Overview
The Message Service is responsible for processing WhatsApp messages through the AI agent service. It manages conversations, generates AI-powered responses, and coordinates with other services for follow-ups and notifications.
Architecture diagram
Features
- AI-Powered Responses: Uses OpenAI/Gemini to generate contextual responses
- Conversation Management: Tracks conversation state and history
- Multi-Tenant Support: Handles messages for multiple tenants
- Channel Integration: Supports WhatsApp, Instagram, and Facebook Messenger
- Follow-up Scheduling: Automatically schedules follow-up messages when needed
Message Processing Flow
How Message Service Processes Messages
-
Receive Message
Message is received from the WhatsApp Message Queue
-
Validate Payload
Message payload is validated against WhatsAppMessageSchema
-
Load Context
Service loads conversation history, customer data, and tenant configuration
-
Generate Response
AI agent generates contextual response based on conversation history and system prompts
-
Send Response
Response is sent via WhatsApp API
-
Schedule Follow-up
If needed, schedules follow-up message in Follow-Up Queue
Integration
The Message Service integrates with:
- AI Agent Service: For generating responses
- Conversation Repository: For managing conversation state
- Customer Repository: For accessing customer data
- Tenant Repository: For tenant configuration
- Channel Repository: For channel settings
- WhatsApp Client: For sending messages
Event-driven architecture documentation: Impulsell