Go to Slack

Making messages actionable

Use cases:
  • Export messages on Slack to external systems
  • Kick-off Slack-based workflows
  • Capture bug reports
Works with:
  • Actions
  • Dialogs
  • Internal integrations
Code samples:

This demo app allows users to export messages from Slack to a third party system (like our fictional app ClipIt). You'll write code that adds a per-message action that triggers a dialog. s This content assumes you've already built or are interfacing with a third party note-keeping app, including persistence and addressable APIs. This blueprint demonstrates a flow where the selected message is exported as JSON for your external app to further process.

How it works

1. Receive action events from Slack

When a user executes the message action associated with the app, Slack will send a POST request to the request URL provided in the app settings. This request will include the message text in the payload. The command scope is used for the message action.

Payload example:

{
  "token": "Nj2rfC2hU8mAfgaJLemZgO7H",
  "callback_id": "clipit",
  "type": "message_action",
  "trigger_id": "13345224609.8534564800.6f8ab1f53e13d0cd15f96106292d5536",
  "response_url": "https://hooks.slack.com/app-actions/T0MJR11A4/21974584944/yk1S9ndf35Q1flupVG5JbpM6",
  "team": {
    "id": "T0MJRM1A7",
    "domain": "pandamonium"
  },
  "channel": {
    "id": "D0LFFBKLZ",
    "name": "lunch"
  },
  "user": {
    "id": "U0D15K92L",
    "name": "dr_meow"
  },
  "message": {
    "type": "message",
    "user": "U0MJRG1AL",
    "ts": "1516229207.000133",
    "text": "Can you order a tuna with cheese and lactose-free milk for me, please?"
  }
}

The payload also includes a user ID for the person who originally posted the message. This example app uses the ID to call users.info method to get the person's full name. You can also obtain more info about the user from the method, like their avatar.

2. Open a Dialog

In order to let the user to edit the message to be saved in the 3rd party app, the app will open a Dialog in Slack. When the user submits the Dialog, Slack will send a POST request to the same request URL used for the message action. To differentiate which action triggers the event, parse the payload and check the type.

3. Confirm the user

Once the user submits the dialog, this example app exports the message in JSON. You'll probably want to transform the content into something more meaningful when importing into your own service. In the meantime, the app notifies the user by sending a DM using chat.postMessage method.

To look up further information about users, you'll need to request the users:read scope and use users.info or users.list..

GIF demo

Diagram

Diagram

Related documentation