The new Slack platform and the features described below are in beta and under active development.

Custom types

Custom types provide a way to introduce reusable, sharable types to your Run On Slack apps. Once registered in your manifest, you can use custom types as input or output parameters in any of your app's functions, workflows, or datastores. The possibilities are endless!

Defining a type

Types can be defined with a top level DefineType export. In the example below, a custom type object is defined as a template for incident reporting:

const IncidentType = DefineType({
  title: "Incident Ticket",
  description: "Use this custom type for creating an Incident Ticket",
  name: "Name",
  type: Schema.types.object,
  properties: {
    id: {
      type: Schema.types.string,
      minLength: 3,
    },
    title: {
      type: Schema.types.string,
    },
    summary: {
      type: Schema.types.string,
    },
    severity: {
      type: Schema.types.string,
    },
  },
  required: [],
});

Types can also be both defined and then used inside of a function:

import { DefineFunction, DefineType, Schema } from "deno-slack-sdk/mod.ts";

export const IncidentType = DefineType("incidentTicket", {
  type: Schema.types.object,
  properties: {
    id: {
      type: Schema.types.string,
      minLength: 3,
    },
    title: {
      type: Schema.types.string,
    },
    summary: {
      type: Schema.types.string,
    },
    severity: {
      type: Schema.types.string,
    },
  },
});

export const IncidentFunction = DefineFunction({
  callback_id: "incident_function",
  title: "Create an Incident Ticket",
  description: "Creates an Incident Ticket",
  source_file: "functions/incident_function.ts",
  input_parameters: {
    properties: {
      incident: {
        type: IncidentType,
        description: "The incident details",
      },
      reporter: {
        type: Schema.slack.types.user_id,
        description: "The user ID of the person who created the incident ticket",
      },
    },
    required: ["incident"],
  }
});
// ...

Registering a type

To register newly-defined types for use with your app, add them to the types array when defining your manifest.

All custom types must be registered in the manifest for them to be available for use.

import { Manifest } from "deno-slack-sdk/mod.ts";

export default Manifest({
  name: "incident-manifest",
  description: "Create an incident ticket",
  icon: "assets/incident_icon.png",
  outgoingDomains: [],
  types: [IncidentType],
  botScopes: [
    "commands", 
    "chat:write", 
    "chat:write.public",
    "triggers:write"
    ],
});

Referencing a type

To use a custom type as a function parameter, import the type:

import { DefineFunction, DefineType, Schema } from "deno-slack-sdk/mod.ts";
// ...

Then, set the parameter's type property to the custom type it should reference:

// ...
input_parameters: {
  incident: {
    title: "A String Cheese Incident",
    type: IncidentType,
  }
},
// ...

In the example above, the title property from the custom type IncidentType is being overridden with the string "A String Cheese Incident".

Have 2 minutes to provide some feedback?

We'd love to hear about your experience with the new Slack platform. Please complete our short survey so we can use your feedback to improve.