WhatsApp Message
Event representing a WhatsApp message to be processed by the AI agent
Event Channel:AWS SQS
Overview
The WhatsApp Message event represents a message that needs to be processed by the AI agent service. This event is published to the WhatsApp Message Queue and consumed by the Message Service.
Payload
The payload follows the WhatsAppMessagePayload schema:
{ "conversationId": "string", "messageId": "string", "sender": "string", "content": "string", "timestamp": "ISO 8601 date-time", "tenantId": "string", "channelId": "string"}Schema Definition
const WhatsAppMessageSchema = z.object({ conversationId: z.string(), messageId: z.string(), sender: z.string(), content: z.string(), timestamp: z.string().datetime(), tenantId: z.string(), channelId: z.string()});Producing the Event
Messages are typically published to the WhatsApp Message Queue by:
- Webhook Processor: When processing incoming WhatsApp webhooks
- Other Services: When they need to trigger message processing
import { SQSClient } from './clients/sqs-client';
const sqsClient = new SQSClient();
await sqsClient.sendMessage({ conversationId: "conv-123", messageId: "msg-456", sender: "+5511999999999", content: "Hello, I'd like to schedule an appointment", timestamp: new Date().toISOString(), tenantId: "tenant-789", channelId: "channel-abc"}, 'whatsapp_message');Consuming the Event
The event is consumed by the whatsappMessageProcessor Lambda function:
export const handler = async (event: SQSEvent): Promise<SQSBatchResponse> => { return sqsBatchProcessor<WhatsAppMessagePayload>({ schema: WhatsAppMessageSchema, processPayload: async (payload, appContext) => { const messageService = appContext.get(MessageService); await messageService.processWhatsAppMessage(payload); }, })(event);};Processing Flow
- Message is received from SQS queue
- Payload is validated against schema
- Message Service loads conversation context
- AI agent generates response
- Response is sent via WhatsApp API
- Follow-up may be scheduled if needed
Event-driven architecture documentation: Impulsell