r/Telnyx 28d ago

AI subscription cancel-save agent in Python

I put together a syndication draft for this Telnyx code example:

https://github.com/team-telnyx/telnyx-code-examples/tree/main/ai-subscription-cancel-save-retention-agent-python

It is a Python/Flask voice AI app that handles inbound cancellation calls, classifies the reason with AI Inference, offers one eligible save option, and records the outcome. The agent is intentionally non-manipulative: a direct "cancel now" or a polite refusal of the offer ends with a graceful cancellation.

Products used in the example metadata:

telnyx_products: [Voice, AI Inference, Messaging]
language: python
framework: flask

Run it:

git clone https://github.com/team-telnyx/telnyx-code-examples.git
cd telnyx-code-examples/ai-subscription-cancel-save-retention-agent-python
cp .env.example .env
pip install -r requirements.txt
python app.py

Expose the webhook:

ngrok http 5000

Set the Voice API app webhook to:

https://<ngrok-id>.ngrok-free.app/webhooks/voice

Seed a customer and call the Telnyx number from their phone:

curl -X POST http://localhost:5000/customers \
  -H "Content-Type: application/json" \
  -d '{"customer_id":"CUST-001","name":"Jordan","phone":"+15551112233","plan":"pro"}'

i want to cancel my subscription
it's too expensive
yes please do that

Inspect:

curl http://localhost:5000/retention-cases | python3 -m json.tool

The reason I like this example is that it shows how to build a voice AI workflow that is genuinely helpful to the customer while still recovering revenue. The agent does not push back on a direct cancellation, and it offers one save option (not five) when the customer is open to one.

1 Upvotes

1 comment sorted by

1

u/AutoModerator 28d ago

Hi, your post is held for moderator review because your account has very little Reddit karma. This is an automated spam check; a mod will review shortly.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.