Build an AI Phone Story Hotline — Interactive Storytelling with Telnyx Voice AI | Low Latency Club
Skip to main content
Blog<br>Code-first technical deep dives
Glossary<br>Voice AI & telecom terminology
Developer Docs<br>API references & integration guides
GitHub<br>Open-source repos & SDKs
Articles<br>Tutorials & support articles
AI Agents<br>Build voice AI agents
Voice API<br>Programmable voice calls
ClawHouse<br>AI-powered voice assistant
ClawdTalk<br>Conversational AI platform
Events<br>Videos<br>Podcast<br>Integrations
Resources
Blog<br>Code-first technical deep dives
Glossary<br>Voice AI & telecom terminology
Developer Docs<br>API references & integration guides
GitHub<br>Open-source repos & SDKs
Articles<br>Tutorials & support articles
Products
AI Agents<br>Build voice AI agents
Voice API<br>Programmable voice calls
ClawHouse<br>AI-powered voice assistant
ClawdTalk<br>Conversational AI platform
Contact us<br>Join our Slack
Imagine calling a phone number, picking a genre — mystery, sci-fi, fantasy, horror, or romance — and listening to an AI narrate a story that adapts to your choices in real time. Press 1 to open the creaking door. Press 2 to check the window. The story branches, the AI continues, and every call is a new adventure.
This is the AI Phone Story Hotline — a 104-line Python app built with Telnyx Call Control and AI Inference. No game engine, no branching script, no pre-written dialogue trees. The AI generates the story as you go, and your phone keypad shapes what happens next.
In this walkthrough, you'll build it from scratch. Clone the repo, configure a phone number, and deploy in minutes.
What You'll Build
A phone number that anyone can call to start an interactive story:
Caller dials in — Telnyx answers and greets them with a genre menu
Caller picks a genre — press 1–5 for mystery, sci-fi, fantasy, horror, or romance
AI generates chapter one — a 3–4 sentence story segment ending with two choices
Caller chooses — press 1 or 2, or speak the choice aloud
Story continues — AI generates the next chapter based on the choice, keeping full conversation context
After 5 chapters — the AI brings the story to a satisfying ending
The whole interaction is voice-driven: Text-to-Speech reads each chapter, and the caller responds with DTMF keypresses or speech. The AI model (Llama 3.3 70B via Telnyx AI Inference) handles the storytelling, and Call Control handles the telephony.
Why This Is Interesting
Most AI phone demos are business use cases — book a table, qualify a lead, reset a password. This one is different. It's creative AI — the model is writing fiction in real time, branching based on human input, and delivering it over a phone call. The storytelling format (short chapters, two choices each) keeps the AI responses tight and the call engaging.
It also demonstrates a pattern that works for any conversational AI app: webhook-driven state machine + LLM with conversation memory + voice I/O. Once you see how the story hotline works, you can swap the storytelling prompt for any domain — a choose-your-own-adventure onboarding flow, an interactive quiz, a branching training simulation.
Prerequisites
Python 3.8+
A Telnyx account with funded balance
A Telnyx API key
A Telnyx phone number with voice enabled
A Call Control Application configured with your webhook URL
ngrok for exposing your local server to Telnyx webhooks
The Architecture
Phone Call<br>Telnyx Call Control (webhook events)<br>Flask app (app.py, 104 lines)<br>├──► call.initiated → answer the call<br>├──► call.answered → TTS greeting + genre menu<br>├──► call.gather.ended → DTMF/speech input → AI Inference<br>├──► call.speak.ended → gather next choice → AI Inference<br>└──► call.hangup → cleanup session<br>Telnyx AI Inference (Llama 3.3 70B)<br>Story chapter (TTS back to caller)<br>The app is a state machine driven by Telnyx webhook events. Each event triggers the next action — answer, speak, gather, or hang up. The AI Inference call sits in the middle, generating story chapters from the running conversation history.
Step 1: Clone and Configure
git clone https://github.com/team-telnyx/telnyx-code-examples.git<br>cd telnyx-code-examples/ai-phone-story-hotline-python<br>cp .env.example .env<br>pip install -r requirements.txt<br>Edit .env with your credentials:
TELNYX_API_KEY=KEY0123456789ABCDEF # from portal.telnyx.com/api-keys<br>TELNYX_PUBLIC_KEY= # from portal.telnyx.com/api-keys (public key)<br>STORY_NUMBER=+13105551234 # your Telnyx phone number<br>AI_MODEL=meta-llama/Llama-3.3-70B-Instruct<br>Step 2: Understand the Code
The entire app is 104 lines in a single file: app.py. Here are the key pieces.
Webhook Signature Verification
Every Telnyx webhook is signed with an Ed25519 key. The app verifies the signature before trusting any event:
@app.route("/webhooks/voice", methods=["POST"])<br>def handle_voice():<br>try:<br>client.webhooks.unwrap(request.get_data(as_text=True), headers=dict(request.headers))<br>except Exception:<br>return jsonify({"error": "invalid signature"}), 401<br>This prevents spoofed webhook calls from...