# Telegram Multi-User Bot

Let's consider an example of a bot that demonstrates the operation of a Telegram bot with multiple users. Each user can communicate with Chat GPT (using an individual chat history). The session name is specified in the variable $NameSession, after which authorization in the client is required.

**Important!** *Connection data for Telegram can be found at: c:\Users\User\AppData\Roaming\Sherpa RPA Data\Telegram\\*

The bot project consists of two diagrams.

The main project diagram looks like this (for convenience, the blocks of the diagram are numbered):

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXeUdEYPvdpSb-oGWIXVky27sLLSbDSc_1CoH6Pj3pmk9tnIFUB8b7JtLavA2uYoWB6ycA2-azMmLhV5_fI3VslbvPX1Z6a59ij9VBWs5jgC9pnYmNgUDWw8s-BUoDAF-tTfXzvl7w?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfnVu_KB5uO1dr5naTVdkY777z0B6i6_lctfumz-7zHvvQ70oZQH5uF_G3GDHwCgjbnqkEbt_rf9mbR3Yn6d0FJHQ-10m2Zf6JHL1aGJdc8jU-t_puiB3tromIawVmCPQobGUecsw?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

1. **Block "Start"** (any diagram starts from this block).
2. **Block "Process"** allows creating scenarios consisting of several diagrams. The execution of the scenario will continue from the "Start" block of the specified project diagram. The execution of the scenario will return to the current block and continue in the current diagram as soon as the "End" block in the external diagram is reached. For the "Process" block, the property "Diagram Name" is specified (the name of the diagram file where the scenario execution will continue).

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXcGT_OkE8_rpRJgKN1eUB1dW07wFy23Buy02ZM0NYx8uzPVpN5vnN8AWUBYRjyGUx4YgDRDfxI3jr7n7EQkKcPhfmcejg558gYuNYSJVXVweRkDRF-4pB8uC9trTDEMqmhNuUkttg?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

3. **Block "Bot. Create Connection"** allows creating connections for the Telegram bot. The following properties are specified for this block:

* Bot Token (the bot token that can be obtained from BotFather in the Telegram client);
* Timeout (the timeout for a response from the Telegram server in seconds).

The output is "Connection" – a variable with the object of the current connection to Telegram. In other blocks, this variable must be specified.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfM2vBvLxOzQZs3SSF1YB3R05Hrsu3jekOPFzyDMChqCFAJxcFz9vrRxbYF5dBLU8l2NDZzHV3jdggvSV__-1wB17sVH0ogSNhT1CIMsoVcXbcdbPkaWORxrDzLhigUz1vJSy25?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

4. **Block "Bot. Get Message"** allows receiving a message or callback from the queue. If there are no messages in the queue, an error is generated. The property "Connection" (the connection object to the bot) is specified for this block. The variable name in this property must match the variable name in the "Connection" property of the "Bot. Create Connection" block from the Telegram group that was previously used to connect to the Telegram bot.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfRCRlsoUq5_OjfJNJagNkM8Rzy2bQuJmFfYKhLOURwDEAAesqif75mIjtxS_W_LUJzFP9LP8QnTJM22lKnDsgReTsK-g6VVTQ-rh-shvqocJp8xDl3MiZbxuh1IfVm0-CCFPkpOw?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

5. **Block "Assign Value to Variable"** sets new values for one or more variables. In this case, one value is specified in the properties, which needs to be assigned to one variable accordingly.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfqqOX78AtdZOrKDzWu6eLtW8sjSvLdZMvlddoJcF7b3iq36jnRBuYMagqufxxWiumB4iqC39a8bHJVkBlu-lMuvivr1PTIg2cwwF8BwEf0evxdSst062w5T05TiSrmdBwfOY6GQQ?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

6. **Block "Get Path"** allows you to find out the full path to a file/directory. The following properties are specified for this block:

* Folder Path (the path to the folder where the required file is located);
* File Name (the name of the file).

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXd_u2PkOza_ehoLNMwPjiJWDg11VEme4heBX1QEPQTx-N8KulvWktps8aqDaNYRian6EBjgWw2RnnoT0eaqVGbMLv24icDYzfHWPY4K6L25tBahhKS1Ph2c6pXxvghBJjZ1U9uifg?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

