DEV Community

Ujjwal Dubey
Ujjwal Dubey

Posted on

A Daily Gold-Rate Broadcast With an Approve Step: Opt-In Lists, Frequency Preferences and a Dry Run in Python

Gold-rate messages are one of the first things Indian jewellers ask to automate. The code is easy; the safety rules are the work. This is a sketch I would hand to anyone building AI automation for jewellery retail India teams can switch off with one reply.

customers.csv

customer_id,phone_e164,opt_in,frequency,last_sent
C001,+91XXXXXXXXXX,yes,daily,2026-11-09
C002,+91XXXXXXXXXX,yes,festival,2026-10-20
C003,+91XXXXXXXXXX,no,,
Enter fullscreen mode Exit fullscreen mode

Script

import csv, datetime, sys

TODAY = datetime.date.today()
FESTIVAL_DAYS = set()  # filled by staff, e.g. {"2026-11-10"}

def due(row):
    if row["opt_in"] != "yes":
        return False
    if row["frequency"] == "daily":
        return row["last_sent"] != TODAY.isoformat()
    if row["frequency"] == "festival":
        return TODAY.isoformat() in FESTIVAL_DAYS
    return False

def send(phone, text):  # stub: call your WhatsApp provider here
    print("SEND", phone, text)

def main(rate_text, approved_by, dry_run=True):
    if not rate_text.strip():
        sys.exit("No rate entered today: nothing sent.")
    rows = list(csv.DictReader(open("customers.csv", encoding="utf-8")))
    queue = [r for r in rows if due(r)]
    print(f"{len(queue)} customers due; approved by: {approved_by or 'NOBODY'}")
    if dry_run or not approved_by:
        for r in queue[:5]:
            print("PREVIEW", r["customer_id"], rate_text)
        return
    msg = rate_text + "\nReply STOP to stop these updates."
    for r in queue:
        send(r["phone_e164"], msg)

if __name__ == "__main__":
    main(rate_text=sys.argv[1] if len(sys.argv) > 1 else "", approved_by=None)
Enter fullscreen mode Exit fullscreen mode

Rules baked in

  1. No rate, no send. The rate is typed by staff; the script never invents one.
  2. Dry run by default. It previews until a named person approves.
  3. Opt-in only, with frequency. "festival" customers only get messages on days staff mark.
  4. Every message has a stop line. Handle "STOP" replies by setting opt_in to no straight away.
  5. Template rules. Business-initiated WhatsApp messages need approved templates; check with your provider.

Before automating any customer message, we map the whole flow first. The Site Roaster read of a jeweller's homepage is a free way to see how the showroom site looks to a first-time buyer while you plan.

Disclosure: I co-founded NxFlowAI, a Mumbai-based AI automation agency.

Top comments (0)