Automa使用教程之一

Automa类似RPA,无代码自动化脚本机器人

1. 请求模块的变量

如果您使用的是 v1.21.x 或更低版本 {{ keyword@path }} ,则 v1.22.x 仍支持语法
此功能允许您根据来自以下数据的数据为块设置动态值:

Name 名字Description 描述Access item 访问项目
table从表中获取数据table
variables从变量中获取数据variables.<variableName>
loopData获取 Loop Data 块的当前迭代数据loopData.<loopId>
prevBlockData获取前一个区块的数据prevBlockData
globalData获取工作流的全局数据globalData
googleSheets获取 Google 表格数据googleSheets.<referenceKey>
activeTabUrl获取活动选项卡 URLactiveTabUrl
workflow获取 Execute Workflow 模块已执行的工作流的数据(表和变量)workflow.<executeId>
Writing Expression 书写表达式

要编写表达式,必须遵循此格式“ {{ keyword }} ”;并将 替换为 keyword 上述数据源之一。它允许Automa区分静态和动态数据。

假设您在工作流中有一个变量,变量名称为 socials ;它的值是一个对象数组。您希望使用 HTTP Request 块将此变量发送到 API。

[
  { "name": "GitHub", "url": "https://github.com/AutomaApp" },
  { "name": "Twitter", "url": "https://twitter.com/AutomaApp" },
  { "name": "Discord", "url": "https://discord.gg/C6khwwTE84" }
]

您可以在 HTTP Request 块正文中使用以下表达式:

{{variables.socials}}

例子

Functions 功能

所有内置函数始终以前缀 $ 开头;例如, $funcName(param) ;以下是 Automa 中可用函数的参考列表。

$date(date, dateFormat?)

获取日期或设置日期格式。此函数采用两个参数,第二个参数是可选的。

如果要格式化当前日期,可以直接将 dateFormat 作为第一个参数传递,例如 {{ $date('DD-MMMM-YYYY') }} ,输出将为 14-January-2022 。在day.js页面上查看所有可用的日期格式。

例子

$date("DD MMMM YYYY") // 14 January 2022
$date("DD-MM-YYYY, hh:mm A")  // 14-01-2022, 02:24 PM
$date("relative") // A few seconds ago
$date("timestamp") // 1651118110948

$date("2005-06-07", "DD MMMM YYYY") // 07 June 2005
$date("1977-04-01T14:00:30", "DD-MM-YYYY, hh:mm A")  // 01-04-1977, 02:00 PM
$date("14 January 2021", "relative") // A year ago
$date("14 January 2021", "timestamp") // 1610553600000
$randint(min?, max?)

生成一个随机数。您可以通过输入 min and max 参数来更改随机数的范围。

例子

$randint() // 30
$randint() // 14

$randint(0, 10) // 4
$randint(0, 10) // 7

####### $getLength(str)
获取字符串或数组的长度。

例子

// Get the length of a string
$getLength("testing") // 7

// Get tabel length
$getLength([table]) // 14

// Get the length of the "text" column on the second row
$getLength([table.1.text]) // 5
$randData(expression)

一个用于生成随机数据的函数,您只需要将表达式传递给其参数。例如, $randData("?l") 将生成一个随机的小写字母,如 a 。支持的表达式:

  • ?l: lowercase ?l :小写
  • ?u: uppercase ?u :大写
  • ?d: digit ?d :数字
  • ?f: uppercase + lowercase
    ?f :大写 + 小写
  • ?s: symbol ?s :象征
  • ?m: uppercase + digit
    ?m :大写 + 数字
  • ?n: lowercase + digit
    ?n :小写字母 + 数字
  • ?a: any ?a :任何

您还可以组合这些表达式,例如 $randData("?u?l?l?l?l?d?d@gmail.com") which 将生成 Apond89@gmail.com

例子

$randData("?d?d") // 89

$randData("?l?l?l?d?d@gmail.com") // wal29@gmail.com

$randData("?d?u?s?l?l?s?a?m") // 4C%ee^MF9

####### $multiply(value, multiplyBy)
用于将值相乘。

例子

$multiply(5, 2) // 10

// Multiply a variable
$multiply([variables.variableName], 0.3) //20.7
$increment(value, incrementBy)

用于递增值。
例子

