Chat Join Requests & Auto-Approval
Automatically approve or decline private channel and group join requests with instant welcome direct messages.
The chat_join_request Update
When users request to join private channels or invite-only groups, Telegram sends a chat_join_request update to your bot rather than a regular message.
Handling chat_join_request
// Detect and Process Join Requests
if (isset($update['chat_join_request'])) {
$req = $update['chat_join_request'];
$chatId = $req['chat']['id'];
$userId = $req['from']['id'];
$userName = htmlspecialchars($req['from']['first_name'] ?? 'Friend', ENT_QUOTES, 'UTF-8');
// 1. Instantly Approve the Join Request
bot('approveChatJoinRequest', [
'chat_id' => $chatId,
'user_id' => $userId
]);
// 2. Send Personalized Welcome Direct Message
bot('sendMessage', [
'chat_id' => $userId,
'text' => "🎉 Welcome {$userName}!
Your request to join our channel has been automatically approved.",
'parse_mode' => 'HTML',
'reply_markup' => [
'inline_keyboard' => [
[['text' => '🚀 Launch Bot Dashboard', 'url' => 'https://t.me/' . BOT_USERNAME]]
]
]
]);
exit('ok');
}
Decline Join Requests
If a user is banned or does not meet membership conditions, you can call declineChatJoinRequest:
declineChatJoinRequest
bot('declineChatJoinRequest', [
'chat_id' => $chatId,
'user_id' => $userId
]);