7. **Block "Container"** allows collapsing content. The content refers to blocks that flow from the current one through the lower connector. For proper operation, the blocks of this container must end with the "End" block. After the internal blocks have finished working, a transition will be made through the "Exit" connector. In this case, in the container "Loading Client Data," you can switch "Prompts" (or set your own) to specify the chatbot's behavior. The content of the "Container" block for this diagram looks like this:

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdYJdQrByzvv81v_GPldw7JG2lXu7k9ZRZUeObXHRSGXC6kjpxXDY_2BVEV7RG4VTefeiR9PIvhmEN6nN_21GOYbIgfVeUNPDkFeP6Xxv8EOKLv-oeFfo2AkAxo0YMo50AdvDEtfw?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXcP3c2BB4Ch7nPoS_nJCAMKzhzbeqJni3TWuH8IN4J2O8XRaYafx7Qbttaet6LdXf-bSa1PR2Sa3uCgmIkWI6sFRzq3ULKOR8uZrdgWiqnKsYeUVTx9MULI284CyDNKGZ44zDsT?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

7.1 **Block "Load from CSV"** allows loading a data table from a CSV document. The following properties are specified for this block:

* File Path (the path to the document from which information needs to be loaded into the Data Table);
* Separator (the delimiter character, semicolon is used by default);
* Encoding (the file encoding).

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdU293LMgwyPgViHODKCN2jpgR7JnhcoBaIBiuPpla5Uh5e_VyUm_WJb-_9hlL9sUuZMb3ELsjbkyP6V6boWI2K9DRG-Qla0W-1ZY1Lb0qnwCfnSzhrdqeif9ujgrZ0qdd04GPJ-A?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

7.2 **Block "Execute Expression"** starts the execution of one or more expressions in a language compatible with PowerShell. In this case, two expressions are used.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXe7swG9uCBYIzwGh3z0v0zLggd6tYGRZg540R2DDxcwamBo1VznH8cbyluLhTmVmIot2nkhtqHMtbKaZm39WAOAk9g1mDDwJ-NTMYOylQ0vGFXJrRz0C8YtGjurgcFYYxPJdtgeVw?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

7.3 **Block "ToDo"** is used as a placeholder or reminder for planned features to be implemented. Unlike the "Comment" block, this block is an element of the scenario but does not perform any actions.

7.4 – 7.11 **Blocks "Add Row"** allow adding a row to the data table. The following properties are specified for this block:

* Table (the data table to which the row is added);
* Values (a list of values for the new row).

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXcnrdRWYjFZsiYDK-D7jwH5y1ioZXZlGejF_oir6NO6ymgqjDrzDxiCAuP6-1qtwRvhhlQ1PQgrFWbFob_Us20pJJr_SaGRrFTHOzXdqti2A9HLEHWDeDKaX4-HUUjyeMlmBPSVbw?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXc4OeWFSDbHmuKreq6k5hp1s9eqpWJFCWbp7Nb8xJpixZhT5NV1o6q18xovoIanAfGtsr2rBpKD-tItw-aBy-gEqVEP4yCkFxfdXmIXtKLhNVrK5LnD7iyKiOQh14xs-B0cIOqJKA?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXcVpBqfLNPdDQoF5uOjiWhPjS6vt1sQSGSjCTbKQUpPNUlQoE6zFphcpTlX0-U9CVFTe_4GoytvOGF3I6a0TkfDwHsXMjOqhgJVKEqGNsNP2SFoBs5F800EC2mwPHmr-wW7q6JVpQ?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXeyWVghcDxdHtRps-WwZadQLqAyFmlTQ0zzxerzb_YTE1XTFdy5oscDI7Dq0PZdnLLTjS6tZhoxplGZFWXTCmuDJ07oMFo4aapeZ33oSIJ8HFPz1OGkdOxV-aeaSLfasZaJ_m1FPg?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXcHuaC8FlYi2CadS9Z2u4aYgCfcmGQGKGq8d7cg1wS14f3K0J2MAw6gUBfFrs7K7zT280CU68oyWetdNp8A1el1hEypJeW3tXb_e3SslNaNIcp9Yq2I0nfU3dgftDsCm5pars6R3A?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXd0MiwbM1eE_oou3zeEmALfhAl0ggN7Fdfm7aeDYxiRIA24aXhK6Qx_VPYgk0ZcB0rKVIx-IAUO9fL8fVi4M_hwWi8oHhL3yH1e9V-xgBmISnYH29XfEzOr0seOCXK2c_Rm4m6oNw?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfF2eymX--DFxF2jKIgWocw69nVsh-_5zusNyhyP6BjxdkVHbaQ1rtw_WRNEZdEVAN0mjSwcprtCBG8_Max2lphJy7RszgMthaPqZ7YB0ghayjCdqPeixGzF1vIhHYxVfyWHV9D?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

