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

# Testing Routes

> Generate and test panchangam messages without sending via WhatsApp

This guide documents the testing routes for generating panchangam messages without sending them via WhatsApp. Use them to:

* Test panchangam accuracy with different coordinates
* Validate message formatting and template parameters
* Debug without touching production webhooks
* Test with coordinates that have no user in the database

**Important:** These routes do **not** send messages via WhatsApp. They only generate and save message data to files.

## Overview

All generated messages are saved to `logs/generated_whatsapp_messages/` as JSON files containing:

* Complete panchangam data
* Template parameters (42 for WhatsApp templates)
* Formatted message text
* User/coordinate and template selection info

## Message generation routes

### 1. Generate message for user

**Endpoint:** `GET /test/whatsapp/generate/<phone_number>`

Generates a panchangam message for an existing user and saves it to a file.

**Requirements:** User must exist with `latitude`, `longitude`, and `timezone` set, and an active subscription.

```bash theme={null}
curl -X GET http://localhost:5050/test/whatsapp/generate/1234567890
```

**Success response** includes `status`, `file_path`, `filename`, `template_name`, `user_info`, and `formatted_message_preview`. **Errors:** "User not found" or "User ... missing location data" with details.

### 2. Generate message from coordinates

**Endpoint:** `POST /test/whatsapp/generate-coords`

Generates a panchangam from coordinates without requiring a user in the database.

**Request body:**

| Field         | Type   | Required | Description                                                 |
| ------------- | ------ | -------- | ----------------------------------------------------------- |
| latitude      | float  | Yes      | -90 to 90                                                   |
| longitude     | float  | Yes      | -180 to 180                                                 |
| timezone      | string | Yes      | IANA timezone (e.g. America/Los\_Angeles)                   |
| date          | string | No       | YYYY-MM-DD (default: current date in timezone)              |
| country\_code | string | No       | "1" for US (dailymessage template), else panchangam\_global |

```bash theme={null}
curl -X POST http://localhost:5050/test/whatsapp/generate-coords \
  -H "Content-Type: application/json" \
  -d '{
    "latitude": 37.3688,
    "longitude": -122.0363,
    "timezone": "America/Los_Angeles",
    "date": "2025-01-16",
    "country_code": "1"
  }'
```

**Success response** includes `status`, `coordinates`, `file_path`, `city_info`, `template_name`, and `formatted_message_preview`. **Errors:** missing fields, invalid coordinates/date/timezone.

## Helper routes

* **GET /test/whatsapp/users** — List active users with phone and location data.
* **GET /test/whatsapp/info** — Info about WhatsApp message types, templates, and test endpoints.
* **GET /test/country-templates** — Test country-based template selection.

## Output files

* **User-based:** `panchangam_{phone_number}_{YYYYMMDD_HHMMSS}.json`
* **Coordinate-based:** `panchangam_coords_{lat}_{lon}_{YYYYMMDD_HHMMSS}.json` (dots/neg replaced for filename safety)

Each file contains `generated_at`, `user_info` or `coordinates`, `city_info`, `template_name`, `template_parameters`, `panchangam_data`, and `formatted_message`.

## Examples

**Mumbai:**

```bash theme={null}
curl -X POST http://localhost:5050/test/whatsapp/generate-coords \
  -H "Content-Type: application/json" \
  -d '{"latitude": 19.0760, "longitude": 72.8777, "timezone": "Asia/Kolkata", "country_code": "91"}'
```

**London:**

```bash theme={null}
curl -X POST http://localhost:5050/test/whatsapp/generate-coords \
  -H "Content-Type: application/json" \
  -d '{"latitude": 51.5074, "longitude": -0.1278, "timezone": "Europe/London"}'
```

**For a user:** List users with `GET /test/whatsapp/users`, then `GET /test/whatsapp/generate/<phone_number>`.

## Template selection

* **US** (country\_code = "1"): `dailymessage` (utility)
* **Others:** `panchangam_global` (marketing)

## Troubleshooting

* **User not found** — Check user exists and phone format.
* **Missing location data** — Use the coordinate-based endpoint instead.
* **Invalid timezone** — Use IANA names (e.g. America/Los\_Angeles, Asia/Kolkata).
* **Invalid date** — Use YYYY-MM-DD.
* **Files not appearing** — Ensure `logs/generated_whatsapp_messages/` exists and check app logs.

## Related

* [WhatsApp Cloud API – Send messages](https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-messages)
* [IANA timezone list](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
