Build a CBT AI Chatbot with Line & Azure OpenAI in n8n

Discover how to create a CBT-focused AI chatbot using n8n automation with Line Messaging API and Azure OpenAI. This workflow handles user text inputs, provides real-time CBT guidance, and manages unsupported message types effectively, improving user engagement and therapy accessibility.
webhook
httpRequest
agent
+4
Workflow Identifier: 1369
NODES in Use: Webhook, HTTP Request, If, AI Agent, Azure OpenAI Chat Model, Set, Sticky Note
Automate CBT chatbot with n8n and Azure OpenAI

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

What this workflow does

This workflow connects Line chat to Azure OpenAI to give quick, smart replies using Cognitive Behavioral Therapy (CBT) ideas.
It helps answer text questions fast, and tells users when non-text messages are not supported.
Users get helpful, clear mental health advice without waiting long.


Who should use this workflow

Anyone running mental health chat support on Line who wants to save time.
It fits people needing reliable chatbot replies for many users without extra staff.


Tools and services used

  • n8n: Automates the chatbot flow.
  • Line Messaging API: Receives and replies messages.
  • Azure OpenAI GPT-4: Generates CBT-based advice.
  • Generic HTTP Header Auth: Secures Line API requests.

Inputs, Processing, and Outputs

Inputs

  • Text messages sent by Line users.
  • Non-text messages like images or stickers.

Processing

  • Webhook node listens to Line messages.
  • HTTP Request node sends “typing” animation to Line.
  • If node checks if the message is text.
  • AI Agent node runs CBT system prompt for text input.
  • Azure OpenAI Chat Model node creates chatbot replies.
  • Set node formats AI output for JSON.
  • HTTP Request node replies to Line with text or unsupported message notice.

Outputs

  • Human-like CBT text replies inside Line chat.
  • Polite note when images or stickers are sent.

Beginner step-by-step: How to use this workflow in n8n production

Step 1: Get the workflow file

  1. Download the workflow using the Download button on this page.

Step 2: Import into n8n

  1. Open the n8n editor.
  2. Click “Import from File” and select the downloaded file.

Step 3: Add credentials

  1. Go to each HTTP Request node, open the credential selector.
  2. Add or select the HTTP Header Auth with a valid Line channel access token.
  3. For the Azure OpenAI node, add your Azure OpenAI API Key.

Step 4: Update IDs if needed

  1. Check webhook URLs and replace any placeholder IDs or paths if necessary.

Step 5: Test the workflow

  1. Send text and image messages from your Line user to verify replies.

Step 6: Activate workflow for production

  1. Toggle the workflow active.
  2. Make sure webhook URL is public and reachable by Line API servers.
  3. Visit self-host n8n if needing a server to run the workflow securely.

Step-by-step description of workflow components

Webhook node

Receives user messages from Line and triggers the automation.

HTTP Request node – Loading Animation

Sends a “typing” indicator to the chat to show reply is coming.

If node

Checks if the user message type is “text” to process or reject.

AI Agent node

Receives user text and runs CBT system prompt to create helpful advice.

Azure OpenAI Chat Model node

Runs GPT-4 or similar model for detailed, empathetic chatbot answers.

Set node

Formats AI reply by removing unwanted code or characters to plain text.

HTTP Request node – ReplyMessage Line

Sends the chatbot’s reply back to the user inside the Line chat app.

HTTP Request node – ReplyMessage Not Supported

Replies politely when images or other non-text message types come in.


Customizations ideas

  • Edit AI Agent node system prompt to switch therapy style like mindfulness.
  • Change temperature in Azure OpenAI node to make responses more creative.
  • Add support for images or audio by branching If node and new reply nodes.
  • Support multiple languages by detecting and translating user text first.
  • Save chat logs into sheets or databases for therapy tracking.

Troubleshooting common problems

401 Unauthorized from Line API

Means the HTTP Header Auth token is wrong or expired.

Fix by updating the Line channel access token in the credential settings.

AI Agent node gives poor replies

System prompt might be generic or missing CBT details.

Improve by adding specific CBT instructions in the system prompt.

Webhook not working

Webhook URL may be wrong or disabled in Line Developer Console.

Check URL matches exactly and remove “test” if making production.


Pre-production checklist

  • Verify webhook URL is correct and enabled in Line Console.
  • Test sending text and non-text messages for correct bot replies.
  • Confirm HTTP Header Auth tokens are valid and up-to-date.
  • Check AI Agent node creates meaningful CBT-style answers.
  • Make sure replies show promptly in Line app.
  • Backup workflow JSON before changing.

Deployment steps

Activate the workflow in n8n editor.

Make webhook URL public and accessible.

Watch executions in n8n to catch issues early.

Tweak AI Agent prompt or model parameters for better chat tone.


Summary of benefits and results

✓ Chatbot answers mental health questions fast using CBT.
✓ Saves hours of manual replies.
✓ Handles unsupported input types politely.
✓ Scales without needing more helpers.
✓ Easy to set up and modify in n8n.

Automate CBT chatbot with n8n and Azure OpenAI

Visit through Desktop to Interact with the Workflow.

Frequently Asked Questions

Update the HTTP Header Authentication token with a valid Line channel access token.
Edit the AI Agent node’s system prompt with clear CBT instructions and examples.
Check the webhook URL matches the n8n URL exactly and is enabled in the Line Developer Console.
Yes, with enough n8n infrastructure and Azure OpenAI capacity the workflow can scale to many users.

Promoted by BULDRR AI

Related Workflows

Automate Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.