Conversational AI

Build a Web Chatbot with a Telnyx AI Assistant

A useful AI assistant demo does not always need a phone call. Sometimes the fastest way to show the value of a Portal-managed assistant is a simple web chat: type a question,.

A useful AI assistant demo does not always need a phone call. Sometimes the fastest way to show the value of a Portal-managed assistant is a simple web chat: type a question, send it to the assistant, and render the answer in your own UI.

The canonical code example is in the Telnyx code examples repo:

https://github.com/team-telnyx/telnyx-code-examples/tree/main/chat-with-ai-assistant-python

What This Example Builds

This example shows how to build a small Flask app that talks to a Telnyx AI Assistant. The assistant is configured in the Telnyx Mission Control Portal, while the application controls the user experience.

The flow is:

browser
  -> flask backend
  -> telnyx conversation
  -> portal-managed ai assistant
  -> assistant response
  -> browser ui

This is a clean pattern for developer demos because the API key stays on the server, the assistant configuration stays in the Portal, and the frontend can be customized like any other web app.

Why This Matters

Developers often want two things at the same time: a managed assistant they can configure without redeploying code, and a custom interface that matches their product. Telnyx AI Assistants support that split.

You can configure instructions, model behavior, voice or messaging settings, and conversation history in Telnyx, then build a web, mobile, voice, or messaging experience around the assistant.

For this demo, the assistant is a Telnyx Chatbot. It answers product questions like:

What is Telnyx?
What is a Frankenstack?
How do Telnyx AI Assistants work?
What can I build with the Voice API?

How The API Flow Works

The current chat flow has two steps.

First, create a conversation:

curl -X POST https://api.telnyx.com/v2/ai/conversations \
  -H "Authorization: Bearer $TELNYX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Web chat demo",
    "metadata": {
      "assistant_id": "assistant_xxx",
      "telnyx_conversation_channel": "web_chat"
    }
  }'

Then send a message to the assistant:

curl -X POST https://api.telnyx.com/v2/ai/assistants/assistant_xxx/chat \
  -H "Authorization: Bearer $TELNYX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "conversation_id": "conversation_xxx",
    "content": "What is Telnyx?"
  }'

The Flask backend wraps those calls so the browser never sees the Telnyx API key.

Run It Locally

git clone https://github.com/team-telnyx/telnyx-code-examples.git
cd telnyx-code-examples/chat-with-ai-assistant-python
cp .env.example .env
pip install -r requirements.txt
python app.py

Add your environment variables:

TELNYX_API_KEY=your_telnyx_api_key
AI_ASSISTANT_ID=your_ai_assistant_id
PORT=5000

Open:

http://localhost:5000

Demo Script

For a live demo, keep the questions short:

What is Telnyx?
What is a Frankenstack?
How do AI Assistants work?

The point is not to show a generic chatbot. The point is to show that a Portal-managed Telnyx AI Assistant can power a custom product experience.

Production Notes

For production, add user authentication, persistent conversation storage, rate limiting, logging, and a clearer separation between demo shortcuts and real assistant calls. If you expose this publicly, keep the Telnyx API key on the server and validate all user input before sending it to downstream systems.

Resources

Share on Social
Anusha Thukral
Developer Advocate

Anusha Thukral is a Developer Advocate at Telnyx, she helps developers understand and build with Voice AI and communications technologies. She studied Cognitive Systems at the University of British Columbia, focusing on the intersection of technology and human behavior.