Working with lists

Create a new list

create_list()

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.

Creating a list from the block without duplicates

create_list_if_not_exist()

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.

Adding a client to the list

add_to_list()

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()

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()

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)

! 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)

! 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()

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()

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()

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']

Check if a client is in the list

inlist()

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()

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.

Retrieving elements from a list

count_occurrences()

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)

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

example

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.

а

Last updated