About Telegram Group Bots
ConnectiveOne allows creating bots that can listen and respond in Telegram groups. This allows automating work in groups, processing commands, and forwarding messages to operators.
Context and Problem
In many cases, you need automation in Telegram groups:
- Bot that executes commands in groups (
/command@mybot) - Bot that recognizes mentions to itself (
@mybot pay attention) - Bot that listens to all messages in the group and forwards them to operators
Group bots solve this task by allowing automating work and providing operator support in groups.
Key Concepts
Types of Group Bots
Command bot:
- Responds to commands like
/command@mybot - Executes specific actions by commands
- Uses action for command processing
Mention bot:
- Recognizes mentions to itself through
@mybot - Can save information or forward to operators
- Uses text message checking
Listener bot:
- Listens to all messages in the group
- Forwards messages to operator panel
- Allows operators to respond on behalf of the bot
Group Privacy Settings
For a bot to listen to all messages in a group, you need to disable "Group Privacy" in BotFather:
- Open BotFather
- Select bot
- "Bot Settings" → "Group Privacy"
- Disable "Group Privacy"
Approach Options
Commands vs Mentions vs Listener
Commands:
- ✅ Pros: Clear structure, easy to process
- ❌ Cons: Limited flexibility
Mentions:
- ✅ Pros: More natural interaction
- ❌ Cons: Requires text processing
Listener:
- ✅ Pros: Full control, operator support possibility
- ❌ Cons: Requires Group Privacy configuration
Why we use different approaches: Each approach suits different usage scenarios and client needs.
Adopted Solutions
Using Action for Processing
For processing commands and mentions, Action blocks are used that:
- Analyze message text
- Determine command type or mention
- Return events for scenario transition
Forwarding to Operator Panel
For forwarding messages to the operator panel, action operator_panel__connect_to_operator_with_msg is used, which allows:
- Creating chat in operator panel
- Forwarding message and user data
- Allowing operator to respond on behalf of the bot
Implications for Users and Implementation
For Integrators
When creating group bots, it's important to:
- Configure Group Privacy — for listener bots, disable Group Privacy in BotFather
- Create Action for processing — for commands and mentions
- Configure forwarding to operator panel — if operator support is needed
- Handle different message types — text, media, commands
Common Errors
Error: Bot does not respond to commands
Problem: Commands are not configured in BotFather or incorrect Action processing
Solution: Check command settings and Action processing
Error: Bot does not see messages in group
Problem: Group Privacy is not disabled
Solution: Disable Group Privacy in BotFather
Error: Operator cannot respond on behalf of bot
Problem: Forwarding to operator panel is not configured
Solution: Use operator_panel__connect_to_operator_with_msg to create chat
Usage Examples
Command Processing
const action_handle_command = function() {
const j = this.getCurrentStateJSON();
const command = j.user_request?.text || '';
if (command === '/start@mybot') {
return 'start';
} else if (command === '/help@mybot') {
return 'help';
}
return 'unknown';
};
Mention Check
const action_check_mention = function() {
const j = this.getCurrentStateJSON();
const message = j.user_request?.text || '';
const bot_username = 'mybot';
if (message.includes(`@${bot_username}`)) {
return 'mentioned';
}
return 'not_mentioned';
};
Related Documents
- Reference: Telegram Bot API Documentation — official Telegram documentation about bots
- Explanation: Connecting Chat with Operator — forwarding messages to operator panel