aisingapore / TagUI

Free RPA tool by AI Singapore
Apache License 2.0
5.54k stars 577 forks source link

Proposing for consideration, community-contributed JS functions - pending #1219

Closed kensoh closed 1 week ago

kensoh commented 2 years ago

Fyi @ruthtxh, @kangyiwen mentioned in email which triggered an idea. There are now helper functions but limited. If we have a way for users to easily contribute their created JS functions, that would crowd-source community contributions and make TagUI more and more powerful and easy to use. To do that successfully, following would be involved -

The immediate first step, if this idea is to be implemented, is to add tagui_local.js / tagui_global.js usage into documentation. This is in the old docs but not in readthedocs to make it less developer-focused. But without this, users won't know how to create their own and the chance of contributing their self-created functions goes to 0%.

kangyiwen commented 2 years ago

@kensoh 让我修改现有的 tagui_local.js / tagui_global.js,我会非常“害怕”,因为我完全看不懂这2个文件代码,而我只是想把一些简单的功能做成函数,我建议:

  1. 让用户自己新建一个 .js 或者 .tag 放在指定目录,例如 kywfunctions.js 或 kywfunctions.tag
  2. 用户可以在.tag里,import kywfunctions.jsimport kywfunctions.tag
  3. tagui_config.txt 内增加参数,设置预加载的 .js 和 .tag

这样感觉更清晰,不混淆,也给了新用户的选择权,不容易破坏已有的 tagui_local.js / tagui_global.js 。

UIPATH等软件,应该都支持“自定义命令”这个功能,也支持所有用户分享自己的功能模块,我是习惯自己做一个独立的函数库,例如: 初始化:关闭所有浏览器、WORD、EXCEL等。 自定义chrome打开:先判断是否有已经打开的CHROME,如果没有就新开,如果有就在原有chrome内打开URL。 自定义excel打开:先判断目标XLS是否已经被打开,如果有打开着就跳过,如果没打开就正常打开,如果没打开并且有其他XLS打开,就先关闭其他XLS再打开目标XLS。 ...

总是,都是一些增加稳定性的常用函数。

RPA元素点击、输入的UI部分,其实工作量不大,而稳定性是RPA的核心,也是最占工作量的部分。所以,我很期待TagUI支持自定义命令。

kensoh commented 2 years ago

Oh tagui_local.js / tagui_global.js are empty files and does not come with TagUI. Users can freely define, use, and share their tagui_local.js / tagui_global.js files with their colleagues.

kangyiwen commented 2 years ago

谢谢 @kensoh 我会用自定义函数了。 把方法记录下:
在 \TagUi\src 下新建 tagui_global.js,里面放自定义的函数,例如:

function today()
{
//首先需要new一个date对象:
var d = new Date();
var year = d.getFullYear();
var month = d.getMonth()+1; //因为月份从0开始,所以当前月份需要加1才能正确显示;  
var day = d.getDate();
return year+"-"+month+"-"+day
}

然后.tag 里就可以用了,例如:

今天=today()
echo 今天是:`今天`

@kensoh 在同时编写 .tag 和 .js 时,因为语法不一样,例如JS字符要双引号,tsg里不需要,我弄的人都分裂了。 希望可以增加对 tagui_global.tag 的支持,这样都是用 tag语法 ,脑子能转过来。同时用2种语法写东西,对用户简直是噩梦。

kensoh commented 2 years ago

Oh, you can try rewriting the function above without using semi-colon ; and it should also work.

In JavaScript, ; is optional users can use it at the end of the line and don't use it.

For TagUI steps, since the goal is human language, definitely we cannot use it. In future iterations, maybe supporting full-stop at the end can be considered. So that users can write the steps like normal human language all in 1 line. But that is a technically challenging thing to get right, and the user benefit plus impact is not yet clear. So is low priority.

www.google.com. type q as 123[enter]. snap page to results.png.
kangyiwen commented 2 years ago

试了下,.js里不带 ;可以正常使用。

但最麻烦的,需要脑子在 js 和 tag 语法之间切换的,是写变量,例如:

js里:year+"-"+month+"-"+day Tag里:year-month-day

另外,在tag里一直用 echo,我就习惯性的在 js里也用了,刚才我找这个原因就花了十几分钟。 所以,还是希望直接在 tagui_global.tag 里写 tag 函数,而不需要写 js 语法。

kensoh commented 2 years ago

Oh, I see what you mean now. Indeed, that is true. JavaScript is standard programming language, thus double quotes or single quotes are needed to mean text. For TagUI, in order to pursue human language, there is no need for double quotes, otherwise the click step will be click "Login" which is not natural language. Unfortunately, there is still strong dependency on JavaScript for specific needs, thus those work can't be done using normal TagUI steps. CC @ruthtxh

kensoh commented 2 years ago

It is a headache which I have no solution yet, because JavaScript syntax is opposite of TagUI human language syntax.

kangyiwen commented 2 years ago

如果需要2个语法融合,这太难了,目前只是希望自定义函数用tag语法。 增加启动加载 tagui_global.tag ,我这种初级开发人员就用这个文件。 同时保留加载 tagui_global.js,留给程序高手开发用。

kensoh commented 2 years ago

It is possible to define a series of TagUI steps in .tag file using the tagui step - https://tagui.readthedocs.io/en/latest/advanced.html#running-flows-within-a-flow

However, if the sequence requires data processing which needs JavaScript code, then JS code is still needed to be written. If not, using .tag files of TagUI steps can streamline commonly used sequences (eg login.tag to login to a specific website).

kangyiwen commented 2 years ago

好的,明白了 谢谢~~~

kensoh commented 2 years ago

Fyi @ruthtxh I'm passing ownership of this issue to you. Maybe for now can wait first, and see @kangyiwen assessment of writing JavaScript functions and what kind of functions. That would give you an idea whether user-created functions can be generalised enough to be committed into the main repo.

Base on the image that Yi Wen shared (https://github.com/kelaberetiv/TagUI/issues/1216#issuecomment-1110432245), I believe there is a thick category of "data-processing" functions which are not available in TagUI now but are generalised enough for rest of users. Even if implemented, it will be a huge list, so finding a way to present those functions could be challenging, given that TagUI mainly does not have menu-based IDE.

Examples from above image include (cut from left of string, return day, return month etc). All these can probably be done with 1 line of JavaScript code, but for users without programming experience, the technical barrier is likely too high to be overcome. And they are likely to be "stuck" at the simple RPA workflows and cannot do the real advance automation.

kangyiwen commented 2 years ago

@kensoh TagUI 虽然没有IDE,但有 Notepad++ 的语法插件 Snippets,我把Snippets 内 JS的内容搬给TagUI用,所以看着很丰富,但这些功能都需要梳理。

我在整理需要的功能和函数,受限于我的编程能力,还是有点慢。慢慢积累,以后函数变多,再重新分类,用起来就比较方便了。

整体: 5

4个分类:目前除了“常用命令” 其他都是JS语法 1 2 3 4

kangyiwen commented 2 years ago

用户从来不怕步骤多,就怕每一步都很理解。 只要函数封装的够简单,用 Notepad++ 当编辑器,就足够了。

kensoh commented 2 years ago

Thank you very much for sharing these thoughts and what you have created!

Copying @ruthtxh, what Yi Wen created into Notepad++ looks very cool.

ruthtxh commented 2 years ago

Hi @kensoh I have added this suggestion for our PM to review!

Cool Notepad++ snippet @kangyiwen 👍

kensoh commented 1 week ago

Closing but please ping back if this is still relevant or an issue.