# Send a post-call text

## Prompt

```text
After the call, thank the customer by text if they agreed to SMS. If I asked for a booking confirmation, check what they said and verify the booking in our calendar before texting.
```

Add the downloaded function as the `call.ended` branch of the Agent Worker that places the call. Set `on_call_ended: true` on that worker and put the contact’s phone number and actual SMS opt-in record in the original event. The callback includes both the call ID and the original event.

Set `max_text_cost_usd` to the total the owner approves for texts per run, using a credential with `messages:write`. Budget each segment at the outbound managed estimate from `get_pricing`, or at the $0.01 base fee for a BYOC number. Run `test_worker` to preview the exact message. Once active, the Agent Worker sends from an SMS-ready workspace number and returns a message ID. Follow `message.updated` to confirm delivery and read the final wallet charge with `list_texts`.

The worker’s final wallet charges for texts stay within the approved per-run budget, even if the carrier bill exceeds the estimate.

For a booking confirmation, set `confirm_booking: true` in the original event. Your agent reads the consented transcript with `get_call_transcript` and checks the booking in your calendar. Once verified, your app can send a `booking.confirmed` event to the Agent Worker’s authenticated webhook with `data.call_id`, `booking_reference` and the original contact. Your app supplies that event. An available time alone is insufficient to send a confirmation.

[Download the Agent Worker function](/recipes/workers/after-call-text.mjs). Test with a confirmed booking and again with a missing booking reference.
