Keyboard shortcuts

Press ← or β†’ to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Broadcast Template

The broadcast template enables mass messaging to contact lists, perfect for announcements, marketing campaigns, and bulk notifications through WhatsApp and other channels.

Topic: Mass Messaging & Announcements

This template is perfect for:

  • Company-wide announcements
  • Marketing campaigns
  • Customer notifications
  • Event reminders
  • Newsletter distribution

The Code

PARAM message AS STRING LIKE "Hello {name}, how are you?" DESCRIPTION "Message to broadcast, supports {name} and {mobile} variables"
PARAM listfile AS STRING LIKE "broadcast.csv" DESCRIPTION "CSV file with contacts (name, mobile columns)"
PARAM filter AS STRING LIKE "status=active" DESCRIPTION "Filter condition for contact list" OPTIONAL

DESCRIPTION "Send broadcast message to a list of contacts from CSV file"

IF NOT listfile THEN
    listfile = "broadcast.csv"
END IF

IF filter THEN
    list = FIND listfile, filter
ELSE
    list = FIND listfile
END IF

IF UBOUND(list) = 0 THEN
    TALK "No contacts found in " + listfile
    RETURN 0
END IF

index = 1
sent = 0

DO WHILE index < UBOUND(list)
    row = list[index]

    msg = REPLACE(message, "{name}", row.name)
    msg = REPLACE(msg, "{mobile}", row.mobile)

    TALK TO row.mobile, msg
    WAIT 5

    WITH logEntry
        timestamp = NOW()
        user = USERNAME
        from = FROM
        mobile = row.mobile
        name = row.name
        status = "sent"
    END WITH

    SAVE "Log.xlsx", logEntry

    sent = sent + 1
    index = index + 1
LOOP

TALK "Broadcast sent to " + sent + " contacts."

RETURN sent

Sample Dialogs

These conversations show how the broadcast template works in real-world scenarios.

Dialog 1: Simple Broadcast

Dialog 2: Filtered Broadcast

Dialog 3: No Contacts Found

Keywords Used

KeywordPurpose
PARAMDefine input parameters with descriptions
DESCRIPTIONTool description for AI
FINDQuery contacts from CSV file
REPLACESubstitute variables in message template
TALK TOSend message to specific phone number
WAITDelay between messages (rate limiting)
SAVELog each message to spreadsheet
RETURNReturn count of sent messages

How It Works

  1. Load Contacts: FIND retrieves contacts from CSV with optional filter
  2. Validate List: Checks if contacts were found
  3. Loop Through Contacts: Iterates through each contact
  4. Personalize Message: REPLACE substitutes {name} and {mobile}
  5. Send Message: TALK TO delivers to each phone number
  6. Rate Limiting: WAIT 5 pauses 5 seconds between messages
  7. Log Operation: Each send is recorded in Log.xlsx
  8. Report Results: Returns total messages sent

Contact List Format

Your CSV file should have these columns:

name,mobile,status,segment
John Smith,+5511999999999,active,regular
Maria Garcia,+5521888888888,active,vip
Carlos Santos,+5531777777777,inactive,regular
Ana Lima,+5541666666666,active,vip
ColumnRequiredDescription
nameYesContact’s display name
mobileYesPhone in international format
statusNoFor filtering (active/inactive)
segmentNoFor targeting (vip/regular)

Customization Ideas

Add Message Templates

ADD TOOL "broadcast"
ADD TOOL "list-templates"
ADD TOOL "create-template"

' Load saved templates
templates = FIND "message_templates.csv"

TALK "Available templates:"
FOR EACH template IN templates
    TALK "β€’ " + template.name + ": " + LEFT(template.message, 50) + "..."
NEXT

TALK "Which template would you like to use?"
HEAR templateName

selected = FIND "message_templates.csv", "name = '" + templateName + "'"
message = selected.message

Add Scheduling

PARAM schedule_time AS STRING LIKE "2025-01-20 09:00" DESCRIPTION "When to send (optional)"

IF schedule_time THEN
    SET SCHEDULE schedule_time
    
    ' Store broadcast details for later
    SET BOT MEMORY "scheduled_message", message
    SET BOT MEMORY "scheduled_list", listfile
    SET BOT MEMORY "scheduled_filter", filter
    
    TALK "πŸ“… Broadcast scheduled for " + schedule_time
    TALK "I'll send to " + UBOUND(list) + " contacts at that time."
    RETURN 0
END IF

Add Progress Updates

total = UBOUND(list)
checkpoints = [25, 50, 75, 100]

DO WHILE index <= total
    ' ... send message ...
    
    ' Check progress
    percent = INT((index / total) * 100)
    IF INARRAY(percent, checkpoints) THEN
        TALK "πŸ“Š Progress: " + percent + "% (" + index + "/" + total + ")"
    END IF
    
    index = index + 1
LOOP

Add Opt-Out Handling

' Check if contact has opted out
optouts = FIND "optouts.csv"

DO WHILE index <= UBOUND(list)
    row = list[index]
    
    ' Skip opted-out contacts
    IF FIND("optouts.csv", "mobile = '" + row.mobile + "'") THEN
        WITH logEntry
            mobile = row.mobile
            status = "skipped-optout"
        END WITH
        SAVE "Log.xlsx", logEntry
        index = index + 1
        CONTINUE
    END IF
    
    ' ... send message ...
LOOP

Add Media Support

PARAM image AS STRING LIKE "promo.jpg" DESCRIPTION "Image to include (optional)"

IF image THEN
    msg = msg + "\n[Image: " + image + "]"
    TALK TO row.mobile, msg, image
ELSE
    TALK TO row.mobile, msg
END IF

Best Practices

Message Content

  1. Personalize: Always use {name} for a personal touch
  2. Be Concise: Keep messages short and clear
  3. Clear CTA: Include a clear call-to-action
  4. Identify Yourself: Make sure recipients know who’s messaging

Compliance

  1. Consent Required: Only message contacts who opted in
  2. Easy Opt-Out: Include unsubscribe instructions
  3. Respect Hours: Don’t send late at night
  4. Honor Limits: WhatsApp has daily messaging limits

Performance

  1. Rate Limiting: Keep 5+ second delays to avoid blocks
  2. Batch Processing: For large lists, consider batching
  3. Error Handling: Log and handle failed sends
  4. Monitor Results: Check logs for delivery issues

Logging Structure

The Log.xlsx file tracks all broadcast activity:

ColumnDescription
timestampWhen message was sent
userWho initiated the broadcast
fromSender identifier
mobileRecipient phone number
nameRecipient name
statussent/failed/skipped
errorError message if failed