# Calculator functions for courses

## Registration for the course

register\_customer\_on\_course(tariff\_id, email, email\_notification, period, reregistration)

<table><thead><tr><th width="239.15234375">Parameters</th><th></th></tr></thead><tbody><tr><td><strong>!</strong> <strong>tariff_id</strong></td><td>required parameter, the ID of the pricing plan id. You can copy it in the browser line in the pricing plan settings.</td></tr><tr><td><strong>! email</strong></td><td>required parameter, the client's email address. You can specify a specific value or variable in which the client's email is recorded.</td></tr><tr><td><strong>email_notification</strong></td><td>optional parameter, sends the student an email message about his registration for the course, if it is enabled.</td></tr><tr><td><strong>period</strong> </td><td><p>optional parameter, time limit for the validity of the pricing plan. Date formats are supported as follows: %d.%m.%Y %H:%M или %d.%m.%Y Example:</p><p><code>period = '15.08.2023 11:00'</code></p></td></tr><tr><td>reregistration</td><td>optional parameter, with values True or False. This parameter is optional and is specified if you need to register students again for the same course and pricing plan.</td></tr><tr><td>purchase_price</td><td>optional parameter. Allows you to specify the course cost if the client paid for access to it through a bot. If you do not specify it, the cost of the specified pricing plan will be used. It will be useful if the client pays for access to the course through the bot at a different price than the cost of the specified pricing plan.</td></tr></tbody></table>

Example: register\_customer\_on\_course(123, email, 1, "", True)

{% hint style="info" %}
In order for clients to receive emails, pass 1 to the parameter **email\_notification.**

**If you do not send 1, then the client's emails will not be received!**
{% endhint %}

## How can I grant access to the course through the Telegram Web App?

To do this, specify the function in the Block Calculator

**`access_course_from_webapp(text, button_label)`**\
During using the function, the student logs in to Telegram and gets access to the course. For further training, the student does not need to enter a username and password, as the authorization has already been completed.

Function Parameters:

**`text`** - is the text of the message that the client will receive. The parameter can be specified in a variable by writing it in the Calculator field before accessing the function, or specified in the function itself in quotation marks.

**`button_label`** - is the text on the Web App button. You can specify the parameter either in a variable or in the function itself. In the second case, the parameter is written in quotation marks.

{% hint style="warning" %} <mark style="color:red;">It is relevant ONLY for working with a Telegram bot.</mark>
{% endhint %}

The screenshot below shows an example of using the function.\
In the first step, we register the client for the course, then use the access\_course\_com\_webapp function to provide access to the online product. &#x20;

The result of the function execution:

<div data-with-frame="true"><figure><img src="/files/pwP3A5l4Xbjprmq6fNmp" alt="" width="375"><figcaption></figcaption></figure></div>

This button opens a page with the courses/rates that the student has.

> If the client is not associated with the student's account, the function returns 'client not attached to customer'.
>
> To create such a connection, you just need to enroll in a course through a bot.

<div data-with-frame="true"><figure><img src="/files/YUND5i0C3FWDVRDOazLf" alt="" width="563"><figcaption></figcaption></figure></div>

## How to grant access to the course via a bot

### register\_customer\_on\_course()

To do this, specify the function in the Block Calculator

**register\_customer\_on\_course(tariff\_id, email, email\_notification, period)**

| Required parameters                                                                                                                                                      | Optional parameters                                                                                                                                                                                               |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <mark style="color:red;">**!**</mark> **tariff\_id** - the ID of the pricing plan ID. You can copy it in the browser line in the pricing plan settings.                  | **email\_notification** - This parameter sends the student an Email message about his registration for the course, if it is enabled.                                                                              |
| <mark style="color:red;">**!**</mark>**&#x20;email** - the client's email address. You can specify a specific value or variable in which the client's email is recorded. | <p><strong>period</strong> - time limit on the validity of the pricing plan. Date formats are supported as follows:  %d.%m.%Y %H:%M или %d.%m.%Y <br>Example:</p><p> <code>period = '15.08.2023 11:00'</code></p> |

{% hint style="danger" %}
In order for clients to receive emails, you must pass 1 in the parameter **email\_notification.**&#x20;

**If you** <mark style="color:red;">do not send 1,</mark> **then the client's emails&#x20;**<mark style="color:red;">**will not be received!**</mark>
{% endhint %}

Assign a function to the variable.&#x20;

After execution, one of the responses will be written in the variable:

**customer is already on tariff** - if there is a pricing plan or access is manually closed

**wrong\_tariff\_id** - invalid id is specified

**tariff\_added** - Pricing plan was added to the student

Example:

<div data-with-frame="true"><figure><img src="/files/ec0O9mWvVdzc9dTE4qVh" alt="" width="563"><figcaption></figcaption></figure></div>

## How to check the availability of access to the course

### has\_customer\_tariff(tariff\_id)

To do this, specify the function in the Block Calculator **has\_customer\_tariff(tariff\_id, email)**<br>

| Required parameters                                                                                                                                                                     | Optional parameters                                                                                                                         |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| <mark style="color:red;">**!**</mark> **tariff\_id** - the ID of the pricing plan id. You can copy it in the browser line in the pricing plan settings or in the Pricing plans section. | **email** - optional parameter. Pass this parameter to check whether the client is enrolled in the course with the specified email address. |

