Skip to content

iqoption/slack-duty-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Slack duty bot

License Go Report Card Build Status

Usage

  1. Create new custom integration Bots (e.g https://{team}.slack.com/apps/manage/custom-integrations)
  2. Add bot to channels you want to listen
  3. Build for your environment or download tarball with binary for your OS and arch
  4. Prepare config.yaml with duties list
  5. Run with the required parameters
SDB_SLACK_TOKEN=your-token-here ./slack-duty-bot \
    --slack.keyword keyword-1 \
    --slack.keyword keyword-2 \
    --slack.group.id your-group-id \
    --slack.group.name your-group-name

You also can run in application in docker:

docker run \
    --name slack-duty-bot \
    --restart on-failure \
    -v $(pwd)/config:/etc/slack-duty-bot \
    -e SDB_SLACK_TOKEN=your-token-here \
    -d \
    iqoption/slack-duty-bot:1.1.0 \
    --config.path=/etc/slack-duty-bot \
    --slack.keyword keyword-1 \
    --slack.keyword keyword-2
    --slack.group.id your-group-id \
    --slack.group.name your-group-name

Build package

** Golang:1.11 is required **

Build

env GOOS=linux GOARCH=amd64 GO111MODULE=on go build -o slack-duty-bot -v

Build via makefile

make GOOS=linux GOARCH=amd64

Build in docker

docker run \
    --rm \
    -v $(pwd):/project \
    -w /project \
    -e GOOS=linux \
    -e GOARCH=amd64 \
    -e GO111MODULE=on \
    golang:1.11 go build -o slack-duty-bot -v

Configuration flags, environment variables

Environment variables are prefixed with SDB_ and MUST be uppercase with _ delimiter

Available variables:

  • SDB_SLACK_TOKEN
  • SDB_SLACK_GROUP_ID
  • SDB_SLACK_GROUP_NAME
  • SDB_SLACK_THREADS
  • SDB_LOGGER_LEVEL

Every environment variable can be overwritten by startup flags

Available flags:

  • --slack.token - Slack API client token (Required)
  • --slack.keyword - Case insensitive keywords slice to search in message text, can be set multiple times (default: []) (Required)
  • --config.path - Path to config.yaml file (default: . and $HOME/.slack-duty-bot)
  • --slack.group.name - Slack user group name, to mention in channel if duty list is empty
  • --slack.group.id - Slack user group ID, to mention in channel if duty list is empty
  • --slack.threads - Use threads as reply target or push message direct to channel (default: true)
  • --logger.level - Log level (default: info)

You can get IDS from api or just use testing page

Configuration file

There are three ways of configuration for slack-duty-bot

Slack group

slack:
  group:
    id: some-group-id
    name: some-group-name

In this way slack-duty-bot will always call entire Slack group in case matching keyword in message.

Duties list

By default duties is an empty slice (or just skipped in config)

duties: []

In this case you MUST set slack.group configuration

If you prefer to set different duties for different days, you MUST set duties as slice, containing 7 indexes of slices:

duties:
  - [username.one, username.two] # Sunday
  - [username.one] # Monday
  - [username.two] # Tuesday
  - [username.one] # Wednesday
  - [username.two] # Thursday
  - [username.one] # Friday
  - [username.one, username.two] # Saturday

Combined

If you prefer to set custom duties for some days, and call full group for another, just pass duties slice and slack.group configuration together:

slack:
  group:
    id: some-group-id
    name: some-group-name
duties:
  - [] # Sunday
  - [username.one] # Monday
  - [username.two] # Tuesday
  - [username.one] # Wednesday
  - [username.two] # Thursday
  - [username.one] # Friday
  - [] # Saturday

As the result of this configuration, slack-duty-bot will call username.one at Friday and full Slack group some-group-name at Saturday and Sunday

Configuration priority

  • Flags
  • Environment variables
  • Config file

Deploy to Kubernetes

Deploy with Helm

Configuration

The following table lists the configurable parameters of the slack-duty-bot chart and their default values.

Parameter Description Default
image.repository SDB image registry iqoption/slack-duty-bot
image.tag SDB Image tag {VERSION}
image.pullPolicy SDB image pull policy IfNotPresent
configuration.slackToken Slack token nil
configuration.keywords Trigger words array duty

Run deploy

helm upgrade --install slack-duty-bot-my-app-name .helm/slack-duty-bot/ --set configuration.slackToken=secret-token,configuration.keywords[0]="duty",configuration.keywords[1]="autobot",dutyUsers.monday=user.one,dutyUsers.tuesday=user.two,dutyUsers.wednesday=user.one

Manual deploy to Kubernetes

Create namespace

kubectl create namespace slack-duty-bot

Create namespace quota

#namespace-quota.yaml
apiVersion: v1
kind: ResourceQuota
metadata:
  name: slack-duty-bot-quota
spec:
  hard:
    requests.cpu: "2"
    requests.memory: 1Gi
    limits.cpu: "4"
    limits.memory: 2Gi
kubectl create -f namespace-quota.yaml --namespace=slack-duty-bot

Create limit range

#namespace-limit-range.yaml
apiVersion: v1
kind: LimitRange
metadata:
  name: slack-duty-bot-limit-range
spec:
limits:
  - default:
      cpu: "200m"
      memory: 128Mi
    defaultRequest:
      cpu: "100m"
      memory: 64Mi
    type: Container
kubectl create -f namespace-limit-range.yaml --namespace=slack-duty-bot

Prepare your deployment file

(docker run \
    --rm \
    -it \
    -v $(pwd):/tmp \
    -e SDB_SLACK_TOKEN_BASE64=your-token-hash \
    -e SDB_NAME=your-deployment-name \
    -e SDB_TAG=1.1.0 \
    -e SDB_KEYWORD=your-keyword \
    -e SDB_SLACK_DEFAULT_USER=default-username \
    -e SDB_SLACK_GROUP_ID=group-id \
    -e SDB_SLACK_GROUP_NAME=group-name \
    supinf/envsubst /tmp/.kubernetes/deploy.yaml.tpl) > $(pwd)/.kubernetes/deploy.yaml

or use native envsubst

(SDB_SLACK_TOKEN_BASE64=your-token-hash \
    SDB_NAME=your-deployment-name \
    SDB_TAG=1.1.0 \
    SDB_KEYWORD=your-keyword \
    SDB_SLACK_DEFAULT_USER=default-username \
    SDB_SLACK_GROUP_ID=group-id \
    SDB_SLACK_GROUP_NAME=group-name \
    envsubst < $(pwd)/.kubernetes/deploy.yaml.tpl) $(pwd)/.kubernetes/deploy.yaml

After that you can change configuration with kubect or edit config map directly from Kubernetes dashboard

Deploy

kubectl apply -f $(pwd)/.kubernetes/deploy.yaml --namespace slack-duty-bot

Contributing

Travis-CI and tests

To enable tests for your fork repository you MUST:

  • Create your project in TravisCI for your fork repository
  • Add environment variables to Travis-CI project:
    • DOCKER_NAMESPACE
    • DOCKER_USER
    • DOCKER_PASSWORD

Travis-CI will run test on every push for every ref and build docker image and push to docker hub ONLY FOR TAGS

Changelog

Changelog for project

Roadmap

Roadmap for project

Authors

Contributors