Systems Library / Customer Service / How to Create a Telegram Customer Service Bot
Customer Service chatbots

How to Create a Telegram Customer Service Bot

Deploy a Telegram bot for automated customer support and engagement.

Jay Banlasan

Jay Banlasan

The AI Systems Guy

A telegram customer service bot with ai automated responses is the easiest platform bot to build. Telegram's Bot API is simple, well-documented, and has no approval process. I use these for communities, info products, and businesses where the audience lives on Telegram.

You can have a working bot in under an hour. No Meta business verification. No webhook approval delays.

What You Need Before Starting

Step 1: Create Your Bot with BotFather

Open Telegram, search for @BotFather, and send /newbot. Follow the prompts:

You: /newbot
BotFather: Choose a name for your bot.
You: My Business Support
BotFather: Choose a username.
You: mybusiness_support_bot
BotFather: Done! Your token is: 123456:ABCdefGHIjklMNOpqrsTUVwxyz

Save that token. It is your bot's API key.

Step 2: Build the Bot Handler

from telegram import Update
from telegram.ext import Application, CommandHandler, MessageHandler, filters
import anthropic
import os

ai_client = anthropic.Anthropic()

SYSTEM_PROMPT = """You are a support bot for [Your Business] on Telegram.
Answer questions from the knowledge base below.
Keep responses concise and formatted for Telegram (use bold with *text* and line breaks).
If you cannot answer, say: "Let me get a team member to help. Please hold."

KNOWLEDGE BASE:
[Your FAQ content]"""

async def handle_message(update: Update, context):
    user_text = update.message.text
    user_id = update.effective_user.id

    response = ai_client.messages.create(
        model="claude-sonnet-4-20250514",
        max_tokens=400,
        system=SYSTEM_PROMPT,
        messages=[{"role": "user", "content": user_text}]
    )

    await update.message.reply_text(response.content[0].text)

async def start(update: Update, context):
    await update.message.reply_text(
        "Welcome! I can help with:\n"
        "- Product questions\n"
        "- Order status\n"
        "- Returns and refunds\n\n"
        "Just type your question and I will find the answer."
    )

def main():
    app = Application.builder().token(os.getenv("TELEGRAM_BOT_TOKEN")).build()
    app.add_handler(CommandHandler("start", start))
    app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_message))
    app.run_polling()

if __name__ == "__main__":
    main()

Step 3: Add Conversation Memory

Track conversations per user:

from collections import defaultdict

user_histories = defaultdict(list)

async def handle_message(update: Update, context):
    user_id = update.effective_user.id
    text = update.message.text

    user_histories[user_id].append({"role": "user", "content": text})

    response = ai_client.messages.create(
        model="claude-sonnet-4-20250514",
        max_tokens=400,
        system=SYSTEM_PROMPT,
        messages=user_histories[user_id][-10:]
    )

    reply = response.content[0].text
    user_histories[user_id].append({"role": "assistant", "content": reply})
    await update.message.reply_text(reply)

Step 4: Add Inline Buttons for Common Actions

Telegram supports inline keyboards for structured navigation:

from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import CallbackQueryHandler

async def start(update: Update, context):
    keyboard = [
        [InlineKeyboardButton("Product Info", callback_data="products")],
        [InlineKeyboardButton("Order Status", callback_data="orders")],
        [InlineKeyboardButton("Talk to Human", callback_data="human")],
    ]
    reply_markup = InlineKeyboardMarkup(keyboard)
    await update.message.reply_text("How can I help?", reply_markup=reply_markup)

async def button_handler(update: Update, context):
    query = update.callback_query
    await query.answer()
    if query.data == "human":
        await query.edit_message_text("A team member will be with you shortly.")
        notify_support_team(query.from_user.id)

Step 5: Deploy as a Background Service

Run the bot as a systemd service on your server:

# /etc/systemd/system/support-bot.service
[Unit]
Description=Telegram Support Bot
After=network.target

[Service]
User=root
WorkingDir=/root/bots/support-bot
ExecStart=/usr/bin/python3 bot.py
Restart=always

[Install]
WantedBy=multi-user.target

What to Build Next

Add group moderation. If your business runs a Telegram community, the same bot can moderate messages, answer FAQs in the group, and DM users who need private support.

Related Reading

Want this system built for your business?

Get a free assessment. We will map every system your business needs and show you the ROI.

Get Your Free Assessment

Related Systems