Create a new list

create_list()

Description

Enter the function in the "Calculator" field in the block settings:

create_list(name) - creates new list. The result is list ID.

Parameters:

! name - list name. The name is specified in single quotes.

Example

list_id = create_list("registered")

Creating a list from the block without duplicates

create_list_if_not_exist()

Description

create_list_if_not_exist('list_name') - creates a new list if one with the given name does not exist yet and returns its identifier, or returns the identifier of the existing list.

Required parameter:

list_name - name for a new list to be created.

Example

new_list = create_list_if_not_exist('List of participants')

Adding a client to the list

add_to_list()

Description

add_to_list(list_id, client_id) - adds a client to a list. The function returns none.

Parameters:

! list_id - list ID

client_id - MaviBot client ID. If not provided, the current client’s ID is used.

Moving a client to the list

move_to_list()

Description

move_to_list(list_id, client_id) - moves a client to the list (Important! The client is removed from all other lists and moved to the specified one). The result is a boolean value (True or False).

Parameters:

! list_id - list ID

client_id - MaviBot client ID. If not provided, the current client’s ID is used.

Removing a client from the list

remove_from_list()

Description

remove_from_list(list_id, client_id) - removes a client with the specified client_id from the list.

Parameters:

! list_id - list ID

client_id - MaviBot client ID. If not provided, the current client’s ID is used.

Deleting lists

remove_list_from_project(list_id, clear_list)

Description
! list_id - required parameter; the ID of the list to be deleted.

clear_list — optional parameter; accepts two values: True or False (default is False).

If you do not provide this parameter and the list contains clients, you will receive the following response:
"Can't delete list, list not empty"

If the list is empty, it will be deleted without issues. However, if you set clear_list to True, the list will be deleted regardless of whether it contains clients or not.

Deleting tags

remove_label_from_project(list_id, clear_list)

Description
! list_id - required parameter; the ID of the tag to be deleted.

clear_list - optional parameter; accepts two values: True or False (default is False).

If this parameter is not provided and the tag is assigned to clients, you will receive the following response:
"Can't delete list, list not empty"

If the tag is not assigned to any clients, it will be deleted without issues. However, if clear_list is set to True, the tag will be deleted regardless of whether it is assigned to clients or not.

Clear the client list

clear_list()

Description

clear_list(list_id) - clears the client list

Parameters:

! list_id - list ID. After use, all clients will be removed from the specified list.

Get the number of clients in the list

list_size()

Description

list_size(list_id) – counts the total number of clients in the list

Parameters:

! list_id- list ID

Count the number of unique client entries across multiple lists

lists_joint_count()

Description

lists_joint_count(massive_list) – counts the total number of unique client entries across multiple lists. The function takes an array of list IDs as input and returns a number.

Parameters:

! massive_list - an array containing the list IDs in which the unique client entries will be counted. The format is: ['list_id1', 'list_id2', ..., 'list_idN']

Code example for copying

/*Creating a list*/
list_id = create_list('New list')

/*Check if the client is in the list*/
k=inlist(list_id, client_id)

/*Get the size of the list — total number of clients in the list*/
razm=list_size(1)

/*Get the total number of unique client entries across multiple lists*/
k=lists_joint_count('[144636,144634]')

Check if a client is in the list

inlist()

Description

inlist(list_id,client_id) - checks if a client is in the list. The result is a boolean value (True or False).

Parameters:

! list_id - list ID

client_id - MaviBot client ID. If not provided, the current client’s ID is used.

Check if a chat participant is in a specific list

some_client_in_list()

Description

some_client_in_list(list_id, recepient)

Parameters:

! list_id - list ID;

! recepient - messenger user ID being checked (platform_id). For chats, the value of the variable is chat_member_id.

It returns values:

True - client is in the list;

False - client is not in the specified list.

Example

Code example for copying

/*Example of checking if a chat participant is in the list, where the first parameter is the list ID, and the second is the user's chat ID*/

r = some_client_in_list(123456, chat_member_id)

Retrieving elements from a list

count_occurrences()

Description

count_occurrences(array, element) - returns the number of specified elements contained in the list.

Parameters:

array - required parameter; list of elements

element - required parameter; element to count

Getting a random client ID from the list

random_list_member(list_id)

Description

random_list_member(list_id) - returns one random client ID in the specified list.

list_id - required parameter, list ID.

The list ID, which contains your clients, can be found in the "Lists" section:

Example of working with lists in the Calculator

Let's look at an example of using functions in the "Calculator" for working with lists.

Important! You need to save a new list ID in order to use it later. To do this, assign the function result to a variable, i.e. list_id = ...

Now you can easily perform other operations with the list — check if a client is in the list, add, move, or remove a client.

For example, let's check if a client is in the list with ID 12333:

It is very convenient to use lists when displaying statistical data:

It’s often necessary to get the total number of unique entries across a set of lists — this can easily be done using the lists_joint_count() function.

а

Get all client list IDs

get_all_client_label_ids(client_id)

Описание

get_all_client_list_ids(client_id) — returns an array containing the IDs of all lists the client belongs to.

If the client does not belong to any lists, the function returns an empty array: [].

Parameters:

  • client_id — the Mavibot client ID. If omitted, the ID of the current client is used.