Chatbot Integration with Telegram Bot
This guide will walk you through the process of integrating our chatbot with the Telegram Bot API. After completing all the steps, your users will be able to communicate with the chatbot directly through the Telegram application. The guide also covers configuring special commands for the bot.
Table of Contents
Select Your Starting Point
Starting from Scratch
I don't have a Telegram bot yet and need to go through the entire integration process
I Already Have a Telegram Bot
I already have a bot created and need to configure it with the AI chatbot
I Have a Configured Chatbot
The chatbot is working and I want to add special commands or optimize settings
Integration Process Overview
Integrating a chatbot with Telegram Bot is a process that consists of several main stages:
- Creating a bot in Telegram - creating a new bot using BotFather and obtaining an access token.
- Configuring the chatbot on the platform - creating a new chatbot with Telegram Bot functionality, entering the token, and automatic webhook configuration.
- Managing commands - configuring special commands for the bot that will be available in the Telegram menu.
- Testing and optimization - verifying the bot's operation and adjusting settings.
- The Telegram application on your phone or computer
- An account on the ChatbotAssistant platform with an active subscription
- Basic knowledge of how Telegram works (optional)
Creating a Bot in Telegram via BotFather
The first step is to create a new bot in Telegram through the official BotFather. BotFather is a special Telegram bot used to manage all bots on the platform.
The official bot for managing Telegram bots
Detailed instructions:
- Open the Telegram application on your phone or computer.
- Search for BotFather - in the search field, type @BotFather and select the official bot (it will have a blue verification icon).
- Start a conversation with BotFather by clicking the "Start" button or sending the /start command.
- Create a new bot by sending the command:
/newbotCommand to create a new bot
- Provide a bot name - BotFather will ask you to provide a name for the bot. The name can contain spaces and special characters. Examples:
Example names: - Shop Assistant - World Flavors Restaurant Bot - Customer Service Center
- Provide a bot username - next, you need to provide a unique username for the bot. The username must:
- End with the word "bot" (e.g. myshopbot or my_restaurant_bot)
- Be unique across the entire Telegram system
- Contain only letters, numbers, and underscores
- Be between 5 and 32 characters long
Example usernames: - myshopbot - restaurant_flavors_bot - techsupport_assistant_bot - Copy the bot token - After successfully creating the bot, BotFather will send you a message containing the access token. The token looks similar to this:
1234567890:AAEhDOM50CUBO9QIugrsgHP2g61FE15LAVwbdbIx
Common issues at this stage:
If the entered username is already taken, try the following solutions:
- Add numbers at the end (e.g. myshopbot2024)
- Add an additional word describing the industry (e.g. myshopfurniturebot)
- Use underscores to separate words (e.g. my_shop_bot)
- Add a location (e.g. myshoplondonbot)
If BotFather does not respond to your commands:
- Make sure you are writing to the official @BotFather (with the blue verification icon)
- Check that the command starts with the / (slash) character
- Try sending the /start command to restart the conversation
- Check your internet connection and try again
Configuring the Chatbot on the ChatbotAssistant Platform
Now configure the chatbot in our system to connect it with your Telegram bot and give it AI intelligence.
Detailed configuration instructions:
- Go to the chatbot form - Log in to your account on the ChatbotAssistant platform and navigate to the dashboard.
- Start creating a new chatbot - Click the "Create New Chatbot" button.
- Select the Telegram Bot functionality - In the "Select chatbot functionality" section, check the "Telegram Bot" option.
- Fill in the basic configuration:
- Chatbot name - enter a name that will be used internally on our platform (e.g. "Telegram Bot - Clothing Store")
- Short description - optionally add a short description of the chatbot to help you identify it
- Enter company information: This is the most important part of the configuration - the more detailed information you provide, the better the chatbot will respond to user questions.
- Company name - the full name of your company
- Location - company address, opening hours, parking information, etc.
- Product/service offering - a detailed description of what you offer along with prices
- Business description - information about the company, specialties, delivery conditions, payment methods, warranties
- Telegram Bot configuration:
- Telegram Bot Token - paste the token received from BotFather in the previous step
- Save the chatbot - After filling in all fields, click the "Create Chatbot" button.
Automatic webhook configuration:
After entering a valid bot token and saving the configuration, our system will automatically configure the webhook that enables communication between Telegram and your AI chatbot.
What happens automatically after saving the chatbot:
- 🔗 Webhook URL configuration - the system automatically sets the correct webhook address in the Telegram API
- 🔐 Security secret generation - automatic generation and configuration of a secure authentication token
- ⚙️ Settings optimization - configuration of only necessary update types (text messages)
- 🧹 Queue cleanup - removal of unprocessed updates from previous configurations
Managing Telegram Commands
Telegram commands are special instructions that users can send to the bot. They provide quick access to specific functions and information. Our platform enables easy command management through a web interface.
Accessing command management:
- In the dashboard, find your Telegram chatbot and click Options then "Telegram Commands".
- You will be redirected to the command management panel.
Adding a new command:
- In the commands panel, click the "Add Command" button.
- Fill in the command form:
Command configuration - field details:
Format: Enter the name without the "/" character (the slash will be added automatically)
Rules:
- Only letters, numbers, and underscores
- Length from 1 to 32 characters
- No spaces or special characters
Examples of valid names:
An optional description displayed in the command list in the Telegram application. It helps users understand what the command is for.
Description examples:
The content of the message that the bot will send in response to the command. You can use variables to personalize responses.
Available variables:
- {user_name} - User's first and last name
- {user_id} - Telegram user ID
- {username} - Username (@username)
- {chat_id} - Chat ID
Example response using variables:
Examples of useful commands:
Managing existing commands:
In the commands panel, you can:
- Edit commands - Click on a command to change its name, description, or response
- Delete commands - Remove unused or unnecessary commands
- Monitor usage - View statistics showing which commands are used most often
Testing the Integration
After configuring all the necessary elements, it's time to test the integration and make sure the chatbot works as expected.
Detailed testing instructions:
- Find your bot in Telegram:
- Open the Telegram application
- In the search field, enter your bot's username (e.g. @myshopbot)
- Click on the bot from the results list
- Start communicating with the bot:
- Click the "Start" button or send the /start command
- The bot should respond with the welcome message configured in the settings
- Testing AI communication:
- Send a simple test message, e.g. "Hello" or "Hi"
- The bot should respond according to the AI configuration and company information
- Ask a question related to your business to check if the bot provides accurate answers
- Testing special commands:
- Send the /help command (if it was configured)
- Test all the commands you added in the previous step
- Check that the responses contain correctly substituted variables (e.g. user name)
- Test the commands menu:
- Click the menu icon (/) in the message input field
- Check that your commands are visible in the list
- Click on a command from the menu to make sure it works correctly
Advanced testing:
Test the bot with different types of questions:
- Product/service questions: "What products do you have?", "How much does ... cost?"
- Hours questions: "When are you open?", "What are your working hours?"
- Location questions: "Where are you located?", "What is the address?"
- Contact questions: "How can I contact you?"
- Out-of-scope questions: Check how the bot reacts to questions outside its scope
Check how the bot handles intensive communication:
- Send several messages quickly one after another
- Test long messages (several hundred characters)
- Check response time at different hours
- Verify rate limiting behavior (if the limit is reached, the bot will inform about the need to wait)
Check the bot's operation on different platforms:
- Mobile app: Telegram on Android/iOS
- Desktop app: Telegram on Windows/Mac/Linux
- Web version: Telegram Web (web.telegram.org)
The bot should work identically on all platforms.
Monitoring and analyzing chatbot performance:
After launching the chatbot, it's important to monitor its performance and analyze user interactions:
Our platform offers comprehensive analytical tools:
- General statistics: Total number of queries and sessions, average conversation length, average response time
- User activity: Interactive charts with traffic distribution by day of the week and hour
- User behavior: Session length and return rate
- Popular topics analysis: Top 5 most discussed topics
- Command statistics: Which commands are used most often
- Optimization suggestions: Automatically generated recommendations
- Log in to the chatbot administration panel
- Go to the "Dashboard" section
- Select your Telegram bot and click the "Analytics" button
- Browse detailed data and usage statistics
Advanced Bot Settings (Optional)
After the basic configuration, you can further customize your Telegram bot using additional features available in BotFather.
Optional settings in BotFather:
To set the bot description and profile picture:
- Open a conversation with @BotFather
- Use the /setdescription command to set the bot description
- Select your bot from the list
- Enter the description that will be visible on the bot's profile
To add a profile picture:
- Use the /setuserpic command
- Select your bot
- Upload the image that should be the bot's avatar
You can set up a list of commands in the Telegram menu:
- Use the /setcommands command in BotFather
- Select your bot
- Enter the list of commands in the following format:
Important: Commands set in BotFather will be visible in the menu, but their functionality is controlled by the commands configured on our platform.
You can configure the bot's privacy settings:
- Use the /setprivacy command in BotFather
- Select your bot
- Choose the appropriate setting:
- Disable: The bot will receive all messages in groups
- Enable: The bot will only receive messages starting with "/" or directly addressed to it
You can assign a custom domain to your bot:
- Use the /setdomain command in BotFather
- Select your bot
- Enter the domain in the format: example.com
After setting the domain, users will be able to find your bot at: https://t.me/example.com
Rate Limiting
Rate limiting is a mechanism that restricts the number of messages a user can send to the chatbot within a specified time period. It protects the system from excessive load and ensures fair use of resources.
How Rate Limiting works:
- Per-user limit: Each user has their own limit (not shared with others)
- Time window: 60 seconds
- Automatic reset: The counter resets every minute
- Configurable limit: Each user can have a different limit set by the administrator
What this means for users:
When a user reaches their message limit within a minute, the chatbot will display a message informing them of the need to wait before sending another message. After one minute from the first message in the given time window, the counter automatically resets.
Increasing rate limits:
If the standard rate limits are not sufficient for your use case (e.g. for high-traffic chatbots or specialized applications), you can request an increase.
Troubleshooting
Despite carefully following all integration steps, problems with the chatbot's operation may sometimes occur. This section presents solutions to the most common issues.
Common issues and their solutions:
Possible causes:
- The Bot Token is invalid or has expired
- The webhook is not properly configured
- The bot is already being used by another system
- Subscription issues on the platform
- Temporary network problems
Solution:
- Check the bot token - make sure it was correctly copied from BotFather
- Verify the subscription status on the ChatbotAssistant platform
- Check for error messages in the chatbot administration panel
- Try generating a new token in BotFather and update it in the configuration
- Make sure the bot is not being used by other systems
Possible causes:
- The Bot Token is invalid
- The bot was deleted from BotFather
- Issues with automatic webhook configuration
Solution:
- Check if the bot still exists - search for it in Telegram
- Make sure the token has not been changed or reset
- Go to the chatbot configuration and save it again to trigger a webhook reconfiguration
- If the problem persists, delete the chatbot and create it from scratch
Possible causes:
- Insufficient or imprecise company information
- Lack of context for specific industry questions
- Issues with AI language understanding
Solution:
- Expand and refine the company information in the chatbot configuration
- Add more details about products, services, and business processes
- Add frequently asked questions with answers to the company description
- Create dedicated commands for the most important information
- Monitor conversations and systematically improve the configuration based on actual user questions
Possible causes:
- Commands were not properly configured on the platform
- The commands menu in BotFather was not set up or is inconsistent
- Errors in command name syntax
Solution:
- Check the command configuration in the ChatbotAssistant panel
- Make sure that command names contain only allowed characters
- Synchronize the commands menu in BotFather with the commands on the platform
- Test commands by typing them manually (e.g. /help)
- Check that the commands have properly configured responses
Possible causes:
- High AI system load
- Complex questions requiring longer processing
- Rate limiting thresholds reached
- Network connection issues
Solution:
- Check if you have reached the rate limiting thresholds
- Wait a moment and try again - temporary delays are normal
- If the problem persists, contact our support team
- Consider optimizing your questions - shorter, more specific questions are processed faster
You can independently check the webhook configuration status of your bot:
Replace YOUR_BOT_TOKEN with your bot's actual token. This call will return information about the current webhook configuration, including:
- Webhook URL
- Connection status
- Recent errors (if any)
- Number of pending updates