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

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

Learn how to Build this Workflow with AI:

Visit through Desktop for Best experience

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.

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 Viral UGC Video Creation Using n8n + Degaus (Beginner-Friendly Guide)

Learn how to automate viral UGC video creation using n8n, AI prompts, and Degaus. This beginner-friendly guide shows how to import, configure, and run the workflow without technical complexity.
Form Trigger
Google Sheets
Gmail
+37
Free

AI SEO Blog Writer Automation Workflows in n8n

A complete beginner guide to building an AI SEO blog writer automation using n8n.
AI Agent
Google Sheets
httpRequest
+5
Free

Automate CrowdStrike Alerts with VirusTotal, Jira & Slack

This workflow automates processing of CrowdStrike detections by enriching threat data via VirusTotal, creating Jira tickets for incident tracking, and notifying teams on Slack for quick response. Save hours daily by transforming complex threat data into actionable alerts effortlessly.
scheduleTrigger
httpRequest
jira
+5
Free

Automate Telegram Invoices to Notion with AI Summaries & Reports

Save hours on financial tracking by automating invoice extraction from Telegram photos to Notion using Google Gemini AI. This workflow extracts data, records transactions, and generates detailed spending reports with charts sent on schedule via Telegram.
lmChatGoogleGemini
telegramTrigger
notion
+9
Free

Automate Email Replies with n8n and AI-Powered Summarization

Save hours managing your inbox with this n8n workflow that uses IMAP email triggers, AI summarization, and vector search to draft concise replies requiring minimal review. Automate business email processing efficiently with AI guidance and Gmail integration.
emailReadImap
vectorStoreQdrant
emailSend
+12
Free

Automate Email Campaigns Using n8n with Gmail & Google Sheets

This n8n workflow automates personalized email outreach campaigns by integrating Gmail and Google Sheets, saving hours of manual follow-up work and reducing errors in email sequences. It ensures timely follow-ups based on previous email interactions, optimizing communication efficiency.
googleSheets
gmail
code
+5
Free