Yes. Just edit the FAQ dictionary in the code and add your own questions and answers. The button keyboard updates from the same values.
Yes. Besides an exact button match, the bot also searches for the keyword inside the user’s sentence and sends the matching answer.
This sample version keeps answers in the code. For a professional version with an admin panel and database, the Filtor team can build a custom bot for you.
Yes. Just edit the FAQ dictionary in the code and add your own questions and answers. The button keyboard updates from the same values.
Yes. Besides an exact button match, the bot also searches for the keyword inside the user’s sentence and sends the matching answer.
This sample version keeps answers in the code. For a professional version with an admin panel and database, the Filtor team can build a custom bot for you.
Download the free source of a Telegram bot that automatically answers customers’ frequent questions with a button keyboard, with a full guide. Built in Python.
Yes. Just edit the FAQ dictionary in the code and add your own questions and answers. The button keyboard updates from the same values.
Yes. Besides an exact button match, the bot also searches for the keyword inside the user’s sentence and sends the matching answer.
This sample version keeps answers in the code. For a professional version with an admin panel and database, the Filtor team can build a custom bot for you.
A practical bot for businesses to reduce the load of repetitive support questions.
Yes. Just edit the FAQ dictionary in the code and add your own questions and answers. The button keyboard updates from the same values.
Yes. Besides an exact button match, the bot also searches for the keyword inside the user’s sentence and sends the matching answer.
This sample version keeps answers in the code. For a professional version with an admin panel and database, the Filtor team can build a custom bot for you.
Follow these steps in order to get the bot running on your system or server.
pip install requests.
Can I change the questions and answers?
Yes. Just edit the FAQ dictionary in the code and add your own questions and answers. The button keyboard updates from the same values.
Does it answer a keyword inside a sentence?
Yes. Besides an exact button match, the bot also searches for the keyword inside the user’s sentence and sends the matching answer.
Can this bot connect to a database or panel?
This sample version keeps answers in the code. For a professional version with an admin panel and database, the Filtor team can build a custom bot for you.
and KEYBOARD values with your own questions and answers.python bot.py, then test in Telegram.This is the same code as in the ZIP file. You can copy it right from here. Just remember to replace the TOKEN value with your own bot token.
# -*- coding: utf-8 -*-
# ------------------------------------------------------------
# Auto-reply
Can I change the questions and answers?
Yes. Just edit the FAQ dictionary in the code and add your own questions and answers. The button keyboard updates from the same values.
Does it answer a keyword inside a sentence?
Yes. Besides an exact button match, the bot also searches for the keyword inside the user’s sentence and sends the matching answer.
Can this bot connect to a database or panel?
This sample version keeps answers in the code. For a professional version with an admin panel and database, the Filtor team can build a custom bot for you.
Telegram bot
# Built by Filtor (filtori.com)
# ------------------------------------------------------------
# This bot is for businesses: instead of answering the same
# customer questions over and over, the bot sends ready answers.
# - shows a keyboard with buttons for frequent questions
# - sends a ready answer for each keyword you configure
#
# Note: a Telegram bot must run on a server that has access
# to api.telegram.org.
#
# Full guide:
# https://filtori.com/en/telegram-bot-source/faq-bot/
# Want a custom version for your business? +98 912 287 4862
# Our Telegram: https://t.me/filtori
# ------------------------------------------------------------
import time
import requests
# Bot token from @BotFather
TOKEN = "PASTE_YOUR_BOT_TOKEN_HERE"
BASE = f"https://api.telegram.org/bot{TOKEN}"
# ------------------------------------------------------------
# Configure the frequent questions and their answers here.
# key = button text (and what the user sends)
# value = the answer the bot gives
# ------------------------------------------------------------
Can I change the questions and answers?
Yes. Just edit the FAQ dictionary in the code and add your own questions and answers. The button keyboard updates from the same values.
Does it answer a keyword inside a sentence?
Yes. Besides an exact button match, the bot also searches for the keyword inside the user’s sentence and sends the matching answer.
Can this bot connect to a database or panel?
This sample version keeps answers in the code. For a professional version with an admin panel and database, the Filtor team can build a custom bot for you.
= {
"Working hours": "Our working hours are every day from 9 AM to 6 PM (except Fridays).",
"Prices": "To get the price list, please leave your phone number so our specialist can call you.",
"Address": "Our exact address and map route are available on our site: filtori.com",
"Support": "For support you can write your question right here or contact us.",
}
# The button texts shown to the user at the bottom of the screen
KEYBOARD = {
"keyboard": [
[{"text": "Working hours"}, {"text": "Prices"}],
[{"text": "Address"}, {"text": "Support"}],
],
"resize_keyboard": True,
}
def send_message(chat_id, text, reply_markup=None):
"""Send a message; with a keyboard if needed."""
url = f"{BASE}/sendMessage"
data = {"chat_id": chat_id, "text": text}
if reply_markup is not None:
data["reply_markup"] = reply_markup
try:
requests.post(url, json=data, timeout=15)
except requests.RequestException as error:
print("Error sending message:", error)
def get_updates(offset):
"""Fetch new messages using long polling."""
url = f"{BASE}/getUpdates"
params = {"offset": offset, "timeout": 30}
try:
return requests.get(url, params=params, timeout=40).json()
except requests.RequestException as error:
print("Error fetching messages:", error)
return {"ok": False, "result": []}
def answer(chat_id, text):
"""Core logic: decides which answer to give."""
if text == "/start":
send_message(
chat_id,
"Hi 👋 I am the auto-reply bot.\n"
"Tap one of the buttons below or type your question.",
reply_markup=KEYBOARD,
)
return
if text in
Can I change the questions and answers?
Yes. Just edit the FAQ dictionary in the code and add your own questions and answers. The button keyboard updates from the same values.
Does it answer a keyword inside a sentence?
Yes. Besides an exact button match, the bot also searches for the keyword inside the user’s sentence and sends the matching answer.
Can this bot connect to a database or panel?
This sample version keeps answers in the code. For a professional version with an admin panel and database, the Filtor team can build a custom bot for you.
:
send_message(chat_id,
Can I change the questions and answers?
Yes. Just edit the FAQ dictionary in the code and add your own questions and answers. The button keyboard updates from the same values.
Does it answer a keyword inside a sentence?
Yes. Besides an exact button match, the bot also searches for the keyword inside the user’s sentence and sends the matching answer.
Can this bot connect to a database or panel?
This sample version keeps answers in the code. For a professional version with an admin panel and database, the Filtor team can build a custom bot for you.
[text], reply_markup=KEYBOARD)
return
for keyword, reply in
Can I change the questions and answers?
Yes. Just edit the FAQ dictionary in the code and add your own questions and answers. The button keyboard updates from the same values.
Does it answer a keyword inside a sentence?
Yes. Besides an exact button match, the bot also searches for the keyword inside the user’s sentence and sends the matching answer.
Can this bot connect to a database or panel?
This sample version keeps answers in the code. For a professional version with an admin panel and database, the Filtor team can build a custom bot for you.
.items():
if keyword.lower() in text.lower():
send_message(chat_id, reply, reply_markup=KEYBOARD)
return
send_message(
chat_id,
"I did not understand your question 🤔 Pick one of the buttons below,\n"
"or contact us to talk to a specialist.",
reply_markup=KEYBOARD,
)
def main():
print("Filtor auto-reply bot is running... (Ctrl+C to stop)")
offset = 0
while True:
updates = get_updates(offset)
if not updates.get("ok"):
time.sleep(2)
continue
for update in updates.get("result", []):
offset = update["update_id"] + 1
message = update.get("message")
if not message:
continue
chat_id = message["chat"]["id"]
text = message.get("text", "")
if text:
answer(chat_id, text)
time.sleep(0.5)
if __name__ == "__main__":
main()
Yes. Just edit the FAQ dictionary in the code and add your own questions and answers. The button keyboard updates from the same values.
Yes. Besides an exact button match, the bot also searches for the keyword inside the user’s sentence and sends the matching answer.
This sample version keeps answers in the code. For a professional version with an admin panel and database, the Filtor team can build a custom bot for you.
Yes. Just edit the FAQ dictionary in the code and add your own questions and answers. The button keyboard updates from the same values.
Yes. Besides an exact button match, the bot also searches for the keyword inside the user’s sentence and sends the matching answer.
This sample version keeps answers in the code. For a professional version with an admin panel and database, the Filtor team can build a custom bot for you.
Yes. Just edit the FAQ dictionary in the code and add your own questions and answers. The button keyboard updates from the same values.
Yes. Besides an exact button match, the bot also searches for the keyword inside the user’s sentence and sends the matching answer.
This sample version keeps answers in the code. For a professional version with an admin panel and database, the Filtor team can build a custom bot for you.
The Filtor team builds a custom auto-reply Telegram bot with an admin panel and database so you can manage answers without touching the code.