Made with Django
, AWS Lambda
and zappa framework.
You can now use Docker insted of Zappa. Read below for instructions.
Once a day a bot writes to selected members list of questions for standup. Users and questions configured in Admin interface.
After user answer this questions the whole answer is posted to public channel.
Post in public channel
In order to quickly use this bot you need to:
- Create AWS account to use Lambda
- Create new Slack App and Slack bot
- Deploy a service with
zappa
and add a webhook for Slack bot - Tune bot with you texts and users
- Authorize your app in you Slack team
Looks hard, but the whole process unlikely takes longer than 30 minutes.
All environment variables are stored into slack/settings/settings.yml
file which is of course ignored. Because file is yaml
we can create multiple environment
and inherite them. So the file structure must be like that
default_env: &default_env
SECRET_KEY:
DEBUG: true
DB_ENGINE: 'django.db.backends.postgresql'
SLACK_CLIENT_ID:
SLACK_CLIENT_SECRET:
SLACK_VERIFICATION_TOKEN:
SLACK_BOT_USER_TOKEN:
TEXT_NO_MORE_QUESTIONS: 'Красава, ты уже отправил сегодняшний стэндап.'
TEXT_STANDUP_IS_DONE: 'Стэндап закончен :tada:. Спасибо за ответы!'
TEXT_NO_USER: 'Тебе проходить стэндап не нужно.'
TEXT_CHANNEL_MESSAGE: '<@{}> закончил стэндап. Красава!'
TEXT_NEW_DAY: 'Привет! Пришло время нового стэндапа.'
SLACK_COMMON_CHANNEL:
local:
<<: *default_env
SECRET_KEY:
DB_NAME:
DB_HOST:
DB_PORT:
DB_USER:
DB_PASSWORD:
dev:
<<: *default_env
SECRET_KEY:
DEBUG: false
DB_NAME:
DB_HOST:
DB_PORT:
DB_USER:
DB_PASSWORD:
SECRET_KEY
— Django secrete key. You can generate it here.DEBUG
— Django debug keyDB_ENGINE
— Django engine for DB. We use Postgres withdjango.db.backends.postgresql
.SLACK_CLIENT_ID
— Slack client id which you can find on your app page likehttps://api.slack.com/apps/XXXXXX
SLACK_CLIENT_SECRET
— Slack client secret which you can find on your app page likehttps://api.slack.com/apps/XXXXXX
SLACK_VERIFICATION_TOKEN
— Slack client verification token which you can find on your app page likehttps://api.slack.com/apps/XXXXXX
SLACK_BOT_USER_TOKEN
— Slack bot user token which you can find on your app page inbot users
sectionTEXT_NO_MORE_QUESTIONS
— The text when user has submitted standut for today and writes another messageTEXT_STANDUP_IS_DONE
— A greeting message which is sent right after the answer for the last questionTEXT_NO_USER
— A message for user which shouldn't write standup (for example, if somebody randomly sent a message to a bot)TEXT_CHANNEL_MESSAGE
— A message template for user for a public channel. Users mention is inside. For example'<@{}> закончил стэндап. Красава!'
TEXT_NEW_DAY
— A welcome message for a new day standupSLACK_COMMON_CHANNEL
— Channel ID for public standup. Can be easily found when open a channel. Take a look at the urlhttps://teamname.slack.com/messages/*CHANNEL_ID*/details/
.
Be sure you have AWS_ACCESS_KEY
and AWS_SECRET_KEY
environment variables set.
To deploy a bot with Zappa just write zappa deploy dev
. Zappa will create CloudFormation stack
for you to manage all the infrastructure. When you need yo update you stack write zappa update dev
.
You need to build Docker image with command docker build -t your_tag_name .
. Then run container with command docker run -p 3720:3720 your_tag_name
where 3720 is a default port in Docker file. You can change the port for any other. In order to use CRON to start standup, you need some trigger. The easiest solution is to make a simple Lambda function that will trigger bot's API. Take a look at scheduler.py
file. You can use alternative schedulers but for Lambda you need to
- Create a file
local.yml
with content
dev:
SCHEDULER_URL: your_url
where dev
is a name of the environment, SCHEDULER_URL
is a URL that sends standup to all users. For current settings, it would look like your_domain:3720/send_standup
.
- Tune CRON settings in
serverless.yml
file. - Deploy Lambda with Serverless framework
sls deploy
.
You can tune deploy settings in zappa_settings.json
file.
For example, you might want to change you standup start day (our when standup is sent).
The admin interface is available with Django interface. When you've deployed a service with
Zappa admin interface will be available by /admin
url (without static files). Don't
forget to create superuser (python manager.py createsuperuser --settings=slack.settings.dev
).
Add questions with the order.
You also need to add user for standup. For example, in our team only developers write standups.
Just fill Slack id
for user and mark Is active
. You can find Slack id
in the url when
open users profile. For example, https://team.slack.com/messages/channel_id/team/USER_ID/
.
You don't need to fill Channel id
for user.