Telegram Bot needs no introduction today and with the growing usage of chat bot in RPA industry it is obvious choice to integrate your workflow with telegram bot.
In this tutorial, we are going to write a small UiPath process which interacts with Telegram Bot chat: send to user a screenshot with Captcha image (from website https://captcha.com/demos/features/captcha-demo.aspx), wait for message with recognized Captcha text or command to change Captcha or command to speak Captcha out.
You can download the project .xaml from GitHub – You’ll just need to add your Telegram Bot token and ChatId (Id of chat of bot with you) https://github.com/mflow42/rpabotsworldbot to to get this example working.
Action plan for this article-
To work with “HTTP request” and “Deserialize JSON” activity you need to first add UiPath Web Activities Pack as dependencies in your project.
You can enable and install it from the Manage Packages window as shown below.
Select UiPath Web Activities Pack and click on install to add a required dependency. As soon as they are added you will be able to see web activities from the activities panel as below.
Open telegram app: mobile, desktop, or web (https://web.telegram.org/). Register if you did not do it before. Then follow instructions:
We will use only the following types of Telegram methods:
Read More at Telegram Documentation – https://core.telegram.org/bots/api#authorizing-your-bot
First of all, you need to add the “Use Application\Browser” activity and assign it to the website https://captcha.com/demos/features/captcha-demo.aspx.
Then add Flowchart and:
Assign EndPoint to “https://api.telegram.org/bot”+Token+”/getUpdates”
Our Intial Workflow will look like this
Then add Deserialize JSON activity to deserialize response from the server.
Then add assign to UpdateId = If(ResultJObj(“result”) IsNot Nothing AndAlso ResultJObj(“result”)(0)(“update_id”) IsNot Nothing, ResultJObj(“result”)(0)(“update_id”).ToString, UpdateId)
Then add assign ChatId and make Breakpoint at this activity to get ChatId from the response in Local Panel via Debug mode.
Now we know all the necessary items: Token and ChatId. So we can move on to the most interesting part of this guide.
More at https://core.telegram.org/bots/api#inlinekeyboardmarkup
I chose this type of markup and it has following JSON form – there are two buttons “change” and “speak” which contains appropriate “callback_data”.
Assign KeyboardMarkup = “{“”inline_keyboard””: [[{“”text””: “”change””,””callback_data””: “”change””},{“”text””: “”speak””,””callback_data””: “”speak””}]]}”
Add “Take screenshot” activity, set it to Captcha image and save image file path to variable CaptchaImagePath:
Then send it to telegram chat via HTTP Request activity:
In the chat it will look like-
The answer is Callback?
ResultJObj(“result”).Count > 0 AndAlso ResultJObj(“result”)(0)(“callback_query”) IsNot Nothing
If it is a callback then save Action:
ResultJObj(“result”)(0)(“callback_query”)(“data”).ToString
The answer is a Message?
ResultJObj(“result”).Count > 0 AndAlso
ResultJObj(“result”)(0)(“message”) IsNot Nothing
If it is a message then save AnswerText:
ResultJObj(“result”)(0)(“message”)(“text”).ToString
We have 2 actions: change and speak. So every action is a click to appropriate button:
Then we need to send a message to the user to give feedback:
Then update UpdateId and loop to “Take Screenshot ‘Captcha’”. Workflow will look like this:
Then we need to process getting and typing into Captcha text. If answer is message with Captcha text then we need to save AnswerText from ResultJObj:
ResultJObj(“result”)(0)(“message”)(“text”).ToString
Then add “Type Into” activity to type this answer to Captcha validation input:
Then add “Click” activity to button “Validate”:
Then we need to get the result text of validation:
Then direct to “HTTP Request sendMessage” activity. If answer is not a message then we need to direct flow to “HTTP Request getUpdates” activity.
Workflow will look like this:
Please feel free to reach me in case you are still facing any issues with your Telegram integration with UiPath.
Happy Automation!
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Sign in to your account
What is Functions of this project