# Telegram Multi-User Client

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

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

The robot 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_4nXeuOSt6EoMbGAHISRRD0-eotKF4PRRjlspApfibambK1gvAABfZgQJUVLIHChyFk2dZIuDoKD5aYmfWk8tcIaqX_6Ud_l-eKezEvmRyrWCwyjWhb4VdwmTqTpSaHtu8_WYV7oCOoA?key=Frh7bkTtqSiaXA6cD6bkJrdr" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfTYDm1bgubup8ukE9WtNPFV5lyaoRjI1yMz-uRgj9UMZqp_cgdsAdH6Tn_fIImTIgIM8T4Be1spuUcVcDv4o6i3uyJzV36bZuVLy7ilmgTlxFMW-qwCnfpkuEH37hypgyclIedHg?key=Frh7bkTtqSiaXA6cD6bkJrdr" alt=""><figcaption></figcaption></figure>

1. **Block "Start"** (any diagram starts from this block).
2. The "Process" block 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 will continue execution).

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXd2Gc6sIB1SDyyFffeszSmhO8PNOm2zlz1zQkhQy-paA6ats1m-ojsf9YQJtbcO8_MlufBHV4Kf2s59Gop1ZN0k5lYTnFDsTYW4MSWq3AGbdMHuMKNsma_BIs60vU5qx1dzm68dYA?key=Frh7bkTtqSiaXA6cD6bkJrdr" alt=""><figcaption></figcaption></figure>

3. **Block "Client. Create Connection"** allows creating a connection to Telegram in the form of a client. The following properties are specified for this block:

