Commands
The Commands API lets you expose commands of your plugin to be used by other plugins or by other Qatium components, like Q, our digital assistant.
addCommand()
Section titled “addCommand()”Allows the plugin to expose commands to be used by other components: Digital assistant (Q), other plugins, other Qatium components, etc.
Method signature
Section titled “Method signature”type CommandDescription = < Receives extends Record<string, string>, Returns extends Record<string, unknown>>{ name: string; description: string; aliases: string[]; arguments: Receives; returnType: Record<keyof Returns, string>;}
type CommandAnswer<Returns extends Record<string, unknown>> = { data: Returns; openPanel?: boolean;};
addCommand<Receives, Returns>( description: CommandDescription<Receives, Returns>, fn: (args: Record<keyof Receives, string>) => Promise<CommandAnswer<Returns>>): void
Parameters
Section titled “Parameters”-
description: CommandDescription<Receives, Returns>
:- name: The name of the command.
- description: A description of the command.
- aliases: A list of aliases for the command.
- arguments: An object describing the arguments your command will receive.
- returnType: An object describing the returned result type.
const commandDescription = {name: "Close Valves",description: "It closes valves from the network",aliases: ["shutdown valves", "close TCV", "close shut-off valves"],arguments: {numOfValves: "number of valves to close"},returnType: {valvesClosed: "how many valves the command was able to close"}} -
fn: <Receives, Returns>(args: Record<keyof Receives, string>) => Promise<CommandAnswer<Returns>>
: It will perform the command and then return aPromise<CommandAnswer>
:type CommandAnswer<Returns> = {/*** The data returned by the command.* It should match the keys in {@link CommandDescription.returnType}*/data: Returns;/*** Whether or not to open the plugin panel after the command succeeds.** @default false.*/openPanel?: boolean;};// A command that sets the demand of a junctiontype Receives = { junctionId: string; demand: string };type Returns = { junctionId: string; newDemand: string };const setJunctionDemandCommand: CommandFn<Receives, Returns> = async (args) => {const { junctionId, demand } = args;sdk.network.setDemand(junctionId, demand);return {data: {junctionId,newDemand: demand},openPanel: true,};};
Example
Section titled “Example”sdk.commands.addCommand( { name: "Set junction demand", description: "sets the demand of a junction", aliases: [ "set demand", "change demand", "increase flow in junction", "set flow in junction" ], arguments: { junctionId: "the id of the junction", demand: "the new demand of the junction" }, returnType: { junctionId: "the id of the junction", newDemand: "the new demand of the junction" } }, async (args) => { const { junctionId, demand } = args;
sdk.network.setDemand(junctionId, Number(demand));
return { data: { junctionId, newDemand: demand }, openPanel: true, }; });
availableCommands()
Section titled “availableCommands()”Returns the available commands to call. You can use this method to connect your plugin with other plugins, or with other Qatium components.
Usually you would connect two plugins you own, so they can interact with each other.
Method signature
Section titled “Method signature”availableCommands() : Command[]