Skip to content
bottomtext228 edited this page Jun 2, 2026 · 2 revisions

Auto-reply and AI

The bot supports two auto-reply mechanisms: keyword-based canned responses (built-in) and AI-powered replies via LLM (optional). Both can be used simultaneously — keyword rules are checked first, and the LLM handles messages that don't match any rule.


Keyword-Based Auto-reply Rules

Define question-answer pairs in config.yaml. When a user message contains the question text as a substring (case-insensitive), the answer is sent automatically. First matching rule wins.

Configuration

autoreply:
  - question: "install"
    answer: "You can install using our [Getting Started guide](https://github.com/bostrot/telegram-support-bot/wiki/Getting-started)"
  - question: "refund policy"
    answer: "We offer full refunds within 30 days of purchase."
  - question: "hours"
    answer: "Our support team is available Monday-Friday, 9am-5pm CET."

How Matching Works

User Message Matches Rule Reason
"How do I install?" question: "install" Case-insensitive substring match
"What's your refund policy?" question: "refund policy" Substring match
"Do you offer refunds?" no match Neither "refund" nor "policy" appear together as defined rule
"Installation help please" question: "install" Matches substring "install" (case-insensitive)

Auto-reply Behavior in Staff Chat

When an auto-reply is sent, the following occurs based on your settings:

  • If show_auto_replied: true, a notification is forwarded to the staff chat indicating which canned response was triggered
  • The user sees the reply with a signature from language.automatedReplyAuthor (default: "BottyBot")
  • Users can provide feedback via the doesntHelp ("This does not help") button on auto-replies

Markdown in Answers

Auto-reply answers support MarkdownV2 formatting. Use \n for line breaks within YAML strings:

autoreply:
  - question: "pricing"
    answer: "*Plans:*  \n- Basic: $9/mo  \n- Pro: $19/mo  \n- Enterprise: Contact us"

LLM-Powered Auto-reply

Enable AI-generated responses using any LiteLLM-compatible proxy. The bot sends the user's message along with your custom knowledge base to the LLM, which generates a contextually appropriate reply.

Configuration

use_llm: true                              # Enable LLM auto-replies
llm_api_key: 'sk-your-api-key-here'        # API key for your provider
llm_base_url: 'https://api.openai.com/v1'  # LiteLLM proxy or direct API endpoint
llm_model: 'gpt-4o'                        # Model identifier
llm_knowledge: |                           # Custom knowledge base (multi-line string)
  Company ABC provides cloud hosting services.
  
  Pricing tiers:
  - Starter: $5/mo, 10GB storage, shared resources
  - Business: $20/mo, 100GB storage, dedicated CPU
  - Enterprise: Custom pricing
  
  Support hours: Mon-Fri 9am-6pm CET.
  
  Refund policy: Full refund within first 14 days. No refunds after that.

Settings Reference

Setting Type Description
use_llm boolean Enable/disable LLM auto-replies. Automatically sets show_auto_replied: true.
llm_api_key string API key for the LLM provider or LiteLLM proxy
llm_base_url string Base URL of the LLM endpoint (e.g., OpenAI, Anthropic via LiteLLM)
llm_model string Model name (e.g., gpt-4o, claude-3-haiku, mistralai/ministral-3b)
llm_knowledge string Custom knowledge base text injected as context — the LLM uses this to generate company-specific answers

How It Works

  1. User sends a message that doesn't match any keyword autoreply rule
  2. Bot constructs a prompt with: user's question + llm_knowledge content + system instructions
  3. Sends request to the configured LLM endpoint
  4. Returns the generated response to the user, attributed as an automated reply

LiteLLM Proxy Setup

LiteLLM allows you to use any LLM provider through a single API-compatible endpoint. To set up:

  1. Install and run LiteLLM proxy
  2. Configure it with your preferred LLM providers (OpenAI, Anthropic, Mistral, etc.)
  3. Point llm_base_url to your LiteLLM instance:
use_llm: true
llm_api_key: 'your-litellm-proxy-key'
llm_base_url: 'http://localhost:4000/v1'   # Your LiteLLM proxy URL
llm_model: 'claude-3-haiku'                # Any model your proxy routes to

Knowledge Base Tips

  • Keep llm_knowledge concise and well-structured — the LLM works best with clear, organized information
  • Use bullet points and sections for readability
  • Include pricing, policies, common procedures, and product details
  • Update when your company's information changes — no bot restart required (config is read on startup)

Fallback Behavior

If the LLM request fails (network error, rate limit, invalid key), the message falls through to normal ticket handling: it gets forwarded to the staff chat as a regular ticket. The user won't see an error — they'll receive a human response instead.


Combining Keyword Rules and LLM

When both are configured, the bot checks in this order:

  1. Keyword autoreply rules → if matched, send canned answer immediately
  2. LLM auto-reply → if no keyword match and use_llm: true, generate AI response
  3. Normal ticket → if neither applies (or LLM fails), forward to staff group as a regular ticket

This means you can use keyword rules for exact, policy-critical answers (refund terms, legal disclaimers) while letting the LLM handle open-ended questions.

Clone this wiki locally