Skip to main content

addCallback(callbackKey, callbackFn)

Adds a callback function to Command AI. See this doc that talks about how callback actions work.

Example

window.CommandBar.addCallback(
"sayHi",
// Assumes an argument called "name". Args are user selected options in Spotlight
(args, context, meta) => alert(`Hi there, ${args.name}!`)
);

Attach a custom field in CB to your callback

Useful as a no-code way for teams to attach options via the CB editor to be used in the callback

window.CommandBar.addCallback("sayHi", (args, context, meta) =>
alert(`Welcome to ${meta?.source.metadata}`)
);

Method parameters

callbackKey Required

string

Key to reference the provided function

callbackFn Required

function

Callback function, with the following signature:

ArgsTypeDescription
argsobjectA dictionary of argument keys and the values entered by the user
contextobjectA dictionary reflecting the state of context when the callback was triggered by an action being executed
metaobjectA dictionary containing any custom meta fields supplied via the CB Action