7.12 – 7.13 **Block "End"** (this block ends the scenario execution or returns the subprocess diagram to the main process).

8. **Block "Add Row"** allows adding a row to the data table. The following properties are specified for this block:

* Table (the data table to which the row is added);
* Values (a list of values for the new row).

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfv0TCsH6xbGWuXLeJjb766S-aoQy-ObGTI6qFS_mFir5z_7OfIP9N-5QPfs1DvXcYGQzLa0pA8rDn1vR3cdYeXtNoaPb-9D-Hzl8cOJx8Xct7AXY1jmiEXPgTD9JA1C_GufDAuew?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

9. **Block "Log"** allows outputting arbitrary messages and/or variable values to the log during the scenario execution. The property "Value" is specified for this block. A text constant is indicated in quotes, and the variable name starts with the $ symbol. That is, this block logs the client's ID and their text message. In the Orchestrator, this robot message will be marked as "Info."

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXcnbZvgJYcD-j423o1XeXgzB84bZ4x-O6TsLJTDzMB_uTc-FVQbZKRKMN2ObQuE-MW-lQGtFgfjTeAaNB-wkKgYyLPNCNiD342W4MNuKUzm5reaoTLZAfzQjE0a3ofx6trvah_DTw?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

10. **Block "Request to ChatGPT"** allows sending requests to the new generative models from Open AI starting with ChatGPT. With it, you can create new texts on demand, perform various classification, summarization, translation, and rewriting tasks, write code prototypes in different programming languages, parse semi-structured and unstructured data, extract and process facts, maintain a dialogue on various topics, and much more. Payment for using this functionality is deducted from the client's account on the platform. For testing purposes, each new user is given the opportunity to test this functionality free of charge. After the robot development is completed, payment is required for using this functionality. The following properties are specified for this block:

* Chat History (the chat history based on which the neural network should generate a response);
* Model (the model for generating the response);
* Temperature (a decimal number from 0 to 1 indicating the degree of "randomness" or "creativity" of the result, where 0 is the least creative result, and 1 is the most random);
* Maximum Length (the maximum length of the result expressed in conditional tokens);
* Auto Limit Length (the set flag enables auto-correction of the maximum length of the result);
* Timeout (the maximum waiting time for a response in seconds).

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXcAdZF0udqVwnKIOiQDwPufqDI3m1T3b6Oyl7bFlKvnDryaQf8lEGbQwWToTI_iHbvPpStcyBdhVwTcILfq9iVm-PKGdnQECTinbUzLzi_vHwdx8qfNZC3vfJFATUuO9oxm24j5tQ?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

11. **Block "Add Row"** allows adding a row to the data table. The following properties are specified for this block:

* Table (the data table to which the row is added);
* Values (a list of values for the new row).

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfytFio-sRVjo_erlWU46qjyY_0yHan6fTyC78RkwXLSd-7XBmorM0TnvHDVWWHGbIbIiT8sXthf91HZ1m8JqFHxqhVNifXXeJLwTtqeB6Xqy4x8X3swq4Yv8M6ON31klt2Fjo2kA?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

12. **Block "Log"** allows outputting arbitrary messages and/or variable values to the log during the scenario execution. The property "Value" is specified for this block. A text constant is indicated in quotes, and the variable name starts with the $ symbol. That is, this block logs the client's ID and the response to their request. In the Orchestrator, this robot message will be marked as "Info."

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXcFLQvCnGC2Xc7BCopmj_5ZLeURZeFlrwyoJfItOuRO8QX6LmD9V7eHdPDDXlEuIIs9mVRmgh9k6VFgLjYtuanVCRxh9g5LB4rCbMpE8TfkS9uShzOEqrw1dp_RtvCokQV6KakT?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

