aisingapore / TagUI

Free RPA tool by AI Singapore
Apache License 2.0
5.45k stars 573 forks source link

Checking if run without errors, notifications, Python integration - some ideas #898

Closed kensoh closed 3 years ago

kensoh commented 3 years ago

Raising a user's query through email


I've run into this RPA product,love it so far. However I cant figure out if there is any option to do an error handling.

Something similar like e.g. UI Vision does with !statusOK variable or any other mechanism to check if particular step/script has run without error. Especially needed as the scripts are planned to run in background each night and I'd like to get notified in case something did not run succesfully (either using your Tmail API or via outlook or some notification with RPA steps via form published on a page).

kensoh commented 3 years ago

Hi Julius, here are some ideas, see one of them could be suitable for your scenario -

  1. You can try using the -report option - https://tagui.readthedocs.io/en/latest/reference.html#report-or-r

This will save a .csv file of all run results to tagui/src/tagui_report.csv and it will show the error encountered.

tagui filename.tag -report
  1. When an automation workflow gets an error and ends, there will be errorlevel 1 returned. If you are calling the tagui command from other programs, you can check the return value to make sure the automation complete successfully.

  2. Design error handling into your automation script. For eg, checking if some element is present or not, or check some return value of a process on the webpage. Then call APIs to do the notification. Tmail is a way to send emails using API if you have an email server. But there are other ways to send notification using API. Do you use Telegram? My friend was suggesting to integrate TagUI with Telegram to send notifications if something fail. For WhatsApp, there is no free service to send notifications. Need to purchase and rent a WhatsApp business account instance to do that. And many restrictions on message sending.

  3. If you are running TagUI from another program, you can check the errorlevel or the 'ERROR -' string in the output log file to determine if the run has an error. To enable output log, create an empty file tagui\src\tagui_logging to start logging result for an automation. After knowing if there is an error, you can call API from your program to send notification. For eg, there are some APIs that can send SMS to mobile phones.

Do share ideas on how your users would like to receive notifications!

julojulox commented 3 years ago

hi Ken, thx so much for your suggestions. I was already considering some of those., I will dig bit deeper to validate each of your suggestion. @3. What do you mean by your friebd suggesting to integrate TagUI with Telegram?Do you mean you are considering to provide such integration within TagUI or just an idea to leverage Telegram api and code it in the tagui flow using e.g. python jump out? One or the other I am using Telegram and I think the idea is great.

Thanks a lot and have a nice day. J.

kensoh commented 3 years ago

Hi Julius, sure let me know if you run into any questions or problems along the way as you implement your solution :)

Yes thinking of providing Telegram integration with TagUI, so user just need to do something like telegram userid message in TagUI to sent notification to Telegram user. And with this, TagUI can also automatically notify users for any runtime errors or successful automation execution, if user wants to enable alert for the automation.

Below are some ideas for TagUI roadmap next year.

I would like to create an AI Recorder for TagUI which can record actions across desktop and web applications, and automatically generate a MS Word document. This Word document is editable by users to fine-tune, and can be used directly by TagUI to automate a process.

We also would like to provide some soft SLA (service level agreement), where we aim to reply user issues within 24 hours. Can be AI Singapore's partners we work with or any user from the general public, both in Singapore and globally. At no charges. This would solve one of the big pain points in using community versions of commercial RPA tools - users could only rely on public forums but they usually can't get solutions there for their specific automation scenarios.

julojulox commented 3 years ago

Hi Ken, thanks a lot. Roadmap looks promissing and very helpful. I like the ideas and especially the approach of yours. I made short research about telegram apiand python-telegram-bot module, I created simple py script to send a message from telegram bot to me which is working fine if I call it standalone. Could you please help me to find out how could I integrate it to tagUI ? I've found https://github.com/kelaberetiv/TagUI/issues/276 I tried ..... run py bot.py echo py_result I also tried .... py exec(open('bot.py').read()) .... None of those seems to work so far for me. Maybe I use some outdated syntax? Another question - would there be an option to hand over some info/variables from tagUI to py script e.g. message="Action switch off - OK" so I could hand over the message to bot.py for bot to send such notification message to me? Or would I have to rewrite the script directly in tagUI step by step with tagUI> py tagUI>py etc.

