Quick overview
This workflow replies to incoming Telegram bot messages using an Ollama, OpenAI, or Anthropic chat model constrained by your business notes, and falls back to a predefined message when it can’t answer or the AI call fails.
How it works
- Triggers when your Telegram bot receives a new message.
- Loads recent conversation turns for the Telegram chat from n8n’s workflow static data to provide context.
- Builds a provider-specific chat request (Ollama, OpenAI, or Anthropic) by injecting your business name, knowledge notes, conversation history, and the new message into a JSON-only prompt.
- Sends the request to the selected AI endpoint via HTTP.
- Parses the AI response as JSON and only uses the model’s reply when it marks the question as answerable, otherwise it uses your predefined fallback message.
- Sends the chosen reply back to the customer in Telegram and appends both the customer and bot messages to the stored chat log.
- If the AI request errors, sends the fallback message to Telegram so the customer still gets a response.
Setup
- Create a Telegram bot with BotFather and connect your Telegram credentials in the Telegram Trigger and Telegram send-message nodes.
- In the Settings node, fill in business_name, knowledge (one fact per line), and optionally customize cannot_answer_message, ai_provider, and ai_model.
- If using Ollama, ensure Ollama is running and reachable at ollama_url and that the selected model is pulled locally.
- If using OpenAI or Anthropic, configure header-based authentication on the HTTP Request node with your API key credential and set ai_provider and ai_model accordingly.