# Consumer Roughwork Analysis

This document identifies RabbitMQ consumers in the system, their status, functionality, and module dependencies.

---

## 🟢 ACTIVE CONSUMERS

### 1. `consumer.py`
- **Path**: `/home/aiteam/pcaa-dev/dashboard-backend/RabbitMQTest/consumer.py`
- **RabbitMQ Queue**: `test_queue`
- **Functionality**: A basic test consumer used to verify RabbitMQ connectivity and message delivery.
- **Modules Called**:
    - **`pika`**: Standard Python library for RabbitMQ (AMQP) communication. Handles connection, channel, and consumption.

---

## ⚪ INACTIVE CONSUMERS

### 1. `call_processor_worker.py`
- **Path**: `/home/aiteam/pcaa-dev/dashboard-backend/call_processor_worker.py`
- **RabbitMQ Queue**: `call_processing_queue`
- **Functionality**: Primary worker for automatic call processing. It listens for call metadata, retrieves transcripts, runs AI-based quality analysis, and saves results to the database.
- **Modules Called**:
    - **`config.py`**: Manages system-wide configurations and environment variables.
    - **`db_handler.py`**: Provides a high-level interface for database operations (saving analytics, fetching transcripts).
    - **`analyze_calls_with_parameters.py`**: The core AI analysis engine. It construct prompts for AWS Bedrock (Nova model) and processes the results.
    - **`quality_parameters_handler.py`**: Manages business-specific quality criteria (parameters) used during AI analysis.

### 2. `audio_job_consumer.py`
- **Path**: `/home/aiteam/pcaa-dev/post call analysis/audio_job_consumer.py`
- **RabbitMQ Queue**: `audio_jobs`
- **Functionality**: A post-call analysis worker that processes audio jobs by coordinating between Sarvam AI (for transcription) and Azure storage.
- **Modules Called**:
    - **`db_config.py`**: Handles database connection configurations.
    - **`sarvam_processor.py`**: The main logic module for this consumer. It manages audio downloading, Sarvam AI job lifecycle (init/start/poll), and Azure uploads.
    - **`dotenv`**: Utility to load sensitive credentials from `.env` files.

---

## 🛠️ CALLED MODULES FUNCTIONALITY

| Module | Purpose | Key Responsibilities |
| :--- | :--- | :--- |
| **`sarvam_processor.py`** | Transcription Pipeline | Audio download, Sarvam AI STT/Translation integration, Azure Blob storage uploads. |
| **`analyze_calls_with_parameters.py`** | AI Analytics Engine | Prompt engineering for AWS Nova, Talk/Listen ratio calculation, BANT extraction, Sentiment analysis. |
| **`db_handler.py`** | Data Persistence Layer | Complex queries for call history, analytics storage, and business-level data management. |
| **`quality_parameters_handler.py`** | Quality Config Manager | CRUD operations for the `quality_parameters` table, defined per Business ID (BID). |
| **`config.py` / `db_config.py`** | Infrastructure | Connection pooling, credential management, and environment setup. |

---

---

## 🔄 POLLING-BASED SERVICES

These services operate by periodically checking (polling) the database or specific directories for new work, rather than listening to a message queue.

### 1. MCube RAG Ingestion Worker
- **Service Name**: `mcube-rag-ingestion-worker.service`
- **Full Script Path**: `/home/aiteam/pcaa-dev/dashboard-backend/rag_ingestion_worker.py`
- **Execution Command**: `/home/aiteam/pcaa-dev/dashboard-backend/venv/bin/python /home/aiteam/pcaa-dev/dashboard-backend/rag_ingestion_worker.py --interval-seconds 300 --limit-per-bid 4000`
- **Functionality**: Periodically scans `*_sarvamresponse` tables for new transcripts and ingests them into the RAG (Retrieval-Augmented Generation) system for knowledge-based querying.

### 2. Post Call Analysis (Nova Customer Worker)
- **Service Name**: `postcall-analysis.service`
- **Full Script Path**: `/home/snn_extraction/nova_customer_worker.py`
- **Execution Command**: `/home/snn_extraction/venv/bin/python3 /home/snn_extraction/nova_customer_worker.py`
- **Functionality**: A polling worker that fetches pending calls from `2000_call_history` and uses AWS Nova to extract real-estate specific fields (budget, RSVP, intent) into the `2000_call_extractions` table.

### 3. Voicebot Campaign Runner
- **Service Name**: `voicebot-campaign.service`
- **Full Script Path**: `/var/www/html/voicebot-api-live/run-campaign.php`
- **Execution Command**: `/usr/bin/php /var/www/html/voicebot-api-live/run-campaign.php`
- **Functionality**: A PHP-based background process that periodically checks for scheduled or active voicebot campaigns and initiates the calling process.

### 4. Laravel Queue Listeners (Polling-based Workers)
These services use Laravel's `queue:listen` mechanism, which effectively polls the database (or other drivers) for pending jobs.
- **Service Names**: 
    - `voicebot-firstCampaigncall.service`
    - `voicebot-retryCalls.service`
- **Working Directory**: `/var/www/html/voicebot-api-live`
- **Execution Command**: `php artisan queue:listen --queue=[queue_name] --sleep=3`
- **Functionality**: 
    - **`firstCampaigncall`**: Handles the initial execution of voicebot campaign calls.
    - **`retryCalls`**: Manages the logic for retrying failed or unanswered campaign calls.

### 5. Transcription Pipeline Worker (Codebase Only)
- **Full Script Path**: `/home/aiteam/pcaa-dev/call-proccessing/stt_pipeline/workers/transcription_worker.py`
- **Status**: Found in codebase; potentially used as a standalone worker or part of another pipeline.
- **Functionality**: Polls `*_raw_calls` tables to discover new audio files and processes them through the STT (Speech-to-Text) factory (Sarvam, Deepgram, etc.).

---

## 🛠️ CALLED MODULES FUNCTIONALITY
