Our future generation platform is in closed beta. During the beta, expect some rough edges, broken windows overlooking blue sky vistas, and regularly scheduled changes.

Already signed up? Great! You can ignore this.
Need to sign up? Apply to join the beta.

Calling Slack API methods

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

To do this, you will:

  1. Import the API library
  2. Add token to your function handler
  3. Instantiate a Slack API client object
  4. Make an API call

1. Import the API library

The first step in making API calls in your Run On Slack functions is to import the API library:

import type { FunctionHandler } from "deno-slack-sdk/types.ts";
import { SlackAPI } from "deno-slack-api/mod.ts"; // Add this

2. Add token to your function handler

The next step is to add the token helper to your function handler:

import type { FunctionHandler } from "deno-slack-sdk/types.ts";
import { SlackAPI } from "deno-slack-api/mod.ts";

const reverse: FunctionHandler<any, any> = async (
  { inputs, env, token }, // Add `token` here
) => {
  
  // ...

3. Instantiate a Slack API client

Then, instantiate the Slack API client by passing along the token helper:

import type { FunctionHandler } from "deno-slack-sdk/types.ts";
import { SlackAPI } from "deno-slack-api/mod.ts";

const reverse: FunctionHandler<any, any> = async (
  { inputs, env, token }, 
) => {
  
  const client = SlackAPI(token, {}); // Add this
  
  // ...

The second argument to SlackAPI is an options object; this can be empty.

4. Make an API call

Finally, make the API call using client.apiCall(...):

import type { FunctionHandler } from "deno-slack-sdk/types.ts";
import { SlackAPI } from "deno-slack-api/mod.ts";

const reverse: FunctionHandler<any, any> = async (
  { inputs, env, token }, 
) => {
  
  const client = SlackAPI(token, {});

  // Call an API method in one of two ways.

  // 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.