# v0.2.2 State + Urgency Classification Fix

## Problem fixed

Two issues were showing up on lead detail pages:

1. The caller gave city/state in the summary, but the dedicated State field stayed blank.
2. Some non-urgent leads showed `urgent` because the AI used `escalate_urgent` or sent `urgency=urgent` while the preferred appointment time was `this week`.

## What changed

- Added backend fallback extraction for `service_state` from:
  - `service_state`
  - `state`
  - `service_address`
  - `city`
  - `ai_summary`
  - `transcript`
  - raw tool payload
- Added defensive urgency normalization:
  - `this week`, `later this week`, `next week`, `not an emergency`, `no rush` downgrade non-same-day leads
  - `today`, `same day`, `right now`, `emergency` remain urgent/high-priority
- Stopped the `escalate_urgent` route from forcibly overriding every lead to `urgency=urgent` and `status=urgent_callback`.
- Updated the dashboard urgency dropdown to use owner-friendly values:
  - Emergency
  - Same day
  - This week
  - Normal
  - Estimate only
  - Unknown
- Updated the Telnyx tool schema urgency enum to match the new values.
- Updated the assistant prompt to make city/state and urgency rules clearer.

## Telnyx tool settings

For both `submit_lead` and `escalate_urgent`, keep only these required:

```text
service_needed
ai_summary
```

Keep these optional:

```text
customer_name
customer_phone
telnyx_end_user_target
call_control_id
service_address
city
service_state
urgency
property_type
preferred_time
caller_intent
questions_asked
answers_given
missing_information
recommended_action
transcript
lead_final
lead_capture_stage
```

## Telnyx urgency values

Use these exact urgency values in Body Parameters if Telnyx lets you define enums:

```text
Emergency
Same day
This week
Normal
Estimate only
Unknown
```

Do not use old values like:

```text
urgent
soon
normal
estimate_only
```

The app still accepts those old values, but it normalizes them for the dashboard.

## Important note

Existing leads that were already saved before this patch may still have old data. You can manually change the State and Urgency fields on the lead detail page and click Save Lead Changes.

Future leads should classify correctly after uploading v0.2.2 and updating the Telnyx assistant prompt/tool schema.