$increment(10, 2) // 12

$increment(72, 2) // 74
$divide(value, incrementBy)

用于除以值。

Examples 例子

$divide(22, 7) // 3.142857142857143

$divide(10, 2) // 5
$subtract(value, incrementBy)

用于减去值。

Examples 例子

$subtract(80, 7) // 73

$subtract(11, 2) // 9
$replace(value, search, replace)

用于替换字符串,从值搜索要替换的字符串。

Examples 例子

$replace("hello world!", "world", "everyone") // hello everyone!

$replace("hello world!", "hello", "hi") // hi world!
$replaceAll(value, search, replace)

用于替换所有匹配的字符串,从值中搜索以替换字符串。

Examples 例子

$replace("hello world!", "o", "0") // hell0 w0rld

$replace("The temperature is 25 degrees today", " ", "") // Thetemperatureis25degreestoday
$toLowerCase(value)

用于将值小写。

Examples 例子

$toLowerCase("HELLO WORLD!") // hello world!

$toLowerCase("hELLO wORLD!") // hello world!
$toUpperCase(value)

用于将值大写。

Examples 例子

$toUpperCase("hello world!") // HELLO WORLD!

$toUpperCase("hELLO wORLD!") // HELLO WORLD!
$modulo(num, divisor)

返回除法的余数或已签名的余数。

Examples 例子

$modulo(13, 5) // 3

$modulo(-13, 5) // -3

$modulo(4, 2) // 0

$modulo(-4, 2) // -0
$filter(data, syntax)

过滤/查询 javascript 对象。Automa 正在使用 JSONPath 库进行查询。

  • data: Javascript object to query
    data :要查询的 Javascript 对象
  • syntax: JSONPath Syntax
    syntax :JSONPath 语法

Examples 例子
以这些作为值查询 colors 变量:

[
	{ color: "red", value: "#f00" },
	{ color: "green", value: "#0f0" },
	{ color: "blue", value: "#00f" },
	{ color: "cyan", value: "#0ff" },
	{ color: "magenta", value: "#f0f" },
	{ color: "yellow", value: "#ff0" },
	{ color: "black", value: "#000" }
]
{{ $filter([variables.colors], "$..color") }}
// ['red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'black']

{{ $filter([variables.colors], "$..value") }}
// ['#f00', '#0f0', '#00f', '#0ff', '#f0f', '#ff0', '#000']

使用 JS 表达式

!!{{ $filter(variables.colors, "$..color") }}
// ['red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'black']

!!{{ $filter(variables.colors, "$..value") }}
// ['#f00', '#0f0', '#00f', '#0ff', '#f0f', '#ff0', '#000']
$stringify(value)

将 JavaScript 值转换为 JSON 字符串。

2. JavaScript模块
automaNextBlock(data, insert?)

您可以在代码中调用多个内置函数

automaNextBlock(
	data?: Object | Object[], 
	insert?: boolean | { insert?: boolean; nextBlockId?: string; replaceTable?: boolean }
): void;

insert :是否在表中插入数据。
nextBlockId :一个字符串,指定要导航到的下一个块的 ID。
replaceTable :将工作流表的值替换为在第一个参数上传递的值。
例子

automaNextBlock({ title: 'Something', count: 200 });

//or

automaNextBlock([{ title: 'Foo', count: 300 }, { title: 'Bar', count: 200 }])

// Continue execution to a specific block
automaNextBlock({ title: 'Hello' }, { nextBlockId: '4dxcxa3' })

automaSetVariable(name, value)

设置工作流变量的值。
例子

automaSetVariable('name', 'John Doe');

automaSetVariable('prices', [200, 1000, 4000, 900, 200]);

automaSetVariable('profile', { firstName: 'John', lastName: 'Doe' });
automaRefData(keyword, path)

使用此函数可以访问工作流数据,例如表、变量等。
例子

// Get the first row of the table
const firstRow = automaRefData('table', '0');

// Get the last row of the table
const firstRow = automaRefData('table', '$last');

// Get the "name" column on the first row of the table
const firstRow = automaRefData('table', '0.name');

// Get the global data of the workflow
const globalData = automaRefData('globalData');

// Get the iteration data of the loop data block
const data = automaRefData('loopData', 'loopId');

