Skip to main content

Overview

Campaign Management enables users to create scheduled WhatsApp message campaigns for groups or individuals. Each campaign consists of multiple scheduled messages with automatic progress tracking and delivery monitoring.

Campaign Lifecycle

1

Create Campaign

Define campaign parameters including target audience, date range, message template, and scheduling options.
2

Schedule Messages

Messages are automatically generated based on the date range and recurrence pattern.
3

Track Progress

Monitor campaign status, message delivery, and completion percentage in real-time.
4

Complete or Update

Campaigns can be updated (before messages are sent) or marked complete when all messages are delivered.

Campaign Status

Campaigns progress through different states:
prisma/schema.prisma:19

Creating a Campaign

API Endpoint

src/server/api/routers/messageCampaign.ts:9

Input Parameters

groupId
string
required
WhatsApp group ID or contact ID for the campaign target
groupName
string
required
Display name for the group or contact
sessionId
string
required
WhatsApp session ID to use for sending messages
title
string
Optional campaign title (displayed in messages unless isFreeForm is true)
targetAmount
string
Optional contribution target amount for fundraising campaigns
startDate
string
required
ISO 8601 date string for campaign start (e.g., “2026-03-10”)
endDate
string
required
ISO 8601 date string for campaign end (must be after startDate)
messageTime
string
required
Time to send messages daily in HH:MM format (e.g., “09:30”)
timeZone
string
default:"America/Chicago"
IANA timezone identifier for scheduling (e.g., “America/New_York”)
messageTemplate
string
required
Message content. Use asterisks (*) to separate messages for recurring campaigns
isFreeForm
boolean
default:false
If true, only sends the message template without campaign metadata
isRecurring
boolean
required
Whether to send messages on a recurring schedule
recurrence
enum
default:"DAILY"
Recurrence pattern: DAILY, WEEKLY, SEMI_MONTHLY, MONTHLY, SEMI_ANNUALLY, ANNUALLY
audienceType
enum
default:"groups"
Target audience type: ‘groups’ or ‘individuals’

Message Template Variables

Templates support dynamic variables:
  • {days_left} - Replaced with remaining days in campaign

Multiple Message Sequences

For recurring campaigns, separate messages with asterisks to create unique content for each occurrence:
The number of messages must match the calculated occurrences. For example, a 4-day DAILY campaign requires exactly 4 messages separated by asterisks, or one message without asterisks to repeat.

Recurrence Patterns

Recurrence intervals are mapped to day counts:
src/server/api/routers/messageCampaign.ts:31
Messages sent every day at the specified time

Viewing Campaigns

Active Campaigns

Get campaigns with upcoming scheduled messages:
src/server/api/routers/messageCampaign.ts:251

Completed Campaigns

Get campaigns where all messages have been sent or scheduled time has passed:
src/server/api/routers/messageCampaign.ts:185

Updating Campaigns

Campaigns can only be updated if no messages have been sent yet. Once messages start sending, the campaign becomes read-only.
src/server/api/routers/messageCampaign.ts:403
The update process:
1

Validate Access

Verify the campaign belongs to the current user and exists
2

Check Message Status

Ensure no messages have been sent yet
3

Mark Old Messages as Deleted

Soft delete all unsent messages from the original campaign
4

Regenerate Messages

Create new messages based on updated parameters

Deleting Campaigns

Campaigns are soft-deleted to preserve historical data:
src/server/api/routers/messageCampaign.ts:319

Campaign Data Model

prisma/schema.prisma:77

Progress Tracking

Track campaign progress through message status:

Total Messages

Count of all non-deleted messages in the campaign

Sent Messages

Messages where isSent = true

Failed Messages

Messages where isFailed = true
Calculate completion percentage:

Best Practices

  • Always specify the timezone for accurate scheduling
  • Messages are stored in UTC but scheduled in the specified timezone
  • Use IANA timezone identifiers (e.g., “America/New_York”)
  • Keep messages concise for better engagement
  • Use the variable for urgency
  • Test templates before creating large campaigns
  • Verify date ranges before creating campaigns
  • For recurring campaigns with sequences, calculate required message count
  • Use free-form mode for simple announcements

Next Steps

Message Scheduling

Learn about timezone handling and recurrence patterns

Admin Dashboard

Monitor all campaigns across users