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 | 获取活动选项卡 URL | activeTabUrl |
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',
}),
})