DEV Community

Cover image for I Built a Telegram Bot That Guides You Through CBT Thought Records — No AI, No App, No Signup
CBT Tools
CBT Tools

Posted on

I Built a Telegram Bot That Guides You Through CBT Thought Records — No AI, No App, No Signup

Therapy apps are heavy. AI chatbots hallucinate. And sometimes you just need to write down a thought, see which cognitive distortion it matches, and reframe it — in 3 minutes, from your phone, without downloading anything.

So I built a Telegram bot that walks you through a 7-step CBT thought record right in chat. No app to install. No account to create. No AI that might make things up. Just a structured, deterministic conversation based on decades of cognitive-behavioral therapy research.

Try it: message @trevor_pl_bot on Telegram, send /record, and follow the prompts.

What Is a CBT Thought Record?

A thought record is the core homework tool of cognitive-behavioral therapy. It's a structured 7-column worksheet:

  1. Situation — What happened?
  2. Thought — What went through your mind?
  3. Emotion — What did you feel? (0-100 intensity)
  4. Evidence For — What supports the thought?
  5. Evidence Against — What contradicts it?
  6. Balanced Thought — A fairer, more accurate perspective
  7. Re-rate Emotion — How do you feel now? (0-100)

The magic is in steps 4-6. Most people don't naturally look for evidence against their anxious thoughts. The thought record forces you to. That's the intervention.

Why a Telegram Bot?

Option Problem
Therapy app Download, signup, onboarding, paywall
AI chatbot Hallucinates reframes. CBT reframes must be clinically accurate.
Notion template Great for journaling, but doesn't guide you step-by-step
Web tool Works, but you need a browser tab open
Telegram bot Already have Telegram. Send a message. Done.

Telegram has 900 million active users. If you have Telegram, you have the bot. No install, no signup, no login. The conversation is the interface.

The Architecture: A State Machine, Not an LLM

The bot uses python-telegram-bot's ConversationHandler — a built-in state machine. Each step of the thought record is a state. The user's message transitions to the next state.

# 7 states, one per thought record step
SITUATION, THOUGHT, EMOTION, EVIDENCE_FOR, EVIDENCE_AGAINST, BALANCED, RERATE = range(7)

conv_handler = ConversationHandler(
    entry_points=[CommandHandler("record", start_record)],
    states={
        SITUATION:        [MessageHandler(filters.TEXT, got_situation)],
        THOUGHT:          [MessageHandler(filters.TEXT, got_thought)],
        EMOTION:          [MessageHandler(filters.TEXT, got_emotion)],
        EVIDENCE_FOR:     [MessageHandler(filters.TEXT, got_evidence_for)],
        EVIDENCE_AGAINST: [MessageHandler(filters.TEXT, got_evidence_against)],
        BALANCED:         [MessageHandler(filters.TEXT, got_balanced)],
        RERATE:           [MessageHandler(filters.TEXT, got_rerate)],
    },
    fallbacks=[CommandHandler("cancel", cancel)],
)
Enter fullscreen mode Exit fullscreen mode

No database. No session storage. Telegram + the ConversationHandler handle all state. The bot is stateless between messages — Telegram sends the update, the handler routes it to the right state, the bot responds.

This is the simplest possible architecture for a multi-step conversation. An LLM would need context window management, prompt engineering, hallucination guards, and a database to store the conversation. The state machine needs none of that.

The Distortion Detector: Rule-Based, Not ML

After the user enters their thought (step 2), the bot runs a cognitive distortion detector. This is the same keyword-pattern matching algorithm I wrote about before — ported from JavaScript to Python.

DISTORTIONS = {
    "all_or_nothing": {
        "name": "All-or-Nothing Thinking",
        "keywords": ["always", "never", "complete failure", "total", "perfect"],
        "reframe": "Is it really all or nothing? Where's the middle ground?"
    },
    "catastrophizing": {
        "name": "Catastrophizing",
        "keywords": ["disaster", "end", "ruined", "can't handle", "breakdown"],
        "reframe": "What's the most likely outcome, not the worst?"
    },
    # ... 10 distortions total
}