13. **Block "Bot. Send Message"** allows sending a text message to the chat. The following properties are specified for this block:

* Connection (the connection object to the bot. The variable name in this property must match the variable name in the "Connection" property of the "Bot. Create Connection" block from the Telegram group that was previously used to connect to the Telegram bot);
* Chat ID (the chat ID. This value is obtained from the "Bot. Get Message" block in the "Message" property);
* Message ID (the ID of the message to which a response is required. This value can be obtained from the "Bot. Get Message" block in the "Message" property);
* Text (the message text).

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXeYiBSnuQ48GM5BhygrlHhnubxPvEyxNgn5XfaI4OqAHYCipbN_EZNWZhohtk0fsFnADE9BGO2CdsLwaUS4loFbkJPeErlzjqLjsJ8UEJUSFymDKIano3gn5WIoY6JS-tr47CLgHA?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

14. **Block "Save to CSV"** allows saving the data table to a CSV document. The following properties are specified for this block:

* Data Table (the data table that needs to be saved in the document);
* File Path (the path to the document where the Data Table needs to be saved);
* Separator (the delimiter character, semicolon is used by default);
* Encoding (the file encoding);
* Write Headers (the set flag enables writing the table headers).

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfusssfET3ZJAWVtjwh4Pk6xwmjba2lk58XjZB-xY6aKBW_UmP5aDBaT-tW7Muofsk3-DmruGqb7SKR7ePKRMqlnbOxXfP1rAtAfs3KEb7dZ_s_qiePH5JbafY_vh7NTqd9KyGf?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

15. **Block "Pause"** pauses the execution of the scenario for a specified time. The following properties are specified for this block:

* Unit of Measurement (the unit of measurement in which the duration of the pause is specified);
* Duration (the value of the time interval in the specified units of measurement).

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfGH70q75WMcjk-El3mASVpobEnCybyjMOjUZvgcjj_RJZ_775iooNgHXDO_A8LX_0F4nu_MiAHyXgLTxUWlMU8U_gfJEJSh8rdYJM7t0yLFHb9yLKCWIqsMTz2CSX0DJSMOu4lWw?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

16. **Block "Requires Stop"** checks the need to stop the scenario.

For this block, the output in the "Result" line specifies the variable $NeedStop.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXeD_luRdNC9UDBefCruJCcEYCxpEPwoDqG2c3vNKV7KA_vkb6r2UtVgRnMN3z8-YLW6sPMWyL7ERkqGU8YNQHov_vDrB2N4imB96spDYOV4PaoPX9VGO57tUchUPgrVp_xZOoo5Dw?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

17. **Block "End"** (this block ends the scenario execution or returns the subprocess diagram to the main process).

**Diagram "Settings"**

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdVPg8TXf4vtfEkSmiPnvIuUukdDKNgQ0O__2KWTzP7zJCx9kkq6jAoA3_fc3diEYgxtxBAJhRlpjPVYzpJxCT7FQ6FQ2-k6wMC8eYO2Phba0HAaX2TO0Ccs1j-64IkICSXuZtSTA?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

1. **Block "Start"** (any diagram starts from this block).
2. **Block "Merge Path"** merges strings into a path. The property "Initial Path" is specified for this block.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfpjvRoB_fTRiLI27kGV-FlCUJ6eMQoaAa24SSFzCX9_6_YK0blX-Kt64w1X3KAvZZBm1FLqXcCO3lMNMN4JE6VZoa778al2eUmFwH5azVZL9adRildrCuUEd5Q9KowtscDaKQLGA?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

3. **Block "Create Folder"** allows creating a new folder. The property "Folder Name" (the full name of the new folder) is specified for this block.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXe57Rlg1zlsTyMKK08K9iwpILU9VL6_edKlGZjrAsbrwr9rDwKoLPH0wbVRVHU2QDI-N4oQ3c_6edACVDracJodfi5QT3H8kjZEB3D0acQvd1at7b5yYWMc9xwtN2fQBktXzAxh2Q?key=31TfmOJqwnG_FrKp-kM5Dugx" alt=""><figcaption></figcaption></figure>

4. **Block "End"** (this block ends the scenario execution or returns the subprocess diagram to the main process).


---

# 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.sherparpa.ru/en/sherpa-rpa/sherpa-designer/primery-robotov/telegram-multi-user-bot.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.
