订阅

UiPath 机器人

UiPath 机器人指南

SDK 规范

您的自定义应用程序或网页中可以包含以下方法和属性:

SDK 规范

初始化

init 方法可选。它会返回 IRobotSDK 实例,使您可以将其存储为变量以供之后使用。

UiPathRobot.init()

Get Process

Get Process 方法会检索并显示可用流程列表。如果机器人已连接到 Orchestrator,它将从机器人所属的环境和文件夹中检索流程。如果未连接到 Orchestrator,则显示本地流程。

const robot = UiPathRobot.init();
robot.getProcesses()
.then(result => {
  for(let i=0; i<result.length;i++){
    console.log(result[i].name);
  }
}, err => {
  console.log(err);
});

Start Job

Start Job 方法通过其 ID 和输入参数(如有)启动流程。

let arguments = {
  "input1" : 23,
  "input2" " 42,
  "operation" : "add"
};
const robot = UiPathRobot.init();
robot.getProcesses()
.then(process => {
  let calculatorProcess = processes.find(p => p.name.includes('Calculator'));
  let job = new job(calculatorProcess.id, arguments);
  robot.startJob(job).then(result => {
    console.log(result.Sum);
  }, err => {
    console.log(err);
  })
}, err => {
  console.log(err);
});

启动

On 方法适用于在 SDK 上附加事件处理程序。UiPath JavaScript SDK 随附内置的同意覆盖,每次您的自定义应用程序或网页需要连接到机器人时都会显示。您可以使用自定义处理程序覆盖此同意覆盖。

const robot = UiPathRobot.init();
robot.on('consent-prompt', (consentCode) => {console.log(consentCode)});
robot.on('mising-components', () => {console.log('Missing Components')});

启动流程

Process Start 方法适用于通过传递输入参数(如果可用)来启动流程。

let arguments = {
  "input1" : 23,
  "input2" " 42,
  "operation" : "add"
};
const robot = UiPathRobot.init();
robot.getProcesses()
.then(process => {
  let process = processes.find(p => p.name.includes('Calculator'));
  process.start(arguments).then(result => {
    console.log(result.Sum);
  }, err => {
    console.log(err);
  })
}, err => {
  console.log(err);
});

流程启动状态

Process Start On Status 方法适用于通过传递回调处理程序来启动流程并附加状态回调。

let arguments = {
  "input1" : 23,
  "input2" " 42,
  "operation" : "add"
};
let globalHandler = (status) => {console.log(status)};
const robot = UiPathRobot.init();
robot.getProcesses()
.then(processes => {
  let statusHandler = (status) => {console.log('Calculator Process Status -' + status)};
  let process = processes.find(p => p.name.includes('Calculator'));
  process.start(arguments)
  .onStatus(globalHandler)
  .onStatus(statusHandler)
  .then(result => {
    console.log(result.Sum);
  }, err => {
    console.log(err);
  })
}, err => {
  console.log(err);
});

Stop Process

Stop Process 方法用于停止正在执行或正在运行的机器人流程。返回一个 promise,该 promise 在成功取消正在运行的机器人流程时得到解决。

try {
  const robot = UiPathRobot.init();
  const robotProcessId = 'MyRunningRobot';
  const processes = await robot.getProcesses();
  const myProcess = processes.find(function(process){return process.name.includes(robotProcessId)});
  await robot.stopProcess(myProcess);
  console.log(robotProcessId +' cancelled successfully');
} catch (e) {
  console.log(robotProcessId +' cancellation failed -'+ e);
}

启动作业

Job On 方法适用于附加事件处理程序,以检索正在进行的流程所处的状态。

let arguments = {
  "input1" : 23,
  "input2" " 42,
  "operation" : "add"
};
const robot = UiPathRobot.init();
robot.getProcesses().then(processes => {
  let calculatorProcess = processes.find(p => p.name.includes('Calculator'));
  let job =new job(calculatorProcess.id, arguments);
  job.on('status', (robotStatus) => {console.log(robotStatus)});
  robot.startJob(job).then(result => {
    console.log(result.Sum);
  }, err => {
    console.log(err);
  })
}, err => {
  console.log(err);
});

设置

Settings 方法允许您编辑默认端口号和轮询间隔时间(以毫秒为单位)。

const robot = UiPathRobot.init();
robot.settings.portNumber = 1234;
robot.settings.pollTimeInterval = 1000

模型定义

设置

class Settings {
    portNumber: number;
    pollTimeInterval: number;
}

机器人流程

class RobotProcess {
    id: string;
    name: string;

    constructor(id: string, name: string);

    start: (inArguments?: any) => JobPromise;
}

IRobotSDK

interface IRobotSDK {
    settings: Settings;
    getProcesses(): Promise<Array<RobotProcess>>;
    init(): IRobotSDK;
    on(eventName: string, callback: (argument?: any) => void): void;
    startJob(job: Job): Promise<JobResult>;
}

作业结果

/**
 * Job result model containing all output arguments from the process.
 * Empty if there are no out arguments.
 */
class JobResult {
    [Key: string]: any;
}

作业

class Job {
    processId: string;
    argument?: any;
    jobId: string;

    constructor(processId: string, argument?: any);
    on(eventName: string, eventHanlder: (argument?: any) => void): void;
}

大约一年前更新


SDK 规范


建议的编辑仅限用于 API 参考页面

您只能建议对 Markdown 正文内容进行编辑,而不能建议对 API 规范进行编辑。