Bots.Business - Help
  • Welcome
  • Getting started
  • Create bot from Google Table
  • App
    • Reset or Update Your Password
  • Commands
    • Answer
    • Aliases
    • Keyboard
    • Groups
    • Wait for answer
    • Auto Retry (AR)
  • Coding: BJS
    • Variables
    • Bot functions
    • Message broadcasting and editing
    • User functions
    • Properties
    • Always running commands
    • Error command: "!"
    • Lists
      • Migration from properties to list
    • Api functions
    • BB Admin functions
    • Admin Panel
    • Send HTTP request
    • Web App
    • Caching
    • Inline Bot
    • BJS Security
    • Good coding practices
    • Top errors
  • Git
    • Import bot from Git repository
    • Export bot to Git repository
    • Repository structure
    • File: bot.json
    • Automatic importing on Git push
  • Iterations. How to reduce theys?
  • Limitations
  • Cloud
  • Reports
  • Deep Linking - pass any params on Bot starting
  • How to link chat account with BB account?
  • BB Inspection
  • Protected bot
  • VS Code
  • How to...
  • Smart Bot
    • Overview
    • Lang File
    • SmartBot
    • SmartTasker
    • Amount Dialog
  • Libs
    • What it is - Libs?
    • Libs development
    • RefferalLib
    • ResourcesLib
    • Random
    • MembershipChecker (MCL)
    • Cooldown Lib
    • CurrencyConverter
    • Lang
    • TopBoardLib
    • QiwiPayments
    • Coinbase (CB)
    • CoinPayments (CP)
    • OxaPay
    • CryptoJS
    • CurrencyQuote
    • GoogleApp
    • GoogleTableSync
    • Guard
    • Webhooks lib
    • DateTimeFormat Lib
  • Store
    • BB Point Bot
    • Welcome bot
    • Help bot
    • SRB Demo Keyboard Tools
Powered by GitBook
On this page
  • Initial setup
  • Setup
  • Callbacks
  • Command /onNeedJoining
  • Command /onJoining:
  • Command /onAllJoining:
  • Command /onStillJoined
  • Limited bot access
  • Check button
  • All methods

Was this helpful?

  1. Libs

MembershipChecker (MCL)

This library is used to verify user membership in other channels and chats. It is also know as MCLib (MCL)

PreviousRandomNextCooldown Lib

Last updated 1 year ago

Was this helpful?

We have demo bots for MCLib in the Store - and

It is recommended to use this library, since it allows you to make the bot work faster.

Verification methods run in the background so the user does not need to wait for a response from the bot.

Initial setup

Install Library and create /setup command:

Libs.MembershipChecker.setup()

Then go to App > Bot > Admin Panels and fill options:

Please note:

  • Small checking delay is not good for iterations

  • One chat (or one channel) require 1 iteration per check

  • you can turn on "debug info" checkbox for bug searching

Setup

Callbacks

You need to define commands in the admin panel. You can define only those commands that you need.

Callback command
Description

onNeedJoining

user still need to join to any resource

onNeedAllJoining

user still need to join to all resource

onJoining

user just joined to any resource

onAllJoining

user just joined to all resources

onStillJoined

user is still joined to all resources

onError

error callback

in @ command:

// for automatic checking
// with checking delay from admin panel

if(chat?.chat_type == "private"){
    // we check joining only in private chat
    Libs.MembershipChecker.handle();
}

This method can have much more iterations usage.

You can increase checking delay time for hour and etc for decreasing iterations usage.

Also you can use it only on /start - but user can leave your channel after joining and bot starting. With @ command it is permanent checking.

We use (chat?.chat_type == "private") because in group chat (usually) joining checking is not needed.

Command /onNeedJoining

Bot.sendMessage(
  "You still need to join: " + options.chat_id
)

// you can access for passed data:
// Bot.inspect(options.bb_option)

This callback will be executed if the user has not yet joined or has left after handle() or check() methods

This callback will be executed per each channel or chat. For example, if you have 5 not joined chats you will have 5 callbacks

Command /onJoining:

if(!options){ return } // protect from manual run
Bot.sendMessage("Thank you for joining to" + options.chat_id);

// you can access for passed data:
// Bot.inspect(options.bb_option)

This callback will be executed if the user just joined after after handle() or check() methods

This callback will be executed if the user just joined to any channel

Command /onAllJoining:

if(!options){ return } // protect from manual run
Bot.sendMessage("Thank you for joining!");

// you can access for passed data:
// Bot.inspect(options.bb_option)

This callback will be executed if the user just joined after after handle() or check() methods

This callback will be executed once if the user has joined all channels

Command /onStillJoined

Bot.sendMessage(
  "You still have membership in our groups. Thank!"
)

This callback will be executed if the user still joined to all channels and chats after check() method only.

Limited bot access

// for all chats and channels:
let isMember = Libs.MembershipChecker.isMember();

// for one chat / channel:
// isMember = Libs.MembershipChecker.isMember("@chatName")

// we need this commands because user always need
// to /start bot and make "/check" command
const skipCommands = [
   "/start",
   "Check", "/check",
    //  "/setup"   // it is also can be
];

const canRunBot = isMember || skipCommands.includes(message);

if(!canRunBot){
  let channels = Libs.MembershipChecker.getChats();
  Bot.sendMessage("Please join to our channels " + channels)
  return // return from bot execution
}

Check button

You can also perform manual check if you need something like "check" button.

Example for /check command:

// for all chats and channels:
// this method perform checking without delay
// but not more often than once every 2 seconds
Libs.MembershipChecker.check()

// also you can pass any data for callbacks:
// Libs.MembershipChecker.check({ any: "data", here: "for callbacks"  })

User can press button many times. So we can restrict this and save iterations

All methods

Method
Description
Background

setup()

Install Admin Panel for Lib

check(options)

Force check memberships.

You can pass any data in options for callbacks (onJoining, onNeedJoining, onNeedAllJoining, onStillJoined)

+

handle(options)

+

isMember(chat_id)

Returns true if the user has joined all resources. chat_id - can be null (it will be all chats) Before you need to execute handle() or check()

getChats()

Returns all resources (group chats, channels) specified in the Admin Panel

getNotJoinedChats()

Returns all resources (group chats, channels) specified in the panel that the user has not yet joined

All background methods require additional iterations.

command

If membership is required to use the bot you can use command: @

It is good to use here

Soft check memberships with delay (you can setup delay in Admin Panel). Use this method in @ command You can pass any data in options for callbacks (onJoining and onNeedJoining)

Before all
before all
Cooldown Lib
BBJoinBot
BBChannelPromotionBot
before all