The new Slack platform is in beta. Your feedback is most welcome.

Webhook Triggers

Invoke a Workflow when a specific URL receives a POST request

Webhook Triggers are an automatic type of Trigger that listens for a certain type of data, much like Event Triggers.

While Event Triggers are used for activating a Trigger based on internal activity, webhooks are instead used when activating a Trigger based on external activity. In other words, Webhook Triggers are useful when tying Slack functionality together with non-Slack services.

There are three steps to using a Webhook Trigger:

  1. Define the Trigger
  2. Create the Trigger, either via the CLI or at runtime
  3. Invoke the Trigger with a POST Request

1. Define the Trigger

A Trigger contains a Typescript payload with the following parameters:

Parameters

Field Description Required
type The type of Trigger: webhook
name The name of the Trigger
workflow Path to Workflow that the Trigger initiates
description The description of the Trigger
inputs The inputs provided to the Workflow
webhook Contains filter, if desired
webhook.filter See Trigger Filters

Example TypeScript payload

The following is a TypeScript payload for creating a Webhook Trigger:

  type: "webhook",
  name: "sends 'how cool is that' to my fav channel",
  description: "runs the example workflow",
  workflow: "#/workflows/myWorkflow",
  inputs: {
    stringToReverse: {
      value: "how cool is that",
    },
    channel: {
      value: "{{data.channel}}",
    },
  }

2. Create the Webhook Trigger

There are two ways to create a Webhook Trigger. You can:

Create a Webhook Trigger with the CLI

To create a Webhook Trigger with the CLI, you'll need to create a trigger file. The trigger file contains the payload you used to define your Trigger.

TypeScript trigger files take the following form:

import { Trigger} from “deno-slack-api/types.ts”;

const trigger : Trigger<typeof ExampleWorkflow.definition> = {
  // your TypeScript payload 
}

export default trigger;

Once you have created a trigger file, use the following command to create the Webhook Trigger:

slack trigger create --trigger-def "path/to/trigger.ts"

Create a Webhook Trigger at runtime

Create a Webhook Trigger at runtime using the client.workflows.triggers.create method within the relevant Function file.

const triggerResponse = await client.workflows.triggers.create<typeof ExampleWorkflow.definition>({
  // your TypeScript payload
);

3. Invoke the Trigger

Send a POST request to invoke the Trigger. Within that POST request you can send values for specific inputs.

Example POST request

curl \ 
-X POST "https://hooks.slack.com/triggers/T123ABC456/.../..." \
--header "Content-Type: application/json" \
--data "{"channel":"C123ABC456"}" 

If successful, you'll get the following response:

{
  "ok":true
}