Mandatory Force-Subscribe System

Raw MD
Protect bot features by requiring users to join your official Telegram channel or group before proceeding.

How Force-Subscribe Works

  1. Add your bot as an Administrator in your official channel or group.
  2. When a user sends /start, call getChatMember with your channel ID and the user's ID.
  3. Inspect the returned status. If status is left or kicked, 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');
}