Skip to content

ExpediaGroup/flyte-slack

Repository files navigation

flyte-slack

Build Status Docker Stars Docker Pulls

A Slack pack for flyte.

Build

Pack requires go version min. 1.11

  • go build go build
  • go test go test ./...
  • docker build docker build -t <name>:<version> .

Configuration

This plugin only works with classic Slack apps at the moment. To learn how to create one, click here.

The plugin is configured using environment variables:

ENV VAR Default Description Example
FLYTE_API - The API endpoint to use http://localhost:8080
FLYTE_SLACK_TOKEN - The Slack Bot API token to use token_abc

Example FLYTE_API=http://localhost:8080 FLYTE_SLACK_TOKEN=token_abc ./flyte-slack

Commands

All the events have the same fields as the command input plus error (in case of failed event)

SendMessage

{
    "message": "...", // required
    "channelId": "...", // required
    "threadTimestamp": "..." // optional
}

Returned events

MessageSent

{
    "message": "...",
    "channelId": "...",
    "threadTimestamp": "..."
}

SendMessageFailed

{
    "message": "...",
    "channelId": "...",
    "error": "..."
}

SendRichMessage

See the Slack message formatting API (and the example below) for details on what can be included in this. All of the fields (at the time of writing) available on the Slack API are supported here.

Returned events

RichMessageSent

The returned event payload is the same as the input.

SendRichMessageFailed

{
  "inputMessage": { ... },
  "error": "..."
}

Events

ReceivedMessage

{
    "channelId": "...",
    "user": {                // user that sent the message
        "id": "...",
        "name": "...",       // display name
        "email": "...",
        "title": "...",      // e.g. Principal Systems Engineer
        "firstName": "...",
        "lastName": "...",
        "timestamp": "...",
        "threadTimestamp": "..."
    },
    "message": "..."
}

ReactionAdded

{
    "type":"...",
    "user":"...",  //user that adds the reaction
    "itemUser":"...",  //user that writes the message, file etc.
    "item": {
            "type" :"message", 
            "channel" :"...", 
            "timestamp" :"..."
            }, 
    "reaction" :"...", //value of the reaction
    "eventTimestamp" :"..." 
}

Example Flows

The following flow will allow you to type any message into a Slack channel where this pack is listening and have it echo back whatever you say. E.g.: typing echo hello world will echo "hello world" back to you.

{
  "name": "echo",
  "description": "Echo message back to the sender with a mention, like echo service",
  "steps": [
    {
      "id": "get_message",
      "event": {
        "packName": "Slack",
        "name": "ReceivedMessage"
      },
      "criteria": "{{ Event.Payload.message | match: '^echo\\\\s+' }}",
      "context": {
        "Msg": "{{ Event.Payload.message | slice:'5:'}}",
        "Channel": "{{ Event.Payload.channelId }}",
        "RequestorId": "{{ Event.Payload.user.id }}"
      },
      "command": {
        "packName": "Slack",
        "name": "SendMessage",
        "input": {
          "channelId":"{{ Context.Channel }}",
          "message":"<@{{ Context.RequestorId }}>, you said:\n>>> {{ Context.Msg }}"
        }
      }
    }
  ]
}

This flow sends a rich message for a hypothetical deployment. More information about rich messages can be found in the Slack API documentation. The message format is exactly the same as documented (at least currently!) so can be directly cut & pasted into Slack's message builder tool, e.g.: this is the below message, verbatim in the tool

{
  "name": "announce_deployments",
  "description": "Announces deployments",
  "steps": [
    {
      "id": "on_deployment_success",
      "event": {
        "packName": "MyContinuousDeploymentToolPack",
        "name": "DeploymentSucceeded"
      },
      "command": {
        "packName": "Slack",
        "name": "SendRichMessage",
        "input": {
          "channel": "ABCDEFG",
          "attachments": [
            {
              "fallback": "The deploy of `YOURAPP.0.1.641` to `staging` has completed with a status of *success*.",
              "color": "#36a64f",
              "title": "Deployment Update",
              "text": "<@USER>, the deploy of `YOURAPP.0.1.641` to `staging` has completed with a status of *success*.",
              "fields": [
                {
                  "title": "Artefact",
                  "value": "YOURAPP.0.1.641",
                  "short": true
                },
                {
                  "title": "Environment",
                  "value": "staging",
                  "short": true
                }
              ],
              "actions": [
                {
                  "type": "button",
                  "text": "View Logs",
                  "url": "http://logs.example.com/staging/deploy/vFZhU-1388",
                  "style": "primary"
                }
              ]
            }
          ]
        }
      }
    }
  ]
}