A Slack pack for flyte.
Pack requires go version min. 1.9 and uses dep to manage dependencies (install dep and run dep ensure
before build/test)
- go build
go build
- go test
go test ./...
- docker build
docker build -t <name>:<version> .
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 API token to use | token_abc |
FLYTE_SLACK_DEFAULT_JOIN_CHANNEL | - | A channel to join by default when launched | 1234 |
FLYTE_SLACK_BACKUP_DIR | $TMPDIR | Directory where to backup joined channels | /flyte-slack |
Example FLYTE_API=http://localhost:8080 FLYTE_SLACK_TOKEN=token_abc FLYTE_SLACK_DEFAULT_JOIN_CHANNEL=1234 ./flyte-slack
All the events have the same fields as the command input plus error (in case of failed event)
{
"message": "...", // required
"channelId": "...", // required
"threadTimestamp": "..." // optional
}
Returned events
MessageSent
{
"message": "...",
"channelId": "...",
"threadTimestamp": "..."
}
SendMessageFailed
{
"message": "...",
"channelId": "...",
"error": "..."
}
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": "..."
}
Same as send message, but without channel id. Message will be sent to all the channels that pack has joined.
{
"message": "..." // required
}
Returned events
BroadcastSent
{
"message": "..."
}
BroadcastFailed
{
"message": "...",
"error": "..."
}
Joins channel, pack will start sending ReceivedMessage
events if there's new message in the joined channel
{
"channelId": "..." // required
}
Returned events
ChannelJoined
{
"channelId": "..."
}
JoinChannelFailed
{
"channelId": "...",
"error": "..."
}
Leaves Slack channel, channel will not be monitored for incoming messages.
{
"channelId": "..." // required
}
Returned events
ChannelLeft
{
"channelId": "..."
}
LeaveChannelFailed
{
"channelId": "...",
"error": "..."
}
{
"channelId": "...",
"user": { // user that sent the message
"id": "...",
"name": "...", // display name
"email": "...",
"title": "...", // e.g. Principal Systems Engineer
"firstName": "...",
"lastName": "...",
"timestamp": "...",
"threadTimestamp": "..."
},
"message": "..."
}
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"
}
]
}
]
}
}
}
]
}