See llms.txt for all machine-readable content.

Back to Templates

Answer support questions from your docs with Telegram, OpenRouter and pgvector

Quick overview

This workflow turns a Telegram bot into an AI support agent that answers from your Postgres pgvector knowledge base using OpenRouter, and hands off to a human support chat when retrieval or the agent is not confident, while logging Q&A and errors to Postgres.

How it works

  1. Triggers when a customer sends a new message to your Telegram bot.
  2. Searches your Postgres pgvector knowledge base using OpenAI embeddings and scores the best match against a minimum similarity threshold.
  3. If retrieval is confident, uses an OpenRouter chat model with Postgres chat memory and a pgvector search tool to answer strictly from your documents.
  4. Checks whether the agent responded confidently (not empty and not “HANDOFF”) and sends the answer back to the customer in Telegram.
  5. If retrieval or the agent is not confident, notifies the customer that a human will reply and sends the question to a Telegram support chat with a “Respond” button.
  6. If the support team replies within 24 hours, forwards the human answer to the customer and saves the Q&A as a new embedded FAQ entry in the pgvector knowledge base.
  7. Logs answered/unanswered Q&A to Postgres and records any workflow errors to a Postgres error table with an alert to the support chat.

Setup

  1. Create and connect a Telegram bot, add it to your support group, and set the support group chat ID in the workflow’s supportChatId setting.
  2. Set up Postgres with pgvector plus the required tables/structures (your vectors/knowledge base tables, rag_errors, and a rag_qa_log table for Q&A logging).
  3. Add Postgres credentials for logging/chat memory and configure the pgvector connection to point at your knowledge base.
  4. Add an OpenAI API credential for embeddings and an OpenRouter credential for the chat model (choose a model that supports tool calling).
  5. Update the Agent Settings values (businessName and minSimilarity) to match your organization and desired confidence threshold.