Mandatory Force-Subscribe System
Protect bot features by requiring users to join your official Telegram channel or group before proceeding.
How Force-Subscribe Works
- Add your bot as an Administrator in your official channel or group.
- When a user sends
/start, callgetChatMemberwith your channel ID and the user's ID. - Inspect the returned
status. If status isleftorkicked, block access and present a Join Channel button with a "Check Membership" callback.
Force-Subscribe Implementation
function is_subscribed(string|int $userId, string|int $channelId): bool {
$res = bot('getChatMember', [
'chat_id' => $channelId,
'user_id' => $userId
]);
if (empty($res['ok'])) return false;
$status = $res['result']['status'] ?? '';
return in_array($status, ['creator', 'administrator', 'member', 'restricted'], true);
}
// In your webhook handler:
define('REQUIRED_CHANNEL', '@BotlifyOfficial');
if (!is_subscribed($chatId, REQUIRED_CHANNEL)) {
bot('sendMessage', [
'chat_id' => $chatId,
'text' => "⚠️ Access Restricted!
You must join our official channel to use this bot.",
'parse_mode' => 'HTML',
'reply_markup' => [
'inline_keyboard' => [
[['text' => '📢 Join Channel', 'url' => 'https://t.me/BotlifyOfficial']],
[['text' => '🔄 Verify Membership', 'callback_data' => 'check_sub']]
]
]
]);
exit('ok');
}