* Session Name (session name);
* Timeout (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.

**Important!** *To maintain authorization, it is necessary to set a unique session name and subsequently use it for connection. Upon the first launch, an authorization form will open. To authorize, you will need to enter your phone number, after which the service will send a code that will arrive in the already connected Telegram client (for example, on your phone). Then enter this code and click "Authorize".*

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXcM51jq9l6Xuk5UySu6Asvk7mjkwSvZVGUg1h3jZs8l1reIfu5-R75wDt7v41czBIm7XbrPPw772efMjr1wo4HDQgoGfWRGJFI5bUPxuFkyjs2DfL0DnCBcXM_86Fa375fOx_X9eg?key=Frh7bkTtqSiaXA6cD6bkJrdr" alt=""><figcaption></figcaption></figure>

4. **Block "Client. Get Message"** allows retrieving a message from the queue. The property "Connection" (the client connection object) is specified for this block. The variable name in this property must match the variable name in the "Connection" property of the "Client. Create Connection" block from the Telegram group that was previously used to connect the Telegram client. The output is "Message" (returns the message object. Available properties: Id - message id; Date - date; From - who the message is from; To - who the message is to; FromId - Id of the user the message is from; Title - chat title; Text - message text; Type - textual designation of the message type; IsFile - indicates whether there is a file in the message (here you can more accurately determine the type using the properties IsDocument, IsPhoto). For example: $TMessage.IsPhoto - if equal to $true, then there is a photo in the message).

**Note:** *if there are no messages in the queue, an error is generated.*

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfXJJQmEf3_ZjKFyKE_3IYrX6OOCS9f2d85HSKuMbIN6OCHJ0NdgNuKyuJ_E02-RTS1TpdKSv-2-6s_9ittartXmVtTUcLoL2NAJ6oc8kDFRTpBezMgCnA5PwyeoQbFD-pz_BQQkIA?key=Frh7bkTtqSiaXA6cD6bkJrdr" 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_4nXenJkzWKvVJS-dj9-nVIhaLrhsIlZJu2BY-xZg9x7wMVCXJl-V_vRlBY1Lmr_lKjU1qYRPr98ttIV_i1NGXwIl8fYJonqXqtgHt1JKrYqPhx6Iz0dkJJR-AuXooGf8jWan6af4P?key=Frh7bkTtqSiaXA6cD6bkJrdr" 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_4nXeUMqPuY-33gYnUNazdyjfn0EydFcj-Hgikrfdjbm39p1thLVZzz0VwWexyfOYUyqfvjFlbWivY75sMGXI-f40dePQwXPVLyq20CoVXEy5Z4yXMdYHwtJW9Nq8XQ3-mS51tW4yO?key=Frh7bkTtqSiaXA6cD6bkJrdr" alt=""><figcaption></figcaption></figure>

7. **Block "Container"** allows collapsing content. The content refers to blocks that come 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 behavior of the chatbot. The content of the "Container" block for this diagram looks like this:

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXd_VZBu-x0-hOPg5OkHfjAVggh5UavRqhiNvPmKyRxTtUMqZdd1Bctiey-HMVxoxya3CdWYPEvKN-5VbZIG0RB4MfSo2bLaeF_G4jemkTFk4QMWl-XM86MlizgWS7gBCWPXuugc_g?key=Frh7bkTtqSiaXA6cD6bkJrdr" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXceR1s7kmf6Vl0XwLOzX6EaWAyqWcabGqdTyqQUypINmU9XGgrmSH7txMNSsI-98wtsA62BaTvFNpHXrGk4aiiZYSVa2Kc7an9Dsnc9_vI81xyVWfgnEY7irj2FXaDHggsCMrRzYA?key=Frh7bkTtqSiaXA6cD6bkJrdr" alt=""><figcaption></figcaption></figure>

<br>

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 (file encoding).

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfmpsLz5CZBgYhGjpirLF4W1tQMDVsqazdeQ7ubjdYZo7IAKhUP4Tvn6hbbnPGioyR5iwYy5klLb6jFLKdXy96UZhyH1iC73O9lKxeWpyO7jc7a7h7RZrqL7COSrk26ekK4ThItdw?key=Frh7bkTtqSiaXA6cD6bkJrdr" 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_4nXe8z_4f22GzrQjAQGxpbKyUIatcpl49_lPL2Y9GA-Drbrvh6CwydNGT9A0shc1mh-TT9XdUCQju3g3fMuYkYsCMdGypB_tfqD2dCKrrMTqJvm8FaymxND06J4b9tjyhkZxVJZH8fw?key=Frh7bkTtqSiaXA6cD6bkJrdr" 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 these blocks:

* 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_4nXdCeXJCjkseowrCHXz9g56mec8m-bfCIT8prCjzMdV3Wb-MyBv81G7tKlSwsoBBAUchnA2f6afKtsxfDmVT8qcKD9mkeppXAjtmLDHOFqioi0QXx0S4nm1pdLVLqv9Amf11cIfIsg?key=Frh7bkTtqSiaXA6cD6bkJrdr" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfdIkxMEAtkYW3awP_bp29CyMqtp64hcIdDKmTB10OVSuXE-FMv7xU_sxMK2Y-TYLh9qIAaevtaDuKOh7n8_1GwQpstKl6U0mbStMrfmW6bmq26qzhZOsd4KIq2LRRRAcs0Um0XWw?key=Frh7bkTtqSiaXA6cD6bkJrdr" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdpMrXh9o4tN1TrRTWB7iIgYrZQao0zPxETL5F0eaaV2W0hqg47VNH1kjvVyuBTpF3XJSxhs8zylVQkcuO76MqNAcLTdrGrfSqV_VI7mIyhp65LtW_IcxEA70HLXbafxgtQ8hpgpw?key=Frh7bkTtqSiaXA6cD6bkJrdr" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXeC7mmfjIBnS6bhpIT6CPmv2GLDPnEUUKB51yWG65mbTEAza7ST88CrkPyiesUth5EKpgVOgat4uPZbyvQP0KPvDSMqtcS31IwfvjoA7PWvQB5wXZ-2bNH0IS0CbTKiTm4ZLcZW6g?key=Frh7bkTtqSiaXA6cD6bkJrdr" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdAT83jjsO0YqrzFyebSbZ_Ra16gxHoWmKrhO3FJ2BZ_H6X7vvdS2IoFUoEmbHYtsLYWP0J2glU378CEhL6Pf8kMtB_kU-Nz_pZvRmEh6lcQm5n4g_jFLbn2iZArre6H_mr3X26?key=Frh7bkTtqSiaXA6cD6bkJrdr" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfoy4IJ8q-9QhCtlIReM4hlF2LftcdKVjY21izM8-3ux582C5xaWUEP3zgdaeZKfvNZKYy6H9bZsSQxerJExJWeGf9tE_H7_-e7DZTlqxxboZtaAX77ttvx7shLgBK5mJmSg9nIPQ?key=Frh7bkTtqSiaXA6cD6bkJrdr" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXe9osriN6eauwvhu6am3ZKvavB02j16zDx3KUuKCRjN_n3WyHYpjGuHNi9poersS5VSwK9yHK_Ta1HicpUraxyvAHg2lRGqUC02lSpIMYROgV-SyEVrGQGOEGTlozDirzl83cPd?key=Frh7bkTtqSiaXA6cD6bkJrdr" alt=""><figcaption></figcaption></figure>

7.12 and 7.13 **Block "End"** (this block completes the scenario 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_4nXeulljZjlWTz0zPjPuMwgY_dDTbXUS-OEs3XyQA24uniAMWToHeUW82VIrug-Ga9NYs1M_PxxVMH9v3v3kSpmj6QVTd0SC_l1ooHizzQf9ULskfCMlyo-GTN8bNqdoHMSxIdqHQig?key=Frh7bkTtqSiaXA6cD6bkJrdr" alt=""><figcaption></figcaption></figure>

9. **Block "Log"** allows outputting arbitrary messages and/or variable values to the log during the robot's 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 its text message. In the Orchestrator, this robot message will be marked as "Info".

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXesAys9KY6jBlNIuvPXmEk1JwrVAk9Qp_ym2yJmk94lUHGrdPY-BidYpkVqvJ0RxFrxKAEmmtZe1z3E4wzBdsCn5vNyNWj6m9vzYDn7JKw-k0gp1LPdHAJd89pNVX89kxIEU3FABw?key=Frh7bkTtqSiaXA6cD6bkJrdr" alt=""><figcaption></figcaption></figure>

10. **Block "Request to ChatGPT"** allows sending requests to new generative models from Open AI starting with ChatGPT. With it, you can create new texts on request, 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 dialogue on various topics, and much more. Payment for the use of 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 the context from 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_4nXc6xRO_pAM20D3U5RLafykp1b8lLb-XNEoOFQ61XT3OF2Dc0QIz1k4agwvFfMVx2zApHpaeAuGkHkMbx1DFY7YU3zAw5AVXfvaohOmz6xIL_KhbVZjxBSnla8T7iBFv5j3Qe_9l9A?key=Frh7bkTtqSiaXA6cD6bkJrdr" 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_4nXdttxgfdi0REBMIdWJ9TLpdIkVOVVgDNNx14LIa6euT50nRlzMAExQpEW4vlQjYMNK-WDfU55anLB0bsIeu3jfw3OLVijK1roY_SGDhLO-KnKMScsKeQ_vjm9U4odQEEMkYHHbt2g?key=Frh7bkTtqSiaXA6cD6bkJrdr" alt=""><figcaption></figcaption></figure>

12. **Block "Log"** allows outputting arbitrary messages and/or variable values to the log during the robot's 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 its request. In the Orchestrator, this robot message will be marked as "Info".

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXeHZQx_tH5hL7IxviLYJB1GMferSVkIvAdwSko-T43CRnQEIg02H7FWGArkIbFP2k6Mfve0smuafpNy00qGlmh90ywX1wzFcHF_ssdQI5E8zGLT8BGB7mIXPhyvUXHGm49Mc_M68w?key=Frh7bkTtqSiaXA6cD6bkJrdr" alt=""><figcaption></figcaption></figure>

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

* Connection (the client connection object. The variable name in this property must match the variable name in the "Connection" property of the "Client. Create Connection" block from the Telegram group that was previously used to connect the Telegram client);
* Destination (the destination object. This string can contain the following values: Chat Id, chat name, user Id, combination "FirstName LastName" of the user, user's Username value, user's phone number);
* Reply to Message (the ID of the message to which a reply is needed);
* Text (the message text).

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdmqbrkn-lMhCP96qrTZdbGrHP4pesCBSpIQNd4DZfnR0XJVxegWB8i9naNH0EyVqJKK6Fm-Y2XQrVs12ZMVlniKEQXlKEBLfDq45J-FZ7vl-hAjSwDuzrOBab9zUEI3iJw4iz6gw?key=Frh7bkTtqSiaXA6cD6bkJrdr" 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 in which the Data Table needs to be saved);
* Separator (the delimiter character, semicolon is used by default);
* Encoding (file encoding);
* Write Headers (the set flag enables writing table headers).

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXeOZ82ePPxtBymnIl5_0v24sgPeTcgOGlZAX1oZUoVfwO7ehzCM9FTGRCt2AcUojkG11eeVABaBjhM1WujZrI8d844NAA4fyEEbG5HSAiGdxUxdNos1cERLZwH9Rqut3TFBDpDg-w?key=Frh7bkTtqSiaXA6cD6bkJrdr" 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_4nXda6SV4F9e3S61ODOqj6b50o3flpfbboWwBe-3NciLAt8OKRHpweKzhFsoQW2jL84MD4C3SmXqrlt3eIxhYhEViNzpt2Ahmk-27e1xI31KB7yco2-wFaL7EEuIq9fOHGWz6DAtqfw?key=Frh7bkTtqSiaXA6cD6bkJrdr" alt=""><figcaption></figcaption></figure>

16. **Block "Requires Stop"** checks the necessity of stopping 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_4nXc5pkZ0R-H_qfepr14ONUWYUh6UHp7kDSD8Aqf0zIxuZTv5g8FHKLZJJ4Z9dxHn1fqjihCeUs2BuuOoFOr3-vQqZ-tqCIPjLUCJLlEoqt1L2ABpbjKq2zD4PWh-ogSd9wTUo_CNEA?key=Frh7bkTtqSiaXA6cD6bkJrdr" alt=""><figcaption></figcaption></figure>

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

**Diagram "Settings"**<br>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdlKWGBEDR-6Af2TVeEvKUhVP6LlX1jrmeMy-J8VPfnKna0-yd1SzgGbGcluYufxe8PXuDE4X5afYBpdpXkIOegSTcM_bBLZ9G6xBdxwGgBM5U-7vzyo259li3ItWBp4VhLFdZF?key=Frh7bkTtqSiaXA6cD6bkJrdr" 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_4nXdF9upE6OLS9H9LcFmFBpwv1nR_KNIwwqs3nEd_bZjwNm1lYAHEZIFRkUmT9jKJngzFZWNCsjbZ5OM8duWTLJJw__8WkK1erSiXdtpJ17N3Cs89789OLZbe-8-aY4oOnAGxeSVrjA?key=Frh7bkTtqSiaXA6cD6bkJrdr" 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_4nXclfgGoIhvlzRhefhhtbatTOiqfDK6SeXWXmQse3ympzKyVnjUQyFR91_40sSiheQ-T5hjM1ZYq3dgn0UPRThRgnpZNy6QB34xOPTszA-LKPqpNJ4a9vnAQ7-oEAJ5tYJWcUo1pqg?key=Frh7bkTtqSiaXA6cD6bkJrdr" alt=""><figcaption></figcaption></figure>

4. **Block "End"** (this block completes the scenario 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-client.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.
