Templates / Turn a GitHub knowledge base into a Telegram RAG bot with Qwen via OpenRouter

Turn a GitHub knowledge base into a Telegram RAG bot with Qwen via OpenRouter

Ready for 3.0

by Do Thanh Vinh ✓ · 122 views · created 2026-05-09 · Internal Wiki, AI RAG

Ready for 3.0. This template uses no nodes that n8n 3.0 removes. No removed nodes, versions or helpers found. Static check, last run 2026-10-19.

Nodes used (7)

TelegramGitHubOpenAI Chat ModelBasic LLM Chain

What it does

WHAT IT DOES This workflow turns a plain JSON file sitting in a GitHub repository into a fully functional Telegram chatbot with retrieval-augmented generation (RAG) — no Pinecone, no Qdrant, no vector database, no extra subscription. A user sends /ask <question> to your Telegram bot. The workflow pulls the knowledge base from GitHub, runs a local keyword-matching engine to find the most relevant chunks, feeds them as context to a Qwen 3 model via OpenRouter, and sends the answer back as a reply to the original message. !GitHub Knowledge Base to Telegram Bot.png(fileId:6175) HOW IT WORKS 1. Telegram Trigger Listens for messages starting with /ask. Anything shorter than 7 characters is rejected with an error message explaining the correct format. 2. Input Validation If a user sends just /ask without a question, or sends a message shorter than 7 characters, the workflow catches it immediately and replies with a clear instruction: "Please use: /ask <your question>". This prevents unnecessary API calls to GitHub and the LLM, and teaches the user the correct format on the first try. 3. GitHub File Fetch Pulls a JSON file from a GitHub repository using a Personal Access Token. If the file doesn't exist or the token is invalid, the user gets a specific error message instead of a silent failure or a generic n8n error. Same applies when the LLM returns an empty response — the user always gets a message, never silence. 4. Binary Decode & Parse Reads the raw binary output from the GitHub node, decodes it to UTF-8, and parses the JSON array. Each entry in the array is expected to have a "text" field (other field names like "content", "answer", "title" also work). 5. Rough Keyword Match Splits the user's question into individual words, scores every knowledge base entry by counting how many words appear in it, and picks the top 2 matches. This is intentionally simple — no embeddings, no vector math, no external API calls for retrieval. It works well for small-to-medium knowledge bases (up to a few hundred entries) where exact keyword overlap is a reliable signal. 6. LLM Call (Qwen 3 via OpenRouter) Sends the matched context and the original question to Qwen 3 235B through OpenRouter. The prompt instructs the model to answer strictly from the provided context. If the context doesn't contain relevant information, the model says so instead of hallucinating. 7. Output Formatting Strips any thinking tags from the model response, capitalizes the first letter, enforces Telegram's 4000-character limit, and appends a branded footer. 8. Telegram Reply Sends the formatted answer as a reply to the user's original message, so conversations stay threaded. WHY THIS APPROACH - Most RAG setups require a vector database, an embedding model, and ongoing infrastructure costs. This workflow skips all of that. The trade-off is precision — keyword matching won't catch semantic synonyms the way vector search does. But for knowledge bases that are focused on a specific topic (FAQ, product info, internal docs, local business info), keyword overlap is surprisingly effective and the setup cost is zero. - The LLM handles the fuzzy part. Even if the keyword match pulls in slightly noisy context, the model can usually extract the right answer. This division of labor - simple retrieval plus smart generation - keeps the workflow fast, cheap, and easy to maintain. SETUP (5-10 minutes) 1. Create a GitHub Fine-grained Personal Access Token with read access to the repository containing your knowledge base file. 2. Add the GitHub credential in n8n and configure the "get gh file" node with your repository owner, name, and file path. 3. Prepare your knowledge base as a JSON array: { "text": "your knowledge entry here" }, { "text": "another knowledge entry" } 4. Add your Telegram Bot credential to all four Telegram nodes. 5. Add your OpenRouter credential to the Qwen model node. You can swap Qwen for any model supported by OpenRouter by changing the model name field. 6.

View the original on n8n.io → Check your own copy

Get the weekly “what broke” email

New templates, newly broken ones, and n8n release changes. One short email a week.

Form not loading? Subscribe here.