> ## Documentation Index
> Fetch the complete documentation index at: https://docs.spn.wtf/llms.txt
> Use this file to discover all available pages before exploring further.

# Operations

> Daily runbook for starting, monitoring, testing, and operating the application.

## Local Run Commands

Database initialization:

```powershell theme={null}
python db.py
```

OpenAI Realtime agent:

```powershell theme={null}
python agent_realtime.py start
```

Sarvam agent:

```powershell theme={null}
python agent.py start
```

Scheduler:

```powershell theme={null}
python scheduler.py
```

Lead fetcher:

```powershell theme={null}
python lead_fetcher.py
```

Dashboard:

```powershell theme={null}
streamlit run streamlit_app.py
```

## Docker Compose

```powershell theme={null}
docker compose up --build
```

Dashboard:

```text theme={null}
http://127.0.0.1:8502
```

## Adding A Lead Manually

```sql theme={null}
INSERT INTO leads (name, phone, source, product_name, city, state)
VALUES ('Rahul Sharma', '<10-digit-mobile>', 'manual', 'carbon cleaning', 'Kolkata', 'West Bengal');
```

## Checking Queue State

Ready leads:

```sql theme={null}
SELECT id, name, phone, source, retry_after, retry_count
FROM leads
WHERE status='new'
ORDER BY created_at ASC;
```

Active calls:

```sql theme={null}
SELECT id, lead_id, phone, call_room, created_at
FROM calls
WHERE status='calling';
```

Qualified but not pushed:

```sql theme={null}
SELECT id, lead_id, phone, qualification
FROM calls
WHERE status='called'
ORDER BY created_at ASC;
```

## Manual Call Test

```powershell theme={null}
python sip_setup.py call +91XXXXXXXXXX
```

For a specific lead:

```powershell theme={null}
python sip_setup.py call +91XXXXXXXXXX 123
```

## Monitoring Logs

Watch for:

* Scheduler started with the expected timezone and calling window
* Lead selected and phone normalized
* SIP participant creation success
* Agent joins the correct `ignitech-lead-{id}` room
* Qualification extraction and DB save
* Talking Shops push success or failure
* Stale calls being cleaned
* Retry scheduling

## Common Status Interpretation

| Where   | Status       | Meaning                             |
| ------- | ------------ | ----------------------------------- |
| `leads` | `new`        | Waiting for scheduler or retry time |
| `leads` | `dispatched` | At least one call attempt started   |
| `leads` | `failed`     | Invalid or retry limit reached      |
| `calls` | `calling`    | Current or stuck attempt            |
| `calls` | `called`     | Qualified, ready for CRM push       |
| `calls` | `pushed`     | CRM handoff complete                |
| `calls` | `failed`     | Attempt failed                      |

## Dashboard Usage

The main Streamlit app shows:

* Total leads
* Awaiting calls
* Dispatched leads
* Qualified calls
* Pushed calls
* Failed numbers
* Max retries reached
* CSV import
* Lead and call tables
* Qualification JSON viewer

The `/minutes` page shows successful call minutes and supports optional password protection:

```env theme={null}
MINUTES_DASHBOARD_PASSWORD=your_password
```