// Get the value of the "text" variable
const value = automaRefData('variables', 'text');
automaFetch(type, resource)

在扩展后台发出 HTTP 请求,使用它来避免 CORS。

  • type :请求的响应类型。可能的值 text & json ;
  • resource :您希望获取的资源
    例子
automaFetch('json', { url: 'https://api.example.com'}).then((result) => {
	console.log(result);
})

automaFetch('json', {
	url: 'https://api.example.com',
	method: 'POST',
	body: JSON.stringify({
		title: 'Hello world',
	}),
})
  • 11
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: AutoMA(自动运维管理系统)是一种用于管理和自动化IT运维流程的工具。它可以帮助组织更高效地管理软件和硬件资源,并减少人工干预。 AutoMA可以实现以下功能: - 资产管理:自动发现网络中的设备,并跟踪其配置和状态。 - 监控:通过收集系统性能数据和事件日志来监控网络和服务的健康状况。 - 自动化:通过设置规则和工作流来自动执行常见运维任务,如软件升级和故障恢复。 - 报告:生成关于网络和服务性能的报告,以帮助管理员了解和解决问题。 AutoMA通常作为一个独立的软件系统运行,但也可以作为其他IT管理工具的插件或模块使用。 ### 回答2: Automa是一个功能强大且易于使用的Python库,用于自动化Web浏览器和桌面应用程序的交互。它可以模拟用户在浏览器中的操作,例如点击链接、填写表单、提交数据等。 Automa的使用非常简单。首先,需要安装Automa库。可以通过pip命令在命令行中输入“pip install automa”来安装。安装完成后,可以在Python代码中导入Automa库并创建一个Automa对象。 创建Automa对象后,可以使用对象的方法来模拟浏览器操作。例如,可以使用click()方法来点击链接或按钮,可以使用type()方法来填写文本字段,可以使用submit()方法来提交表单等。 Automa还提供了一些其他有用的方法,例如wait()方法可以使程序等待一段时间,直到某个元素出现在页面上;find()方法可以通过选择器查找页面上的元素。这些方法可以帮助我们在自动化的过程中进行条件判断和元素定位。 Automa还支持与桌面应用程序的交互。可以使用类似的方法来模拟鼠标点击、键盘输入等操作。通过与桌面应用程序的交互,可以实现一些复杂的自动化任务,例如自动打开应用程序、执行特定的操作、截取屏幕截图等。 总之,Automa是一个非常实用的自动化工具,可以帮助开发人员简化Web浏览器和桌面应用程序的自动化任务。它提供了简洁的API和丰富的功能,使得自动化任务变得更加容易实现和维护。无论是简单的浏览器操作还是复杂的桌面应用程序交互,Automa都可以提供有效的解决方案。 ### 回答3: Automa 是一种自动化工具,用于在 Windows 操作系统下进行图形用户界面 (GUI) 的自动化操作。它可以模拟用户的键盘输入和鼠标操作,实现自动执行重复任务或自动化测试。下面是 Automa 的详细介绍。 Automa 的主要特点包括以下几个方面: 1. 简单易用:Automa 提供简洁直观的 API,使得编写自动化脚本变得简单和容易上手。即使是没有编程经验的用户也可以快速上手。 2. 图形界面操作:Automa 可以模拟各种鼠标点击、移动、拖拽等操作,同时支持键盘输入,可以实现对 GUI 界面的完全模拟操作。 3. 文本识别:Automa 提供文本识别功能,可以识别图像中的文本,实现自动化文本操作,例如自动填写表单、读取文本内容等。 4. 图像识别:Automa 还提供图像识别功能,可以通过识别特定的图像区域来实现自动化操作。这对于处理一些没有文字标识的 GUI 界面非常有用。 5. 自动化测试:Automa 可以用于自动化测试,可以记录用户的操作序列并自动生成测试脚本,以便重复执行测试,节省时间和精力。 6. 多语言支持:Automa 支持多种编程语言,包括 Python、C#、Java 等,方便开发人员根据自己的喜好选择合适的语言进行开发。 总的来说,Automa 是一个功能强大且易于使用的自动化工具,可以帮助用户自动执行重复的任务和自动化测试。无论是普通用户还是开发人员,都可以通过 Automa 来提高工作效率,节省时间和精力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值