đź“– Turn a GitHub knowledge base into a Telegram RAG bot with Qwen via OpenRouter

⚡ 122 views · 📖 Internal Wiki & Knowledge Base

💡 Pro Tip — If you need GitHub data beyond what the REST API gives you, ScraperNode has a repository scraper that extracts metadata at scale without token rate limits.

View All Scrapers

Description

WHAT IT DOES

GitHub Knowledge Base to Telegram Bot.png

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

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. Activate the workflow and send /ask <your question> to your Telegram bot.

CUSTOMIZATION

WHAT’S NEXT

This workflow is designed as a foundation. The keyword matching engine works well for small knowledge bases, but here’s where it can grow:

The current version is intentionally simple. Simple means it runs cheap, breaks rarely, and is easy to debug. Complexity can be added when the use case demands it.

REQUIREMENTS

đź”— Nodes Used

GitHub, Telegram, Telegram Trigger, Basic LLM Chain, OpenAI Chat Model

📥 Import

Download workflow.json and import into n8n: Workflow menu → Import from File

📖 Importing guide · 🔑 Credential setup