Type | Kind | Description |
---|---|---|
Schema.types.string |
String | UTF-8 encoded string, up to 4000 bytes |
Schema.types.boolean |
Boolean | A logical value, must be either true or false |
Schema.types.array |
Array | An array of items (based on a type that you specify) |
Schema.types.object |
Object | A custom Javascript object, like {"site": "slack.com"} |
Schema.types.integer |
Integer | A whole number, such as -1 , 0 , or 31415926535 |
Schema.types.number |
Number | A number that allows decimal points such as 13557523.0005 |
Schema.slack.types.user_id |
Slack User ID | A Slack user ID such as U123ABC456 or W123ABC456 |
Schema.slack.types.channel_id |
Slack Channel ID | A Slack channel ID such as C123ABC456 or D123ABC456 |
Schema.slack.types.usergroup_id |
Slack User Group ID | A Slack channel ID, such as S123ABC456 |
Schema.slack.types.timestamp |
Integer | A Unix timestamp in seconds. Not compatible with Slack message timestamps - use string instead. |
Schema.slack.types.blocks |
Slack Blocks | An object that contains layout and style information about your message |
Schema.slack.types.interactivity |
Object | An object that contains context about the interactive event that led to opening of the form |
Schema.slack.types.user_context |
Object | Represents a user who interacted with a workflow at runtime |
Schema.slack.types.date |
String | A string containing a date, format is displayed as YYYY-MM-DD |
Schema.slack.types.rich_text |
Object | A way to nicely format messages in your app. This type cannot convert other message types e.g. blocks, strings |
Schema.slack.types.oauth2 |
Object | The OAuth2 context created after authenticating with external auth |
Schema.slack.types.message_context |
Object | An individual instance of a message. |
Have 2 minutes to provide some feedback?
We'd love to hear about your experience building modular Slack apps. Please complete our short survey so we can use your feedback to improve.
Declare a string
type:
// ...
{
name: "notes",
title: "Notes",
type: Schema.types.string,
},
// ...
In this example workflow, we use a string
type to allow a user to add notes about their time off request.
import { Schema } from "deno-slack-sdk/mod.ts";
import { CreateFTOWorkflow } from "../workflows/create_fto_workflow.ts";
const ftoRequestData = CreateFTOWorkflow.addStep(
Schema.slack.functions.OpenForm,
{
title: "Request dates off",
description: "Hooray for vacay!",
interactivity: CreateFTOWorkflow.inputs.interactivity,
submit_label: "Submit request",
fields: {
elements: [
{
name: "start_date",
title: "Start date",
type: Schema.slack.types.date,
},
{
name: "end_date",
title: "End date",
type: Schema.slack.types.date,
},
{
name: "notes",
title: "Notes",
description: "Anything to note?",
type: Schema.types.string,
long: true, // renders the input box as a multi-line text box on the form
},
],
required: ["start_date", "end_date"],
},
},
);
Declare a boolean
type:
// ...
isMember: {
type: Schema.types.boolean,
}
// ...
In this example datastore definition, we use a boolean
type to capture whether the message author holds membership in our club.
import { DefineDatastore, Schema } from "deno-slack-sdk/mod.ts";
export const MyDatastore = DefineDatastore({
name: "my_datastore",
primary_key: "id",
attributes: {
id: { type: Schema.types.string },
channel: { type: Schema.slack.types.channel_id },
message: { type: Schema.types.string },
author: { type: Schema.slack.types.user_id },
isMember: { type: Schema.types.boolean },
},
});
Declare an array
of types:
// ...
{
name: "departments",
title: "Your department",
type: Schema.types.array,
items: {
type: Schema.types.string,
enum: ["marketing", "design", "sales", "engineering"],
},
default: ["sales", "engineering"],
}
// ...
Fully defined arrays
Be sure to define the array's properties in the items
object. Untyped objects are not currently supported.
In this example function, we have an array of the custom type ChannelType
as both an input_parameter
and output_parameter
. See this custom type and array in action in the Deno Archive Channel sample app.
const ChannelType = DefineType(...)
export const FilterStaleChannelsDefinition = DefineFunction({
callback_id: "filter_stale_channels",
title: "Filter Stale Channels",
description:
"Filter out any channels that have received messages within the last 6 months",
source_file: "functions/filter_stale_channels.ts",
input_parameters: {
properties: {
channels: {
type: Schema.types.array,
description: "The list of Channel IDs to filter",
items: {
type: ChannelType,
},
},
},
required: ["channels"],
},
output_parameters: {
properties: {
filtered_channels: {
type: Schema.types.array,
description: "The list of stale Channel IDs",
items: {
type: ChannelType,
},
},
},
required: [],
},
});
Declare a custom object
type. Refer to custom types for more information.
// ...
properties: {
reviewer: {
type: Schema.types.object,
properties: {
login: { type: "string" },
},
},
},
// ...
In this example workflow, we notify authors about updates to their file review status.
import { DefineWorkflow, Schema } from "deno-slack-sdk/mod.ts";
export const ReviewStatusWorkflow = DefineWorkflow({
callback_id: "review_status_workflow",
title: "Review status",
description: "Review status",
input_parameters: {
properties: {
action: {
type: Schema.types.string,
},
review_request: {
type: Schema.types.object,
properties: {
number: { type: "integer" },
title: { type: "string" },
body: { type: "string" },
changed_files: { type: "integer" },
},
},
author: {
type: Schema.types.object,
properties: {
login: { type: "string" },
},
},
reviewer: {
type: Schema.types.object,
properties: {
login: { type: "string" },
},
},
},
required: ["action", "review_request", "author", "reviewer"],
},
});
Declare an integer
type:
// ...
name: "meetings",
title: "Number of meetings",
type: Schema.types.integer,
// ...
In this example workflow, we check the number of meetings we have scheduled for the day.
import { Schema } from "deno-slack-sdk/mod.ts";
import { MeetingsWorkflow } from "../workflows/meetings.ts";
const inputForm = MeetingsWorkflow.addStep(
Schema.slack.functions.OpenForm,
{
title: "Number of meetings",
interactivity: MeetingsWorkflow.inputs.interactivity,
submit_label: "Check meetings",
fields: {
elements: [
{
name: "channel",
title: "Channel to send results to",
type: Schema.slack.types.channel_id,
default: MeetingsWorkflow.inputs.channel,
},
{
name: "meetings",
title: "Number of meetings",
description: "meetings",
type: Schema.types.integer,
minimum: -1,
maximum: 5,
},
{
name: "meetingdate",
title: "Meeting date",
type: Schema.slack.types.date,
},
],
required: ["channel", "meetings", "meetingdate"],
},
},
);
Declare a number
type:
// ...
{
name: "distance",
title: "race distance",
type: Schema.types.number,
}
// ...
In this example workflow, we collect a runner's distance and date of their last run.
import { Schema } from "deno-slack-sdk/mod.ts";
import { LogRunWorkflow } from "../workflows/log_run.ts";
const inputForm = LogRunWorkflow.addStep(
Schema.slack.functions.OpenForm,
{
title: "Log a run",
interactivity: LogRunWorkflow.inputs.interactivity,
submit_label: "Log run",
fields: {
elements: [
{
name: "channel",
title: "Channel to send logged run to",
type: Schema.slack.types.channel_id,
default: LogRunWorkflow.inputs.channel,
},
{
name: "distance",
title: "Distance (in miles)",
type: Schema.types.number,
description: "race distance (in miles)",
minimum: 0,
maximum: 26.2,
},
{
name: "rundate",
title: "Run date",
type: Schema.slack.types.date,
},
],
required: ["channel", "distance", "rundate"],
},
},
);
Declare a user_id
type:
// ...
{
name: "runner",
title: "Runner",
type: Schema.slack.types.user_id,
}
// ...
In this example workflow, we get a runner's ID and the distance of their logged run.
import { Schema } from "deno-slack-sdk/mod.ts";
import { RunWorkflow } from "../workflows/run.ts";
const inputForm = RunWorkflow.addStep(
Schema.slack.functions.OpenForm,
{
title: "Log your run",
interactivity: RunWorkflow.inputs.interactivity,
submit_label: "Submit",
fields: {
elements: [
{
name: "channel",
title: "Channel to send entry to",
type: Schema.slack.types.channel_id,
default: RunWorkflow.inputs.channel,
},
{
name: "runner",
title: "Runner",
type: Schema.slack.types.user_id,
},
{
name: "distance",
title: "Distance (in miles)",
type: Schema.types.number,
},
],
required: ["channel", "runner", "distance"],
},
},
);
Declare a channel_id
type:
// ...
input_parameters: {
properties: {
interactivity: {
type: Schema.slack.types.interactivity,
},
channel: {
type: Schema.slack.types.channel_id,
},
},
},
// ...
In this example workflow definition, we enable users to send a greeting to a specific channel.
import { DefineWorkflow, Schema } from "deno-slack-sdk/mod.ts";
export const GreetingWorkflow = DefineWorkflow({
callback_id: "greeting_workflow",
title: "Send a greeting",
description: "Send a greeting to channel",
input_parameters: {
properties: {
interactivity: { type: Schema.slack.types.interactivity },
channel: { type: Schema.slack.types.channel_id },
},
required: ["interactivity"],
},
});
Declare a usergroup_id
type:
// ...
attributes: {
usergroup_id: {
type: Schema.slack.types.usergroup_id,
},
},
// ...
In this example datastore definition, we store work shift details for a team.
import { DefineDatastore, Schema } from "deno-slack-sdk/mod.ts";
export const MyShifts = DefineDatastore({
name: "shifts",
primary_key: "id",
attributes: {
id: { type: Schema.types.string },
team_id: { type: Schema.types.string },
channel: { type: Schema.slack.types.channel_id },
usergroup_id: { type: Schema.slack.types.usergroup_id },
shiftRotation: { type: Schema.types.string },
},
});
Declare a timestamp
type:
// ...
inputs: {
currentTime: {
value: "{{data.trigger_ts}}",
type: Schema.slack.types.timestamp,
},
},
// ...
In this example trigger, we call a workflow that logs an incident and the time it occurred.
import { DefineWorkflow, Schema } from "deno-slack-sdk/mod.ts";
import { Trigger } from "deno-slack-api/types.ts";
export const MyWorkflow = DefineWorkflow({
callback_id: "my_workflow",
title: "My workflow",
input_parameters: {
properties: {
currentTime: { type: Schema.slack.types.timestamp },
interactivity: { type: Schema.slack.types.interactivity },
},
required: [],
},
});
export const incidentTrigger: Trigger<typeof MyWorkflow.definition> = {
type: "shortcut",
name: "Log an incident",
workflow: `#/workflows/${MyWorkflow.definition.callback_id}`,
inputs: {
currentTime: { value: "{{data.trigger_ts}}" },
interactivity: { value: "{{data.interactivity}}" },
},
};
Declare a Block Kit JSON object type. You can use handmade Block Kit JSON objects, or those built with the Block Kit builder.
// ...
properties: {
forecast: {
type: Schema.slack.types.blocks,
},
},
// ...
In this example function, we get the current weather forecast.
import { DefineFunction, Schema } from "deno-slack-sdk/mod.ts";
export const ForecastFunctionDefinition = DefineFunction({
callback_id: "get_forecast",
title: "Weather forecast",
description: "A function to get the weather forecast",
source_file: "functions/weather_forecast.ts",
input_parameters: {
properties: {
city: {
type: Schema.types.string,
description: "City",
},
country: {
type: Schema.types.string,
description: "Country",
},
state: {
type: Schema.types.string,
description: "State",
},
},
required: ["city"],
},
output_parameters: {
properties: {
forecast: {
type: Schema.slack.types.blocks,
description: "Weather forecast",
},
},
required: ["forecast"],
},
});
Declare the interactivity
type:
// ...
properties: {
interactivity: {
type: Schema.slack.types.interactivity,
},
},
// ...
In this example workflow, we specify that it is an interactive workflow.
import { DefineWorkflow, Schema } from "deno-slack-sdk/mod.ts";
const GreetingWorkflow = DefineWorkflow({
callback_id: "greeting_workflow",
title: "Send a greeting",
description: "Send a greeting to channel",
input_parameters: {
properties: {
interactivity: { type: Schema.slack.types.interactivity },
channel: { type: Schema.slack.types.channel_id },
},
required: ["interactivity"],
},
});
Declare the user_context
type:
// ...
input_parameters: {
properties: {
person_reporting_bug: {
type: Schema.slack.types.user_context,
description: "Which user?",
},
},
},
// ...
In this example workflow, we use the Schema.slack.types.user_context
type to report a bug in a system and to collect the reporter's information.
import { DefineWorkflow, Schema } from "deno-slack-sdk/mod.ts";
const ReportBugWorkflow = DefineWorkflow({
callback_id: "report_bug",
title: "Report a Bug",
description: "Report a bug",
input_parameters: {
properties: {
channel_id: {
type: Schema.slack.types.channel_id,
description: "Which channel?",
},
person_reporting_bug: {
type: Schema.slack.types.user_context,
description: "Which user?",
},
},
required: ["person_reporting_bug"],
},
});
import { CreateBugFunction } from "../functions/create_bug.ts";
ReportBugWorkflow.addStep(
CreateBugFunction,
{
title: "title",
summary: "summary",
urgency: "S0",
channel_id: ReportBugWorkflow.inputs.channel_id,
creator: ReportBugWorkflow.inputs.person_reporting_bug,
},
);
Declare a date
type:
// ...
fields: {
elements: [
{
name: "date",
title: "Date Posted",
type: Schema.slack.types.date,
},
],
},
// ...
In this example workflow, a form requires a date
as input, which is printed along with the message after the form is submitted.
import { DefineWorkflow, Schema } from "deno-slack-sdk/mod.ts";
const TestReverseWorkflow = DefineWorkflow({
callback_id: "test_reverse",
title: "Test reverse",
input_parameters: {
properties: {
channel: { type: Schema.slack.types.channel_id },
interactivity: { type: Schema.slack.types.interactivity },
},
required: ["interactivity"],
},
});
const formData = TestReverseWorkflow.addStep(Schema.slack.functions.OpenForm, {
title: "Reverse string form",
submit_label: "Submit form",
description: "Submit a string to reverse",
interactivity: TestReverseWorkflow.inputs.interactivity,
fields: {
required: ["channel", "stringInput", "date"],
elements: [
{
name: "stringInput",
title: "String input",
type: Schema.types.string,
},
{
name: "date",
title: "Date Posted",
type: Schema.slack.types.date,
},
{
name: "channel",
title: "Post in",
type: Schema.slack.types.channel_id,
default: TestReverseWorkflow.inputs.channel,
},
],
},
});
import { ReverseFunction } from "../functions/reverse.ts";
const reverseStep = TestReverseWorkflow.addStep(ReverseFunction, {
input: formData.outputs.fields.stringInput,
});
// Add the date parameter as a step in your workflow. The message and date will be printed side by side.
TestReverseWorkflow.addStep(Schema.slack.functions.SendMessage, {
channel_id: formData.outputs.fields.channel,
message: reverseStep.outputs.reverseString + " " +
formData.outputs.fields.date,
});
Declare a rich_text
type:
// ...
elements: [
{
name: "formattedStringInput",
title: "String input",
type: Schema.slack.types.rich_text,
},
],
// ...
In this example workflow, we collect a formatted message from the user using the rich_text
type.
import { DefineWorkflow, Schema } from "deno-slack-sdk/mod.ts";
const TestWorkflow = DefineWorkflow({
callback_id: "test",
title: "Test",
input_parameters: {
properties: {
channel: { type: Schema.slack.types.channel_id },
interactivity: { type: Schema.slack.types.interactivity },
},
required: ["interactivity"],
},
});
const formData = TestWorkflow.addStep(Schema.slack.functions.OpenForm, {
title: "Send Message Form",
submit_label: "Send Message form",
interactivity: TestWorkflow.inputs.interactivity,
fields: {
required: ["channel", "formattedStringInput"],
elements: [
{
name: "formattedStringInput",
title: "String input",
type: Schema.slack.types.rich_text,
},
{
name: "channel",
title: "Post in",
type: Schema.slack.types.channel_id,
default: TestWorkflow.inputs.channel,
},
],
},
});
// To share this message object with other users, embed it into a built-in function such as SendMessage.
TestWorkflow.addStep(Schema.slack.functions.SendMessage, {
channel_id: formData.outputs.fields.channel,
message: formData.outputs.fields.formattedStringInput,
});
The message_context
type is used in the ReplyInThread
built-in function as the target message you want to reply to.
For example, let's say you have a workflow step that uses the SendMessage
function. If you want to send a reply to that message in a follow-on
step that calls the ReplyInThread
function, pass
the return value from the first step into the message_context
parameter of ReplyInThread
.
Here's a brief example:
// Send a message to channel with ID C123456
const msgStep = GreetingWorkflow.addStep(Schema.slack.functions.SendMessage, {
channel_id: "C123456",
message: "This is a message to the channel.",
});
// Send a message as an in-thread reply to the above message by passing
// the outputs' message_context property
GreetingWorkflow.addStep(Schema.slack.functions.ReplyInThread, {
message_context: msgStep.outputs.message_context,
message: "This is a threaded reply to the above message.",
});