If such info exchange would not be possible between tagui and ext. python scripts, would you recommend to rather use RPA-Python? I have noticed you created this as kind of successor/extension of tagUI tool, correct? Thanks a lot for yoru answer and wish you nice day. J.

kensoh commented 3 years ago

Hi Julius,

Running the following shows 123 as the output. -nobrowser option is used since the demo doesn't need Chrome. The Python process current working directory is in tagui/src folder, so maybe that's why it didn't work when you use exec().

tagui demo.tag -nobrowser

demo.tag

py exec(open('/Users/kensoh/Desktop/demo.py').read())
echo `py_result`

demo.py

print('123')
kensoh commented 3 years ago

You can also use run step to call a command line and get the printed result with run_result this way -

run python /Users/kensoh/Desktop/demo.py
echo `run_result`
kensoh commented 3 years ago

You can also embed your Python script within TagUI, by using py steps or py begin and py finish.

py import os
py print(os.getcwd())
echo `py_result`

Indentation for your Python code will also be respected.

py begin
import os
print(os.getcwd())
py finish
echo `py_result`
kensoh commented 3 years ago

I personally find the integration with Python pretty seamless, except for passing variables. It isn't easy to come up with something to accurately and correctly pass variables, thus for now below is the syntax for passing, using py_step() function. That is the only way that TagUI can convey exactly what variable to be passed to Python.

phone = 1234567
py_step('phone = ' + phone)
py print(phone)
echo `py_result`
name = 'Donald'
py_step('name = "' + name + '"')
py print(name)
echo `py_result`
kensoh commented 3 years ago

For getting results, whatever that is printed from Python using print() will be returned as py_result to be used in TagUI.

From your experience, do you and your Python friends use backticks `? A possible implementation for variables is by using backticks like below. So whenever backtick is used, TagUI will know that it is referring to a variable in TagUI and do the sending accordingly. But I did not implement this yet, because that means using backticks as they are would not be doable in the Python code anymore, as they are by default subjected to special interpretation by TagUI.

phone = 1234567
py phone = `phone`
kensoh commented 3 years ago

Above are examples of passing and receiving simple data.

For more complex data, you can use JavaScript and Python JSON libraries to send and receive back JSON strings.

a = 1
b = 2
c = {"a":a, "b":b}
json_c = JSON.stringify(c)
echo `json_c`
py_step("json_c = '" + json_c + "'")

py begin
import json
c = json.loads(json_c)
d = c["a"] * 10
e = c["b"] * 10
f = {"d":d, "e":e}
json_f = json.dumps(f)
print(json_f)
py finish

echo `py_result`
f = JSON.parse(py_result)
echo `f.d`
echo `f.e`

Above passes 2 variables from TagUI to Python, make modifications, return 2 variables, and shows below for e and f -

10
20
kensoh commented 3 years ago

RPA for Python I did that as a personal side project. I think there are rising ecosystem of Python users, so I thought it would be great for Python users to have the same automation capabilities like TagUI. I haven't got time to work on it past few months due to dealing with family issues - https://github.com/tebelorg/RPA-Python/issues/144

But the project is very much alive and I'll look at the issues and any bug fix when I get a moment. Have recently engaged a full-time helper to help with housework and cooking, and some baby care. Hopefully I'll get some personal time to work on that soon.

TagUI is more like a complete RPA framework, there are features like object repositories and datatables built into it. And presented as human language syntax, supporting over 20 human languages - https://github.com/kelaberetiv/TagUI/tree/master/src/languages / https://github.com/kelaberetiv/TagUI/blob/master/flows/samples/8_chineseflow.tag

RPA for Python, on the other hand, is a bare minimal wrapper that exposes the UI automation features of TagUI to the Python user. I kept it as simple and un-opinionated as possible so that Python users can do things in their style and choose their preferred Python packages to build something cool. So for that package, no other dependencies or integration with other packages, openpyxl for example.

For someone familiar with Python language and programming concepts, I'll think it's easier to use.

For everyone else, probably TagUI can get the outcome the user wants faster than RPA for Python.

julojulox commented 3 years ago

Hi Ken, sorry for delay of my answer. I was not much online recently. Nevertheless thanks to your advices and hints. I managed to code working solution with dynamic messages from TagUI being passsed to python script which sends these message to me as a notification via telegram app. I simply love it :) Once you have a telegram intergation natively in TagUI as per your roadmap I will adapt it to use your solution instead as it will be more stable/compatible I guess.

One more question/idea (reverse direction) - do you think it could be possible to call a tagUI script via a command/answer to telegram bot? I mean in your future telegram integration or maybe even somehow with current TagUI version?

Thanks J.

julojulox commented 3 years ago

For getting results, whatever that is printed from Python using print() will be returned as py_result to be used in TagUI.

From your experience, do you and your Python friends use backticks `? A possible implementation for variables is by using backticks like below. So whenever backtick is used, TagUI will know that it is referring to a variable in TagUI and do the sending accordingly. But I did not implement this yet, because that means using backticks as they are would not be doable in the Python code anymore, as they are by default subjected to special interpretation by TagUI.

