Follow-Up Request

Event representing a request to send a follow-up message for a conversation

Event Channel:AWS SQS

Overview

The Follow-Up Request event represents a request to send an automated follow-up message for a conversation. This event is published to the Follow-Up Queue and consumed by the Follow-Up Processor.

Payload

The payload follows the FollowUpPayload schema:

Follow-Up Payload
{
"id": "string" // Conversation ID
}

Schema Definition

FollowUpPayloadSchema (Zod)
const FollowUpPayloadSchema = z.object({
id: z.string() // Conversation ID
});

Producing the Event

Follow-up requests are published to the Follow-Up Queue by:

  1. Scheduled Lambda Functions: Cron jobs that check for conversations needing follow-ups
  2. Message Service: When a conversation meets follow-up criteria
  3. Follow-Up Service: When manually scheduling follow-ups
Publishing Follow-Up Request
import { SQSClient } from './clients/sqs-client';
const sqsClient = new SQSClient();
await sqsClient.sendMessage({
id: "conversation-123"
}, 'follow_up');

Consuming the Event

The event is consumed by the followUpProcessor Lambda function:

Processing Follow-Up Request
export const handler = async (event: SQSEvent): Promise<SQSBatchResponse> => {
return sqsBatchProcessor<FollowUpPayload>({
schema: FollowUpPayloadSchema,
processPayload: processFollowUp,
shouldRetry: (error) => {
if (error instanceof FollowUpError) {
return error.shouldRetry;
}
return true;
},
})(event);
};

Processing Flow

  1. Conversation ID is extracted from payload
  2. Conversation is loaded and validated
  3. Business rules are checked (status, tenant config, appointments, etc.)
  4. Customer and conversation history are loaded
  5. AI chatbot generates follow-up message
  6. Follow-up message is sent via WhatsApp

Business Rules

Follow-up messages are only sent when:

  • Conversation status is “open”
  • Tenant has APPOINTMENTS module enabled
  • Tenant has follow-up feature enabled
  • Customer has no existing appointments
  • Channel is active or sender is in test senders list
Event-driven architecture documentation: Impulsell