After execution, the function returns True or False.

{% hint style="danger" %}
Possible function responses in case of errors:

**wrong tariff\_id** -  invalid value passed **tariff\_id**

**customer not found** - the user is not registered as a student.
{% endhint %}

## How to register a client on the platform WITHOUT granting access to the course

### register\_customer(email)

To do this, specify the function in the Block Calculator **register\_customer(email)**&#x20;

| Function Parameters                             | Description                 |
| ----------------------------------------------- | --------------------------- |
| <mark style="color:red;">**!**</mark> **email** | the client's email address. |

You can specify a variable in a function or parameter values. To specify a variable, write its name, without quotation marks and syntax marks, grids and curly braces. To specify a specific value, specify the client's email address in quotation marks.

> It is recommended to assign a variable to the function, so you can see the result of the function and work with it. Example in the screenshot below: the variable name is set before the equal sign, followed by the function and parameter in parentheses.

After successful execution of the function, the response will be written in the variable:\
**customer created**

## How to check course access and time limits?

To do this, specify the function in the Block Calculator **has\_customer\_tariff\_with\_date(tariff\_id, email),** to check the availability of access to the course by email (returns a detailed response about the availability of access and time restrictions).

&#x20;Function Parameters:

| Required parameter                                                                                                                                                                      | Optional parameter              |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- |
| <mark style="color:red;">**!**</mark> **tariff\_id** - the ID of the pricing plan id. You can copy it in the browser line in the pricing plan settings or in the Pricing plans section. | **email** - optional parameter. |

The answer will be:

* the student is enrolled and there is a time limit on access: Has access until 2023-09-28 22:00:00&#x20;
* the student is enrolled, there are no restrictions: Has access without time limit&#x20;
* the student is not enrolled: No access to this tariff

{% hint style="danger" %}
**Possible function responses in case of errors:**

**wrong tariff\_id** - invalid value passed **tariff\_id**

**customer not found** -the user is not registered as a student.
{% endhint %}

## How to remove access to a student's course via a bot&#x20;

### del\_customer\_from\_course(**course\_id, email**)

To do this, specify the function in the Block Calculator  **del\_customer\_from\_course(course\_id, email)**

| Parameters                                                | Description             |
| --------------------------------------------------------- | ----------------------- |
| <mark style="color:red;">**!**</mark>**&#x20;tariff\_id** | pricing plan ID         |
| <mark style="color:red;">**!**</mark>**&#x20;email**      | clients's email address |

## How to check if a student has attended a webinar&#x20;

### customer\_was\_on\_translation()

Access to the course need to be granted in the bot.

There is a function for this [register\_customer\_on\_course()](https://docs.salebot.pro/onlain-kursy/sozdanie-kursov/chat-bot-dlya-onlain-kursa#kak-vydat-dostup-k-kursu-cherez-bot-register_customer_on_course) и [access\_course\_from\_webapp()](https://docs.salebot.pro/onlain-kursy/sozdanie-kursov/chat-bot-dlya-onlain-kursa#kak-vydat-dostup-k-kursu-cherez-web-app-telegramm)

To check whether a student attended the webinar or not, specify the function in the Block Calculator customer\_was\_on\_translation(translation\_guid, email, after\_start\_time)

| Required parameters                                                                                                                                                            | Optional parameter                                                                         |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ |
| <p><mark style="color:red;"><strong>!</strong></mark> translation\_guid -the broadcast ID. Copy the field value </p><p><em>The name is in the broadcast settings link</em></p> | after\_start\_time - the start time of the broadcast in the format: '2023-04-18 13:30:00'. |
| <mark style="color:red;">**!**</mark> email - Student's email address                                                                                                          |                                                                                            |

{% hint style="warning" %}
**Pay attention!** The name of the variable can be any name that is convenient and understandable to you. In case of an error in writing the function parameters, a message will be written to the variable:  wrong translation\_guid

In this case, we recommend checking the function parameters and testing them again. To get the value of the length of stay at the webinar from a variable in the Calculator, you can use the function of working with arrays and dictionaries. ссылка/ссылка [массивами](https://docs.salebot.pro/peremennye-1/rabota-s-massivami-i-slovaryami/rabota-s-massivami#kak-poluchit-element-massiva) и [словарями](https://docs.salebot.pro/peremennye-1/rabota-s-massivami-i-slovaryami/rabota-so-slovaryami#kak-poluchit-znachenie-slovarya-po-klyuchu).

Example of settings in the Block Calculator:

time\_spent1 = answer2\[0]\['time\_spent']
{% endhint %}

## How to find the student's name linked to a bot?

There are cases when students may be linked to the online chat of a student's personal account, as well as those who are linked to a messenger and write to your supervisors via a bot. In order to correctly issue named certificates of completion of the course in the bot and not search for the student's name in the list, there is a function:

get\_customer\_name() - returns the name of the student associated with the client.

A function with no parameters.

<div data-with-frame="true"><figure><img src="/files/vkAWm6grAgcVYrgrWS0d" alt="" width="563"><figcaption></figcaption></figure></div>

Returns the student's name that the student entered during registering for the course, or the student's name from their personal account.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mavibot.ai/lms/how-to-sell-courses/selling-courses-in-a-chatbot/calculator-functions-for-courses.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
