Bulk Messaging System

An Electron Desktop app for marketing campaign & broadcast management, using either whatsapp, gmail or a SMTP server

Contact extraction utilities

Introduction#

Shared extractors for CSV, Excel, and TXT. They clean phones the same way and skip rows that fail length checks.

Project structure#

The contact extraction functionality is organized within the Python backend module, with supporting components for validation and manual number parsing:

Core components#

The contact extraction system consists of four primary components, each serving a specific purpose in the contact processing pipeline:

Main contact extraction module (extract_contacts.py)#

This module provides the core functionality for extracting contacts from various file formats. It implements intelligent column detection, fallback parsing mechanisms, and clear error handling.

Web API service (app.py)#

The Flask-based web service exposes the contact extraction capabilities through RESTful endpoints, supporting file uploads and real-time processing with proper error handling and response formatting.

Manual number parser (parse_manual_numbers.py)#

This component handles manually entered phone numbers with flexible parsing logic that can accommodate various input formats and separator combinations.

Phone number validator (validate_number.py)#

A specialized utility for validating and cleaning individual phone numbers with standardized formatting rules.

Architecture overview#

Pieces and how they connect:

The architecture implements a fallback mechanism where each file format handler attempts pandas-based parsing first, with manual fallback parsing for edge cases and error recovery.

Detailed component analysis#

CSV file processing#

The CSV extraction function implements careful automatic column detection and fallback parsing mechanisms:

Column detection algorithm#

Fallback parsing mechanism#

When pandas parsing fails, the system automatically falls back to manual CSV parsing:

TXT file parsing logic#

The TXT file parser implements regex-based phone number detection with flexible separator handling:

Phone number detection algorithm#

Separator handling#

The TXT parser supports multiple separator types:

  • Comma (,) for comma-separated values
  • Semicolon (;) for semicolon-separated values
  • Tab (\t) for tab-separated values
  • Pipe (|) for pipe-separated values

Excel file processing#

The Excel processing functionality supports both modern .xlsx and legacy .xls formats through pandas integration:

Column mapping strategy#

Phone number cleaning and validation#

The phone number cleaning function implements detailed validation with international format support:

Cleaning algorithm#

Manual number parsing#

The manual number parsing utility handles various input formats with flexible separator detection:

Parsing strategy#

Dependency analysis#

The contact extraction utilities have a well-defined dependency structure with clear external library requirements:

Performance considerations#

Performance notes:

Memory management#

  • Streaming file processing for large CSV files
  • Lazy evaluation of pandas DataFrames
  • Proper resource cleanup and file handle management

Processing efficiency#

  • Early termination for empty files
  • Optimized regex patterns for phone number detection
  • Minimal memory allocation during processing

Error recovery#

  • Falls back from pandas to manual parsing
  • Detailed exception handling with logging
  • Resource cleanup on failure

Limits#

  • Configurable file size limits (16MB default)
  • Efficient column detection algorithms
  • Optimized phone number validation

Troubleshooting guide#

Common issues and solutions#

File format compatibility#

  • Issue. Excel files not opening
  • Solution. Ensure openpyxl and xlrd are installed for .xlsx and .xls respectively
  • Reference. requirements.txt

Phone number validation failures#

  • Issue. Valid phone numbers rejected
  • Solution. Check number length (7-15 digits) and international format requirements
  • Reference. validate_number.py

Memory issues with large files#

  • Issue. Out of memory errors
  • Solution. Process files in smaller chunks or use streaming approaches
  • Reference. app.py

Encoding problems#

  • Issue. Special characters not displaying correctly
  • Solution. Ensure UTF-8 encoding for text files
  • Reference. extract_contacts.py

Error handling strategies#

The system implements clear error handling across all components:

Conclusion#

Format-specific extractors should all exit through the same cleaner. That is what keeps WhatsApp JIDs consistent later.