robot
2022.10
false
- 发行说明
- 入门指南
- UiPath Assistant
- 安装和升级
- 机器人类型
- 机器人组件
- 许可
- 将机器人连接到 Orchestrator
- 流程与活动
- 日志记录
- Robot JavaScript SDK
- 特定场景
- 故障排除
重要 :
请注意此内容已使用机器翻译进行了部分本地化。
机器人用户指南
Last updated 2024年10月25日
SDK 规范
init
方法可选。它会返回 IRobotSDK 实例,使您可以将其存储为变量以供之后使用。
const robot = UiPathRobot.init();
const robot = UiPathRobot.init();
“设置”类型的
settings
属性让您可以更改默认端口号、轮询间隔时间(以毫秒为单位),或禁用发送遥测数据。
const robot = UiPathRobot.init();
robot.settings.portNumber = 1234;
robot.settings.pollTimeInterval = 1000;
robot.settings.disableTelemetry = true;
const robot = UiPathRobot.init();
robot.settings.portNumber = 1234;
robot.settings.pollTimeInterval = 1000;
robot.settings.disableTelemetry = true;
每次您的自定义应用程序或网页需要连接到机器人时,UiPath JavaScript SDK 都会显示内置的同意叠加层。
可以使用自定义处理程序覆盖此同意覆盖。
const robot = UiPathRobot.init();
robot.on('consent-prompt', consentCode => console.log(consentCode));
const robot = UiPathRobot.init();
robot.on('consent-prompt', consentCode => console.log(consentCode));
当机器人 JS 服务未运行时,将引发
missing-components
事件。 在这种情况下,SDK 会显示一个错误,可以使用自定义处理程序覆盖该错误。
const robot = UiPathRobot.init();
robot.on('missing-components', () => console.log('Missing Components'));
const robot = UiPathRobot.init();
robot.on('missing-components', () => console.log('Missing Components'));
getProcesses
方法检索可用流程的列表。 将 Promise 返回给 RobotProcess 对象数组。 如果机器人已连接到 Orchestrator,则会从机器人所属的环境和文件夹中检索流程。 否则,将检索本地流程。
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
for(let i=0; i<processes.length; i++){
console.log(processes[i].name + " (" + processes[i].description + ") - Id=" + processes[i].id);
}
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
for(let i=0; i<processes.length; i++){
console.log(processes[i].name + " (" + processes[i].description + ") - Id=" + processes[i].id);
}
通过使用已安装流程的
inputArgumentsSchema
属性,您可以检索流程的输入参数。 使用inputArgumentsSchema
属性前,您需要先安装流程。
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const installedProcess = await robot.installProcess(processes[0].id);
for(let i=0; i<installedProcess.inputArgumentsSchema.length; i++){
console.log("Argument " + i + ":");
console.log(" name: " + installedProcess.inputArgumentsSchema[i].name)
console.log(" type: " + installedProcess.inputArgumentsSchema[i].type)
console.log(" isRequired: " + installedProcess.inputArgumentsSchema[i].isRequired)
console.log(" hasDefault: " + installedProcess.inputArgumentsSchema[i].hasDefault)
}
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const installedProcess = await robot.installProcess(processes[0].id);
for(let i=0; i<installedProcess.inputArgumentsSchema.length; i++){
console.log("Argument " + i + ":");
console.log(" name: " + installedProcess.inputArgumentsSchema[i].name)
console.log(" type: " + installedProcess.inputArgumentsSchema[i].type)
console.log(" isRequired: " + installedProcess.inputArgumentsSchema[i].isRequired)
console.log(" hasDefault: " + installedProcess.inputArgumentsSchema[i].hasDefault)
}
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const myProcess = processes.find(p => p.name === "MyProcess");
const installedProcess = await myProcess.install();
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const myProcess = processes.find(p => p.name === "MyProcess");
const installedProcess = await myProcess.install();
createJob
方法使用流程 ID 创建机器人作业。 它可以选择接收作业输入参数。 它返回一个 作业 对象。
注意:从 v2022.10 开始,流程列表会在流程执行的同时刷新,在此之前,流程列表会在流程启动之前刷新。这意味着,在运行有可用更新的流程时,作业可能会使用该流程的旧版本运行。
robot = UiPathRobot.init();
processes = await robot.getProcesses();
const calculatorProcess = processes.find(p => p.name.includes('Calculator'));
const arguments = {
"input1" : 23,
"input2" : 42,
"operation" : "add"
};
const job = robot.createJob(calculatorProcess.id, arguments);
const result = await robot.startJob(job);
console.log(result.Sum);
robot = UiPathRobot.init();
processes = await robot.getProcesses();
const calculatorProcess = processes.find(p => p.name.includes('Calculator'));
const arguments = {
"input1" : 23,
"input2" : 42,
"operation" : "add"
};
const job = robot.createJob(calculatorProcess.id, arguments);
const result = await robot.startJob(job);
console.log(result.Sum);
注意:在 TypeScript 中,可以使用 Job 类构造函数创建作业。
robot = UiPathRobot.init();
processes = await robot.getProcesses();
const calculatorProcess = processes.find(p => p.name.includes('Calculator'));
const arguments = {
"input1" : 23,
"input2" : 42,
"operation" : "add"
};
const job = new Job(calculatorProcess.id, arguments);
const result = await robot.startJob(job);
console.log(result.Sum);
robot = UiPathRobot.init();
processes = await robot.getProcesses();
const calculatorProcess = processes.find(p => p.name.includes('Calculator'));
const arguments = {
"input1" : 23,
"input2" : 42,
"operation" : "add"
};
const job = new Job(calculatorProcess.id, arguments);
const result = await robot.startJob(job);
console.log(result.Sum);
每次作业状态发生更改时,都会在作业执行期间引发
status
事件。
每次执行 ReportStatus 活动时,也会发生此事件。
const robot = UiPathRobot.init();
const job = robot.createJob('processId');
job.on('status', robotStatus => console.log(robotStatus));
await robot.startJob(job);
const robot = UiPathRobot.init();
const job = robot.createJob('processId');
job.on('status', robotStatus => console.log(robotStatus));
await robot.startJob(job);
每次执行发送工作流事件的活动时,在作业执行期间都会引发
workflow-event
事件。 它支持在“ 发送临时结果 ”活动的帮助下实施部分结果。 事件处理程序具有类型为 WorkflowEventData的参数。
const robot = UiPathRobot.init();
const job = robot.createJob('processId');
job.on('workflow-event', e => console.log(e.name));
await robot.startJob(job);
const robot = UiPathRobot.init();
const job = robot.createJob('processId');
job.on('workflow-event', e => console.log(e.name));
await robot.startJob(job);
对象 RobotProcess 的
start
方法用于通过向流程传递输入参数(如果可用)来启动流程。
该方法会返回一个 JobPromise 类型的对象。
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const myProcess = processes.find(p => p.name === "MyProcess");
const arguments = {
"a" : 41,
"b" " 27
};
const result = await myProcess.start(arguments);
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const myProcess = processes.find(p => p.name === "MyProcess");
const arguments = {
"a" : 41,
"b" " 27
};
const result = await myProcess.start(arguments);
onStatus
方法用于将事件处理程序附加到作业的“状态”事件。
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const myProcess = processes.find(p => p.name === "MyProcess");
const result = await myProcess.start().onStatus(status => console.log(status));
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const myProcess = processes.find(p => p.name === "MyProcess");
const result = await myProcess.start().onStatus(status => console.log(status));
onWorkflowEvent
方法用于将事件处理程序附加到作业的“workflow-event”事件。
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const myProcess = processes.find(p => p.name === "MyProcess");
const result = await myProcess.start().onWorkflowEvent(e => console.log(e.name));
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const myProcess = processes.find(p => p.name === "MyProcess");
const result = await myProcess.start().onWorkflowEvent(e => console.log(e.name));
stopProcess
方法用于停止正在执行的机器人流程。
它返回一个承诺,该承诺在成功取消正在运行的机器人流程后得到解决。
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const myProcess = processes.find(p => p.name === "MyProcess");
const result = await myProcess.start();
await robot.stopProcess(myProcess);
const robot = UiPathRobot.init();
const processes = await robot.getProcesses();
const myProcess = processes.find(p => p.name === "MyProcess");
const result = await myProcess.start();
await robot.stopProcess(myProcess);
interface IRobotSDK {
settings: Settings;
getProcesses(): Promise<Array<RobotProcess>>;
init(): IRobotSDK;
on(eventName: string, callback: (argument?: any) => void): void;
startJob(job: Job): Promise<JobResult>;
stopProcess(process: RobotProcess): Promise<void>;
installProcess(processId: string): Promise<InstallProcessResult>;
}
interface IRobotSDK {
settings: Settings;
getProcesses(): Promise<Array<RobotProcess>>;
init(): IRobotSDK;
on(eventName: string, callback: (argument?: any) => void): void;
startJob(job: Job): Promise<JobResult>;
stopProcess(process: RobotProcess): Promise<void>;
installProcess(processId: string): Promise<InstallProcessResult>;
}
class Settings {
portNumber: number;
pollTimeInterval: number;
disableTelemetry: boolean;
}
class Settings {
portNumber: number;
pollTimeInterval: number;
disableTelemetry: boolean;
}
class RobotProcess {
id: string;
name: string;
description?: string;
start: (inArguments?: any) => JobPromise;
install: () => Promise<InstallProcessResult>;
}
class RobotProcess {
id: string;
name: string;
description?: string;
start: (inArguments?: any) => JobPromise;
install: () => Promise<InstallProcessResult>;
}
class InstallProcessResult {
inputArgumentsSchema: InputArgumentSchema[]
}
class InstallProcessResult {
inputArgumentsSchema: InputArgumentSchema[]
}
class InputArgumentSchema {
name: string;
type: string;
isRequired: boolean;
hasDefault: boolean;
}
class InputArgumentSchema {
name: string;
type: string;
isRequired: boolean;
hasDefault: boolean;
}
class JobPromise {
onStatus(eventHanlder: (argument?: any) => void): JobPromise;
onWorkflowEvent(eventHanlder: (argument?: any) => void): JobPromise;
}
class JobPromise {
onStatus(eventHanlder: (argument?: any) => void): JobPromise;
onWorkflowEvent(eventHanlder: (argument?: any) => void): JobPromise;
}
class Job {
processId: string;
argument?: any;
jobId: string;
on(eventName: string, eventHanlder: (argument?: any) => void): void;
}
class Job {
processId: string;
argument?: any;
jobId: string;
on(eventName: string, eventHanlder: (argument?: any) => void): void;
}