robot
2023.10
false
- Robot JavaScript SDK
重要 :
新发布内容的本地化可能需要 1-2 周的时间才能完成。

Robot 开发者指南
上次更新日期 2025年9月10日
SDK 规范
link方法和属性
link您可以在自定义应用程序或网页中包含以下方法和属性。
初始化
linkinit
方法可选。它会返回 IRobotSDK 实例,使您可以将其存储为变量以供之后使用。
const robot = UiPathRobot.init();
const robot = UiPathRobot.init();
设置
link“设置”类型的
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;
同意提示
link每次您的自定义应用程序或网页需要连接到机器人时,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));
缺少组件
link当机器人 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'));
open-uipath-protocol
linkBefore being shown the consent prompt you might be asked to allow the browser to open a uipath-web URL in the associated application.
By default, RobotJS will automatically try to open this URL, but users can override this behavior by providing a custom event handler.
const robot = UiPathRobot.init();
robot.on('open-uipath-protocol', (protocolUrl) => console.log('RobotJS protocol URL: ' + protocolUrl));
const robot = UiPathRobot.init();
robot.on('open-uipath-protocol', (protocolUrl) => console.log('RobotJS protocol URL: ' + protocolUrl));
获取进程
linkgetProcesses
方法检索可用流程的列表。 将 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);
}
获取输入参数架构
link通过使用已安装流程的
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();
开始作业
linkcreateJob
方法使用流程 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);
启动作业
linkJob
对象的on
方法用于将事件处理程序附加到作业。 可用的事件为status
和workflow-event
。
状态
link每次作业状态发生更改时,都会在作业执行期间引发
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);
工作流事件
link每次执行发送工作流事件的活动时,在作业执行期间都会引发
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);
启动进程
link对象 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);
流程开启状态
linkonStatus
方法用于将事件处理程序附加到作业的“状态”事件。
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));
处理工作流事件
linkonWorkflowEvent
方法用于将事件处理程序附加到作业的“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));
停止流程
linkstopProcess
方法用于停止正在执行的机器人流程。
它返回一个承诺,该承诺在成功取消正在运行的机器人流程后得到解决。
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);
模型定义
linkIRobotSDK
linkinterface 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>;
}
设置
linkclass Settings {
portNumber: number;
pollTimeInterval: number;
disableTelemetry: boolean;
}
class Settings {
portNumber: number;
pollTimeInterval: number;
disableTelemetry: boolean;
}
机器人流程
linkclass 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>;
}
安装流程结果
linkclass InstallProcessResult {
inputArgumentsSchema: InputArgumentSchema[]
}
class InstallProcessResult {
inputArgumentsSchema: InputArgumentSchema[]
}
输入参数架构
linkclass InputArgumentSchema {
name: string;
type: string;
isRequired: boolean;
hasDefault: boolean;
}
class InputArgumentSchema {
name: string;
type: string;
isRequired: boolean;
hasDefault: boolean;
}
工作承诺
linkclass 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;
}
作业
linkclass 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;
}
作业结果
linkclass JobResult {
[Key: string]: any;
}
class JobResult {
[Key: string]: any;
}
工作流事件数据
linkclass WorkflowEventData {
name: string;
payload: string;
}
class WorkflowEventData {
name: string;
payload: string;
}