Skip to content

Slack target

Sends events to the Slack through the Slack Web API.

With tmctl:

tmctl create target slack --token <token>

On Kubernetes:

Secret (using the Slack API token)

apiVersion: v1
kind: Secret
metadata:
  name: slack-tm
type: Opaque
stringData:
  token: xoxb-12345-abcde

Target

apiVersion: targets.triggermesh.io/v1alpha1
kind: SlackTarget
metadata:
  name: slack-tm
spec:
  token:
    secretKeyRef:
      name: slack-tm
      key: token

Slack target accepts events of the following types:

  • com.slack.webapi.chat.postMessage
  • com.slack.webapi.chat.scheduleMessage
  • com.slack.webapi.chat.update

These types expect a JSON payload with the following properties:

You can test the Target by sending it an event using curl.

Send Message

  • Slack docs https://api.slack.com/methods/chat.postMessage
  • Needs chat:write
curl -v http://localhost:8080 \
 -X POST \
 -H "Content-Type: application/json" \
 -H "Ce-Specversion: 1.0" \
 -H "Ce-Type: com.slack.webapi.chat.postMessage" \
 -H "Ce-Source: awesome/instance" \
 -H "Ce-Id: aabbccdd11223344" \
 -d '{"channel":"C01112A09FT", "text": "Hello from TriggerMesh!"}'

Send Scheduled Message

  • Slack docs https://api.slack.com/methods/chat.scheduleMessage
  • Use with a scheduled future epoch.
  • Needs chat:write
curl -v http://localhost:8080 \
 -X POST \
 -H "Content-Type: application/json" \
 -H "Ce-Specversion: 1.0" \
 -H "Ce-Type: com.slack.webapi.chat.scheduleMessage" \
 -H "Ce-Source: awesome/instance" \
 -H "Ce-Id: aabbccdd11223344" \
 -d '{"channel":"C01112A09FT", "text": "Hello from scheduled TriggerMesh!", "post_at": 1593430770}'

Update Message

  • Slack docs https://api.slack.com/methods/chat.update
  • Use with an existing message timestamp.
  • Needs chat:write
curl -v http://localhost:8080 \
 -X POST \
 -H "Content-Type: application/json" \
 -H "Ce-Specversion: 1.0" \
 -H "Ce-Type: com.slack.webapi.chat.update" \
 -H "Ce-Source: awesome/instance" \
 -H "Ce-Id: aabbccdd11223344" \
 -d '{"channel":"C01112A09FT", "text": "Hello from updated2 TriggerMesh!", "ts":"1593430770.001300"}'

See the Kubernetes object reference for more details.

Prerequisite(s)

  • Slack user that can manage applications
  • Pre-existing Slack App
  • Slack API token

Configuring Your Slack App

  1. Create a new Slack App.
  2. Go to Basic Information > Add features and functionality and select the Permissions pane.
  3. Under Bot Token Scopes add chat:write.
  4. From the Install App menu follow steps to deploy to your workspace.
  5. Copy the Bot OAuth Access token, it should begin with xoxb-...

The application created in Slack for this integration will need to be added to the scopes that satisfy the web API methods used (chat:write shown here). See Sending Slack Operations to determine which scopes will be required per operation.

Slack API token

A Slack API token is required to use this target. From the Install App menu, retrieve the OAuth Access token that begins with xoxb-. For more information on how to obtain one, see the Slack Developer's Guide

For more information about using the Slack API, please refer to the Slack API documentation.