指令管理 / 请求脚本 / 指令对象
指令对象用于访问当前指令数据,例如参数,状态,配置等数据。 在脚本中可使用 $this
进行调用。
变量设置
在编辑参数时, 可以使用占位符 {{变量名}}
来获取脚本变量,从而生成动态请求参数。
以文本类型的参数为例, 假设请求内容如下:
hello {{username}}, time {{now}}
在脚本中,我们可以使用 $this.variableSet()
来设置变量 username
和 now
, 例如:
$this.variableSet("username", "sige");
$this.variableSet("now", bittly.date('%Y-%m-%d'));
那么在最终发送时数据为:
hello sige, time 2023-02-11
函数说明
$this.variableSet(<string> name, <string> value)
设置参数变量
参数
- name : [string] 变量名称
- value : [string] 变量值
状态管理
当指令发送需要依赖上次发送的数据,例如有一个指令包含一个计数器参数,计数器参数在每次发送的时候需要自动累加后再发送出去。
这样我们可以创建一个 counter
状态,在每次发送时获取 counter 状态值, 然后加1之后更新到状态,最后在参数中可以使用 {{status.counter}}
来获取状态值。
示例脚本 :
// 读取状态 "counter", 当状态不存在时默认为 "0"
let counter = $this.statusGet("counter", "0");
// counter 加 1
counter = counter * 1 + 1;
// 更新状态值
$this.statusSet("counter", counter);
发送示例
函数说明
$this.statusSet(<string> name, <string> value)
设置状态值,状态值在设置时会被自动转换为字符串类型。
参数:
- name : [string] 状态名称
- value : [string] 状态值
$this.statusGet(<string >name [, defaultVal=''])
获取状态值
参数:
- name : [string] 状态名称
- defaultVal : [string] [可选] 当状态不存在时的默认值,默认为空字符串
返回:[string] 状态值
$this.statusClear()
清空所有状态值
请求参数
在脚本中可以通过 $this.parameter
获取参数实例。 当该属性为 null
时说明该参数暂时不支持在脚本中进行处理。
对于不同参数类 $this.parameter
所支持的操作也不同,所以需要参考相应的参数类型说明文档。
内置参数处理器说明链接: