AI & Data · NLP

WhatsApp Message Urgency Classification

A FastText-based NLP system that classifies incoming WhatsApp messages by urgency level, streams dashboard updates in real time, and maps phone numbers to WhatsApp identities for reliable ticket handling.

FastText Python Flask Baileys Node.js SSE PWA NLP
WhatsApp Urgency Classification
Role
ML + Full-stack Dev
Client
Pharmacy (SMB)
Model
FastText (fine-tuned)
Status
Completed

Background

A small pharmacy was drowning in WhatsApp messages — prescription refill requests, appointment inquiries, promotional spam, and casual chats all flooding the same inbox with no way to prioritize. Staff were manually scrolling through hundreds of messages a day, often missing time-sensitive requests from patients.

Pain Points
  • Inbox flooded with spam and low-priority chats
  • Urgent patient messages getting buried
  • No system to surface what needs immediate attention
Goals
  • Auto-classify messages into urgency levels
  • Surface urgent chats on a priority dashboard
  • Alert staff with repeat notifications until handled

ML Pipeline

FastText was chosen as the model backbone — it's lightweight, fast at inference, and reliable enough for small business use cases without needing heavy infrastructure. Since FastText is pre-trained, the pipeline focused on collecting domain-specific training data and fine-tuning it to the pharmacy context.

1
Data Collection

Gathered real-world WhatsApp message samples representative of the pharmacy context — covering prescription requests, appointment questions, complaints, spam, and casual messages.

2
Data Cleaning

Removed noise such as emoji-only messages, media placeholders, and duplicate entries. Text was normalized for consistent tokenization.

3
Labelling

Each message was labelled into one of three classes: Urgent (requires immediate staff response), Normal (standard inquiry, can be queued), or Non-Urgent (spam, promotional, or irrelevant).

4
Fine-tuning

The pre-trained FastText model was fine-tuned on the labelled dataset. Because FastText is already pre-trained on large corpora, fine-tuning required minimal data and compute while still achieving reliable domain accuracy.

Why FastText?
Lightweight — runs on minimal server resources, ideal for small business hosting
Fast inference — classifies messages in milliseconds, no GPU required
Pre-trained — fine-tuning needs far less labelled data than training from scratch

How It Works

The deployed system connects to the pharmacy's WhatsApp through a Fonnte webhook and a Baileys Node.js listener. Every incoming message is normalized, mapped from phone number to WhatsApp identity, classified in real time, and streamed to the staff dashboard through Server-Sent Events (SSE).

Input
WhatsApp Chat
Webhook
Fonnte / Baileys
Mapping
Phone → WA ID
Model
FastText (Flask)
Output
Urgency Label
Action
SSE / Notif

Urgency Classes

Urgent

Requires immediate staff response. Surfaces on the priority dashboard and triggers a repeat notification every 10 minutes until handled.

Normal

Standard inquiries that can be queued and addressed in order without time pressure.

Non-Urgent

Spam, promotional content, or casual messages with no actionable follow-up needed.

Dashboard & Notification System

Priority Dashboard

Urgent messages are surfaced front and center with sender info and message content. The dashboard updates through SSE so staff can see new urgent tickets without manually refreshing.

Repeat Notifications

If urgent messages remain unresolved, the system re-alerts staff every 10 minutes — ensuring nothing critical gets missed during busy periods.

Quick Reply Shortcut

Each urgent message card uses stored phone-to-WhatsApp mapping data to open the correct conversation directly, so staff can respond without searching manually.

Web & PWA

Works as a standard web app on desktop. On mobile, it's installable as a PWA — giving staff a native-like experience with push notifications on their phones.

Results

Urgency Classes
3
Urgent, Normal, Non-Urgent
Notification Interval
10 min
Repeat alert until resolved
Realtime Updates
SSE
Live dashboard refresh