Command Response
A JSON-encoded data structure used to describe the behavior and UI of a Slapdash command.
A command should return a JSON that tells what the Command Bar should show or do. The JSON needs to conform to a certain format, which can be described with the TypeScript definition below.
1
interface CommandResponse {
2
/**
3
* Optional.
4
* A side effect of the Command when it's run.
5
*/
6
action?: Action;
7
8
/**
9
* Optional.
10
* The View the Command Bar should display
11
* (List, Form etc.).
12
*/
13
view?: View;
14
15
/**
16
* Optional.
17
* A way to configure the command before it can
18
* be used. For example, to collect an API key.
19
*/
20
config?: Config;
21
22
/**
23
* Optional.
24
* A way to customize how Command Bar tokens
25
* that are visualized.
26
*/
27
tokens?: Token[];
28
29
/**
30
* Optional.
31
* The placeholder text in the Command Bar's input.
32
*/
33
inputPlaceholder?: string;
34
}
Copied!

Quick Examples

The simplest way to experiment with commands is to copy one of the examples below to a file with *.js extension and then create a Local Command in the Slapdash desktop app.
Open URL Action
List View
Masonry View
Form View
Custom Config
1
// https://github.com/slapdash/platform/blob/main/docs/reference/open-url.js
2
console.log(
3
JSON.stringify({
4
action: {
5
type: "open-url",
6
url: "https://slapdash.com/",
7
},
8
})
9
);
Copied!
When selected in the Command Bar, the command just opens a particular URL in the browser:
1
// https://github.com/slapdash/platform/blob/main/docs/reference/list-view.js
2
console.log(
3
JSON.stringify({
4
view: {
5
type: "list",
6
options: [
7
{
8
title: "Open Google",
9
action: {
10
type: "open-url",
11
url: "https://www.google.com/",
12
},
13
},
14
{
15
title: "Open Bing",
16
action: {
17
type: "open-url",
18
url: "https://www.bing.com/",
19
},
20
},
21
],
22
},
23
})
24
);
Copied!
The command shows the list of options. Each option has an associated Action (in this example, the actions are to open URLs):
1
// https://github.com/slapdash/platform/blob/main/docs/reference/masonry-view.js
2
console.log(
3
JSON.stringify({
4
view: {
5
type: "masonry",
6
options: [
7
{
8
imageURL:
9
"https://images.unsplash.com/photo-1481819613568-3701cbc70156",
10
action: {
11
type: "copy",
12
value: "Moon",
13
},
14
},
15
{
16
imageURL:
17
"https://images.unsplash.com/photo-1614642264762-d0a3b8bf3700",
18
action: {
19
type: "copy",
20
value: "Sun",
21
},
22
},
23
{
24
imageURL:
25
"https://images.unsplash.com/photo-1512361180836-1ecddb33f2dd",
26
action: {
27
type: "copy",
28
value: "Sky",
29
},
30
},
31
],
32
},
33
})
34
);
Copied!
Similar to the List View, but shows the images in a Masonry grid:
1
// https://github.com/slapdash/platform/blob/main/docs/reference/form-view.js
2
console.log(
3
JSON.stringify({
4
view: {
5
type: "form",
6
title: "Order Drink",
7
submitLabel: "Order",
8
fields: [
9
{
10
type: "text",
11
id: "name",
12
label: "Your Name",
13
},
14
{
15
type: "select",
16
id: "drink",
17
label: "Drink",
18
options: ["Cappuccino", "Latte", "Green Tea", "Coke"],
19
},
20
],
21
},
22
})
23
);
Copied!
The command shows a form and allows the user to enter some data. When the form is submitted, the command is run again, and the entered data is passed as JSON to its STDIN.
1
// https://github.com/slapdash/platform/blob/main/docs/reference/custom-config.js
2
console.log(
3
JSON.stringify({
4
config: {
5
form: {
6
fields: [
7
{
8
type: "text",
9
id: "api-key",
10
label: "API Key",
11
placeholder: "GIPHY API key",
12
},
13
],
14
},
15
},
16
})
17
);
Copied!
Emitting config property allows the command to request some private configuration data from the user when it is first executed. Later, the configuration is passed back to the command via process environment variables.
Last modified 1mo ago
Copy link