n8n tutorial - Lesson 28: Build a RAG Chatbot with n8n Pinecone and Telegram
Hi everyone, in this post I'll show you how to build a RAG chatbot that answers questions over Telegram using n8n, Pinecone, and Claude Haiku — a practical n8n RAG pipeline tutorial from real session notes. This is part of the n8n Workflow Automation Tutorial series, and by the end you'll have a working Telegram bot that queries your Pinecone knowledge base on demand.
How to do:
Step 1 — Prepare the RAG Query Sub-Workflow
Before building the Telegram-facing workflow, you need to make your existing RAG query workflow callable by other workflows in n8n.- Open your existing RAG query workflow — in this series it is named T8-B2-RAG-Query.
- Add a new trigger node: search for and select When Executed by Another Workflow.
- Inside that trigger node, define one input field:
- Field name:
query - Field type:
String
- Field name:
- Save the workflow and set its status to Active.
Note — The Call n8n Workflow tool node only lists sub-workflows that have a When Executed by Another Workflow trigger. If your workflow uses a Chat Trigger or Manual Trigger only, it will not appear in the tool's dropdown. You must add this trigger and declare the input schema for the workflow to be usable as a tool.
Step 2 — Create the RAG Telegram Workflow
This step builds the main workflow — T8-B3-RAG-Telegram — that receives a Telegram message and routes it through an AI Agent with Pinecone-backed RAG.- Create a new workflow and name it
T8-B3-RAG-Telegram. - Add a Telegram Trigger node as the entry point. Configure it with your Telegram bot token so it listens for incoming messages.
- Add an AI Agent node and connect it to the Telegram Trigger output.
- Set the model to Claude Haiku 4.5 (or your preferred model credential).
- Pass the user's message from the trigger as the agent's input prompt.
- Inside the AI Agent's Tools section, add a Call n8n Workflow tool.
- In the Call n8n Workflow tool, select T8-B2-RAG-Query from the workflow list and map the
queryfield to the incoming user message. - Add a Telegram node at the end, set the action to Send Message, and map the Chat ID and the AI Agent's output text as the message body.
- Save and set the workflow to Active.
Tip — When mapping the Chat ID for the reply, use the value from the Telegram Trigger output — typically $json.message.chat.id. This ensures the bot always replies to the correct conversation thread.
Step 3 — Test the End-to-End RAG Chatbot
With both workflows active, send a real message through Telegram to confirm the full pipeline works.- Open Telegram and find your bot.
- Send a question that is covered by your Pinecone knowledge base.
- Confirm that:
- The Telegram Trigger fires and passes the message to the AI Agent.
- The AI Agent calls T8-B2-RAG-Query with the
queryfield populated. - The RAG query retrieves relevant context from Pinecone and returns it to the agent.
- The agent composes a response and the Telegram send node delivers it back to the chat.
- Check the execution logs in n8n for each workflow to verify no errors occurred.
Tip — If the bot replies but the answer is not grounded in your knowledge base, check that the T8-B2-RAG-Query workflow is returning results correctly by running it manually with a test query value first.
Step 4 — Set Up a Cloudflare Named Tunnel (for a Stable Webhook URL)
A named Cloudflare Tunnel gives your local n8n instance a permanent public HTTPS URL, so Telegram webhooks never break on restart — unlike Quick Tunnel which generates a new URL every time.- Log in to your Cloudflare account and add your domain (e.g.
dan14.vn) on the free plan. - At your domain registrar, replace the existing nameservers with the two Cloudflare nameservers provided — for example:
brenna.ns.cloudflare.comhasslo.ns.cloudflare.com
- Wait for DNS propagation — typically 1–2 hours but can take up to 24 hours. Cloudflare will send a confirmation email when the domain is active.
- Once you receive the "your domain is now active on Cloudflare" email, open a terminal and run:
cloudflared tunnel login— a browser window opens; select your domain and click Authorize.cloudflared tunnel create n8n-tunnel— note the Tunnel ID that is returned.cloudflared tunnel route dns n8n-tunnel n8n.dan14.vn— this creates a CNAME record in your Cloudflare DNS automatically.
- Create the tunnel config file at
C:\Users\<user>\.cloudflared\config.ymlwith the following content:tunnel: <TUNNEL_ID> credentials-file: C:\Users\<user>\.cloudflared\<TUNNEL_ID>.json ingress: - hostname: n8n.dan14.vn service: http://localhost:5678 - service: http_status:404 - Start the tunnel by running:
cloudflared tunnel run n8n-tunnel
Note — The last ingress rule — service: http_status:404 — is required as a catch-all. Cloudflare will reject the config if no catch-all rule is present.
Step 5 — Update n8n Webhook URL and Restart
After the tunnel is live, update n8n's environment config so all webhooks use the new permanent domain.- Open your Docker Compose file at
D:\n8n\docker-compose.yml. - Find the
WEBHOOK_URLenvironment variable and set it to:https://n8n.dan14.vn - Save the file and restart Docker:
- Run
docker compose downthendocker compose up -din the same directory.
- Run
- In n8n, deactivate and reactivate any webhook-based workflows — for example T7-B2-Telegram-Chatbot and T8-B3-RAG-Telegram — so they re-register with the new URL.
Production tip — Always deactivate then reactivate webhook workflows after changing WEBHOOK_URL. n8n caches the webhook registration URL at activation time, so existing active workflows will still point to the old address until you cycle them.
Key Lessons from This Session
- Sub-workflows must have a "When Executed by Another Workflow" trigger to appear as a callable tool. Chat Trigger and Manual Trigger are not recognized by the Call n8n Workflow tool node — you must add this specific trigger and declare the input schema.
- Named Tunnels require your domain to be managed inside Cloudflare DNS. Quick Tunnel works without a domain but the URL changes on every restart, breaking all registered webhooks.
- The Cloudflare tunnel setup order matters: add domain → change nameservers → wait for propagation → login with cloudflared → create tunnel → route DNS → write config → run tunnel.
- Reactivating workflows after a webhook URL change is mandatory. n8n does not automatically re-register webhooks when the environment variable changes.
Conclusion:
In this n8n RAG pipeline tutorial, you built a fully functional RAG chatbot on Telegram by chaining a Telegram Trigger, an AI Agent, and a callable RAG sub-workflow backed by Pinecone — a key milestone in this n8n workflow automation series. You also learned how to give your local n8n instance a stable public URL using a Cloudflare Named Tunnel, which is essential for reliable webhook-based workflows in production. Next session, the focus shifts to completing the Named Tunnel setup and verifying the permanent webhook URL end-to-end.
If you have any questions, feel free to leave a comment below. Thank you!
Tags: n8n RAG pipeline tutorial, n8n tutorial, n8n workflow automation, Telegram chatbot n8n, Pinecone n8n integration, Cloudflare tunnel n8n, AI agent n8n, n8n sub-workflow
Maybe you are interested!
- Getting Started with n8n: Interface & Your First Manual Trigger
- n8n HTTP Request Node: Connect Any API Without Code
- Branching Workflows: IF, Switch & Merge Nodes in n8n
- n8n Expressions & Built-in Variables: The Complete Guide
- Comparing AI Models in n8n: Claude vs Gemini vs ChatGPT
- Connect Gmail to n8n: OAuth Setup & Reading Emails
- Build an AI Email Classifier with n8n
- Automated Email Digest to Telegram with n8n
- Google Sheets Automation with n8n: 4 Key Operations
- Auto-Generate Google Docs from Data with n8n