phone = 1234567
py phone = `phone`

In regards to your "backticks" question. Frankly speaking I am not a python programmer, acctually I am not a programmer at all, so I cant tell you the answer. I am a pure beginner in this area, but as you can see TagUI is obviously very user friendly althought putting it together means writing it in commands. In couple of hours I was able to put together a very nice script, with quick adaptation for multiple apps via variables defined at very begining and being used accross the script later on. I tried another solutions (no coding solutions) before TagUI to achieve my automation and it was way more difficult, not that stable and straight forward etc. In another few hours (and your hints of course) I was able to integrate TagUI with Telegram app for notifications. I think no further comments are necessary :) Nevertheless if backtick implementation would bring downsides interprating python as you described, I think it make no sense to do it. Especially when py_step solution which you suggested is working fine. With py_step its maybe not that nice for reading, but for nice reading one can still buy some nice book instead ;-) Or is there any other reason why to consider backtick or similar equivalent ? Thanks PS: wish you all the best in 2021 and lot of achievments from your roadmap plans too.

kensoh commented 3 years ago

Hi Julius, no probs and Happy 2021!

Wow that's a nice automation you did together with Telegram 😄

For running TagUI automations from Telegram bot, I believe on your Telegram bot server, you should be able to use standard programming languages functions to call tagui command from the command prompt to run certain automations. I have seen other users examples where they programmatically generate the .tag file to be automated, and the parameters, and run the automation by calling tagui command. For eg writing a NodeJS program that runs TagUI automation.

From Telegram's website, it does look like to create a working bot requires some programming - https://core.telegram.org/bots/faq#how-do-i-create-a-bot

If the programming language you choose to run your Telegram bot is Python, for eg by using https://github.com/python-telegram-bot/python-telegram-bot, then you could use RPA for Python, since that's directly in Python already.

However, note that running in parallel multiple TagUI processes on the same computer, is not a designed feature. So users have to figure out what is the best way to implement multiple processes. On your Telegram server, you could for example, implement a queue structure where the first automation request will be served and responded before the 2nd one runs. Or you can create multiple user accounts to run TagUI on the same computer so that each individual TagUI / Chrome / SikuliX processes do not accidentally affect each other.

kensoh commented 3 years ago

Your putting together the automation with Telegram notification is impressive!

Thanks for sharing :) And I like your sense of humour lol.

Oh for the backticks thing, we are trying to make RPA accessible to everyone. Having py_step() feels very much like programming, and is harder to follow than using backticks directly to mean variables to pass to Python. The other consideration is in Python 2, backticks is a normal usage, but in Python 3 no more. There are still people using v2. Will think more about it together with my new team-mate after she joins.

In the meantime, here's the latest news on TagUI. Am doing a webinar in late Jan, and I'm also introducing new features like 24h soft SLA and weekly RPA Clinics to do live Q&As and solve users problems. I hope these unique free support initiatives, together with the new features on the roadmap (AI Recorder, Office RPA idea), will help make RPA accessible to more people.

kensoh commented 3 years ago

I'm closing this issue for now but please ping me if anything, I'll still get notification of updates here.