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

Slack API methods

While building your Run On Slack functions, you can access and make calls to the Slack API via the client prop.

First, add the client context property to your SlackFunction:

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

export const ExampleFunctionDefinition = DefineFunction({
  callback_id: "example_function_def",
  title: "Example function",
  source_file: "functions/example_function.ts",
});

export default SlackFunction(
  ExampleFunctionDefinition,
  ({ inputs, client }) => { // Add `client` here

  // ...

The client prop allows you to access the Slack API in one of two ways:

  • client.<noun>.<verb> (e.g., client.chat.postMessage)
  • client.apiCall('<nounVerb>') (e.g., client.apiCall('chat.postMessage', {/* ... */});)

These API calls return a promise, so be sure to await their responses.

For example, let's send Hello World to channel C123456:

// functions/example_function.ts
import { DefineFunction, Schema, SlackFunction } from "deno-slack-sdk/mod.ts";
import { SlackAPI } from "deno-slack-api/mod.ts"; // Add this

export const ExampleFunctionDefinition = DefineFunction({
  callback_id: "example_function_def",
  title: "Example function",
  source_file: "functions/example_function.ts",
  input_parameters: {
    properties: {
      some_channel: {
        type: Schema.slack.types.channel_id,
        description: "Example channel ID",
      },
      some_string: {
        type: Schema.types.string,
        description: "Example string",
      },
    },
    required: [],
  }
});

export default SlackFunction(
  ExampleFunctionDefinition,
  async ({ inputs, client }) => { // Note the addition of `async` here

    let response = await client.chat.postMessage({
      channel: "C123456",
      text: "Hello World"
    });

    // Remember: you can bring in values from the function's inputs (defined 
    // in the function's source file)

    // Option #1: use client.apiCall(<method name>)
    await client.apiCall('chat.postMessage', {
      channel: inputs.some_channel,
      text: `You said "${inputs.some_string}"`
    });

    // Option #2: use client.methodGroup.method
    await client.chat.postMessage({
      channel: inputs.some_channel,
      text: `You said "${inputs.some_string}"`
    });
  
    // ...

Most API endpoints require specific permission scopes. Add scopes to your app by listing them in the botScopes property of your manifest.

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.