Voice AI

Build an AI Prescription Refill Intake Voice Assistant with Telnyx

Prescription refill calls are a practical healthcare voice AI use case because the workflow is repetitive, time-sensitive, and structured. A caller usually needs to provide a medication name, pharmacy, contact information, and enough context for staff to review the request.

The important boundary is that the AI should not approve prescriptions, deny prescriptions, change dosage instructions, diagnose symptoms, or replace clinical judgment. It should collect the minimum information needed and route the request to the right human team.

The Telnyx code example is here:

https://github.com/team-telnyx/telnyx-code-examples/tree/main/ai-prescription-refill-intake-voice-assistant-python

It is a Python + Flask example that shows how to use Telnyx AI Assistants, Call Control, and assistant webhook tools to build a refill intake line.

What This Example Builds

The example starts with an inbound call to a Telnyx number. Telnyx sends a call.initiated webhook to the Flask app. The app answers the call and starts a configured Telnyx AI Assistant with ai_assistant_start.

From there, the assistant handles the live conversation. It asks one question at a time and calls backend tools when it has enough context:

  • create_refill_request
  • flag_manual_review
  • queue_callback

The backend stores structured refill requests, masks caller identifiers, and keeps the staff-review workflow explicit.

Architecture

caller dials Telnyx number
  -> Telnyx sends call.initiated
  -> Flask app answers the call
  -> backend starts Telnyx AI Assistant
  -> assistant asks refill intake questions
  -> assistant calls create_refill_request
  -> assistant flags manual review when needed
  -> assistant queues callback when requested
  -> staff reviews the backend request record

This is different from writing the full voice state machine yourself. The backend does not need to manage every prompt and speech-gather loop. Telnyx AI Assistants handle the conversational layer, while your app handles workflow actions.

Why Use AI Assistant Tools

The useful part of this pattern is the separation of responsibilities.

The assistant is responsible for the caller experience:

  • explain the refill line
  • give an emergency reminder
  • ask one question at a time
  • collect the minimum necessary information
  • avoid making clinical or pharmacy approval decisions

The backend is responsible for the workflow:

  • create the refill request
  • flag manual-review reasons
  • queue callbacks
  • optionally notify staff
  • expose staff-review APIs
  • enforce secrets and webhook verification

That keeps the AI from becoming the source of truth for business state. The assistant can request an action, but the backend decides what gets stored and how staff should review it.

Run The Example

git clone https://github.com/team-telnyx/telnyx-code-examples.git
cd telnyx-code-examples/ai-prescription-refill-intake-voice-assistant-python
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env

Fill in:

TELNYX_API_KEY=KEY...
PUBLIC_BASE_URL=https://your-ngrok-url.ngrok-free.app
TOOL_SECRET=replace_with_a_random_shared_secret
TELNYX_PHONE_NUMBER=+18005551234
TELNYX_PUBLIC_KEY=your_telnyx_public_key_here

Start the Flask backend:

python app.py

Expose it:

ngrok http 5000

Then create or update the assistant:

python provision_assistant.py

Copy the printed assistant ID into .env:

TELNYX_ASSISTANT_ID=assistant-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Point your Telnyx Call Control Application webhook to:

https://<your-ngrok-domain>/webhooks/voice

Assign your Telnyx number to that application and call the number.

The Core Code

When Telnyx sends the inbound call webhook, the app answers the call and starts the assistant:

requests.post(
    f"{TELNYX_API_BASE}/calls/{call_control_id}/actions/answer",
    headers=telnyx_headers(),
    timeout=10,
)

requests.post(
    f"{TELNYX_API_BASE}/calls/{call_control_id}/actions/ai_assistant_start",
    headers=telnyx_headers(),
    json={"assistant_id": TELNYX_ASSISTANT_ID},
    timeout=10,
)

The assistant is provisioned with webhook tools. For example, create_refill_request posts structured intake context back to the Flask app:

POST /tools/create_refill_request

That tool stores a request and returns a request ID. Follow-up tool calls can use that ID to flag manual review or queue a callback.

HIPAA-Aware Safeguards Demonstrated

This sample is not a compliance certification, but it shows implementation patterns that matter for healthcare workflows:

  • webhook signature verification
  • a shared secret on assistant tool endpoints
  • minimum necessary summaries
  • masked caller identifiers
  • explicit manual-review routing
  • assistant instructions that prohibit approval, denial, prescribing, dosage changes, diagnosis, or emergency handling

For production, add encrypted storage, staff authentication, role-based access control, audit logs, retention policies, monitoring, and compliance review.

Why This Pattern Matters

Healthcare voice AI should not be framed as replacing clinicians or pharmacists. The better use case is operational intake.

The AI answers the phone, collects structured context, and creates a clean handoff for the care or pharmacy team. The backend keeps the workflow auditable, and staff still make the actual decisions.

That is the pattern this example demonstrates:

AI handles the intake
assistant tools call your backend
backend stores structured workflow state
staff reviews and decides

Resources

  • Code example: https://github.com/team-telnyx/telnyx-code-examples/tree/main/ai-prescription-refill-intake-voice-assistant-python
  • Telnyx AI Assistant quickstart: https://developers.telnyx.com/docs/inference/ai-assistants/no-code-voice-assistant
  • Attach an AI Assistant to a Call: https://developers.telnyx.com/docs/voice/programmable-voice/ai-assistant-start
  • AI Assistant dynamic variables: https://developers.telnyx.com/docs/inference/ai-assistants/dynamic-variables
  • Telnyx Developer Docs: https://developers.telnyx.com

Ready to build with low-latency voice AI?

Join developers building the future of real-time conversations