# v0.1.7 Final Lead Capture + Caller ID Fix

## What changed

v0.1.7 changes lead saving so the AI can collect and correct details during the call, then save the final corrected lead at the end of the call.

### Fixes

- Added a final lead capture mode using `lead_final=true` and `lead_capture_stage=final`.
- Draft or early tool calls are saved as `AI Collecting Info` and do not trigger push notifications by default.
- The dashboard alert/push is sent when the final lead payload is saved.
- AI/tool updates no longer erase existing lead fields with blank/null values.
- Added better caller ID fallback from the Telnyx inbound TeXML request.
- Added a Telnyx dynamic variables webhook endpoint:

```text
https://pestdemo.recovermissedcall.com/telnyx/dynamic-variables
```

- Added `call_control_id`, `telnyx_end_user_target`, `lead_final`, and `lead_capture_stage` to the Telnyx tool schema.

## Telnyx Assistant tool changes

For both tools, add these body parameters:

| Parameter | Type | Required | Notes |
|---|---|---:|---|
| `customer_phone` | string | Yes | Default to `{{telnyx_end_user_target}}` unless the caller gives a different number. |
| `telnyx_end_user_target` | string | No | Set to `{{telnyx_end_user_target}}` if Telnyx allows dynamic value assignment. |
| `call_control_id` | string | No | Set to `{{call_control_id}}` if available. |
| `lead_final` | boolean | Yes | `true` only for final/post-call save. |
| `lead_capture_stage` | string | Yes | Use `final` or `post_conversation`. |

## Recommended Telnyx setup

Best setting: enable Telnyx post-conversation tool execution if your assistant has that option, then call `submit_lead` after the call ends.

If post-conversation tool execution is not available, update the assistant prompt and tool descriptions so the assistant calls `submit_lead` only after it has read back the final summary and the caller confirms.

## Dynamic variables webhook

If your Telnyx assistant has a field for Dynamic Variables Webhook URL, set it to:

```text
https://pestdemo.recovermissedcall.com/telnyx/dynamic-variables
```

The endpoint returns:

```json
{
  "dynamic_variables": {
    "customer_phone": "caller number if available",
    "caller_phone": "caller number if available",
    "telnyx_end_user_target": "caller number if available",
    "call_control_id": "call control id if available",
    "telnyx_conversation_id": "conversation id if available"
  }
}
```

## Optional setting

By default, drafts do not trigger push notifications:

```env
NOTIFY_DRAFT_LEADS=false
```

Set this to true only if you want alerts before the call is finalized:

```env
NOTIFY_DRAFT_LEADS=true
```
