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
- Triggers when a customer sends a new message to your Telegram bot.
- Searches your Postgres pgvector knowledge base using OpenAI embeddings and scores the best match against a minimum similarity threshold.
- If retrieval is confident, uses an OpenRouter chat model with Postgres chat memory and a pgvector search tool to answer strictly from your documents.
- Checks whether the agent responded confidently (not empty and not “HANDOFF”) and sends the answer back to the customer in Telegram.
- 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.
- 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.
- 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
- 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.
- 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).
- Add Postgres credentials for logging/chat memory and configure the pgvector connection to point at your knowledge base.
- Add an OpenAI API credential for embeddings and an OpenRouter credential for the chat model (choose a model that supports tool calling).
- Update the Agent Settings values (businessName and minSimilarity) to match your organization and desired confidence threshold.