def detect_distortion(thought):
    thought_lower = thought.lower()
    matches = []
    for key, d in DISTORTIONS.items():
        if any(kw in thought_lower for kw in d["keywords"]):
            matches.append(d)
    return matches
Enter fullscreen mode Exit fullscreen mode

Why rule-based, not ML? For CBT distortion detection:

  • Precision: A keyword match is a guaranteed signal. An LLM might say "this looks like catastrophizing" — but it might be wrong, and you can't see why.
  • Zero hallucination: The reframe suggestions come from a fixed table written by a therapist. An LLM might generate a reframe that's clinically inappropriate.
  • Explainability: The user can see which keyword triggered the detection. The full chain is transparent.
  • Zero cost: No API calls. No GPU. The detection runs in microseconds.
  • Small known output space: There are only 11 cognitive distortions. You don't need a language model to classify into 11 categories — a keyword lookup is sufficient and more reliable.

The Full User Experience

Here's what happens when you send /record to @trevor_pl_bot:

Bot: Let's do a CBT Thought Record. 7 steps.
     Step 1: What situation triggered your reaction?
     (Describe what happened — where, when, who)

You: My manager said my code needs "significant rework"

Bot: Step 2: What thought went through your mind?
     (The automatic thought — your first reaction)

You: I'm terrible at my job, they're going to fire me

Bot: 🔍 Detected: All-or-Nothing Thinking, Catastrophizing, Mind-Reading
     Step 3: What emotion did you feel? (0-100 intensity)

You: anxiety 85

Bot: Step 4: What evidence supports this thought?

You: The code did need a lot of changes

Bot: Step 5: What evidence goes against this thought?

You: I've shipped good work before. "Significant rework" 
     doesn't mean fire. They're investing time in fixing it,
     not replacing me.

Bot: Step 6: Write a balanced thought (fairer perspective)

You: My code needs work on this PR, but that doesn't mean 
     I'm terrible. Feedback is normal.

Bot: Step 7: Re-rate your anxiety (0-100)

You: 40

Bot: ✅ Thought Record Complete.
     Anxiety: 85 → 40 (↓53%)

     📋 Summary saved. 
     🔧 Try the full interactive toolkit: 
        https://473185670.github.io/cbt-toolkit/
     📝 Want a Notion template for daily records? 
        https://4043969836017.gumroad.com/l/yyzll
Enter fullscreen mode Exit fullscreen mode

The distortion detection happens automatically after step 2. The user sees which distortions their thought matches — this is the insight that CBT provides. Then the evidence steps (4-5) are where the restructuring happens.

Why This Bot Is Different from AI Therapy Bots

There are AI therapy bots on Telegram. They use LLMs to chat with you about your feelings. That's a fundamentally different approach:

AI Therapy Bot This Bot (CBT Thought Record)
Method Free-form chat Structured 7-step worksheet
Output Varies every time Same structure every time
Accuracy May hallucinate Deterministic, clinically grounded
Cost API calls per message Zero (keyword matching)
Privacy Thoughts sent to LLM API Thoughts stay in Telegram
What it is A chatbot pretending to be a therapist A structured tool, not a therapist

This bot is not a therapist. It's a structured tool that guides you through a well-researched CBT exercise. The structure is the feature — not the conversation.

The Tech Stack

  • python-telegram-bot 22.8 — async Telegram bot framework
  • ConversationHandler — built-in state machine for multi-step conversations
  • No database — Telegram handles all state between messages
  • No AI/ML — keyword-pattern matching for distortion detection
  • ~280 lines of Python — the entire bot

The bot runs on a single process, polling for updates. No web server, no webhook, no SSL certificate. Just application.run_polling().

Try It

  1. Open Telegram
  2. Search for @trevor_pl_bot
  3. Send /record
  4. Follow the 7 prompts

It takes 3-5 minutes to complete a thought record. Do one when you're feeling anxious, stressed, or stuck on a negative thought pattern.

Free Toolkit

The bot is part of a larger free CBT toolkit:

All free. No signup. No backend. No AI hallucination. Privacy-first.


If this was helpful, the best CBT tool is the one you actually use. Try the bot, try the web tools, and if you want a structured daily practice, there's a Notion template for that.

Top comments (0)