Manage students progress and provide the report if needed
- PostgreSQL 13
- Add bot to the chat
- Make bot admin (to read all messages, not only commands)
- Set a webhook to bot https address:
curl https://api.telegram.org/bot<BOT_TOKEN>/setWebhook\?url\=<BOT_HTTPS_URL>
- Create a config file for bot or use ENV variables, please check the example
- Provide the db/migrations folder
- Start bot
docker run -it -p 3000:3000 -e DATABASE_URL="postgres_url" -e TELEGRAM_BOT_TOKEN="telegram_bot_token" to4kin/devops-school-bot:latest
Use serverless
framework to deploy AWS Lambda. Do not forget set environment variable AWSLAMBDA_ENABLED=true
service: devops-school-bot
useDotenv: true
configValidationMode: error
frameworkVersion: '>=2.61.0'
provider:
region: "eu-central-1"
lambdaHashingVersion: "20201221"
name: aws
runtime: go1.x
logRetentionInDays: 30
endpointType: regional
tracing:
apiGateway: true
lambda: true
ecr:
images:
latest:
path: ./
iam:
role:
statements:
- Effect: "Allow"
Resource: "*"
Action:
- "xray:*"
functions:
webhook:
image: latest
timeout: 15
description: Manage students progress and provide the report if needed
memorySize: 128
environment:
AWSLAMBDA_ENABLED: true
DATABASE_URL: ${env:DATABASE_URL}
TELEGRAM_BOT_TOKEN: ${env:TELEGRAM_BOT_TOKEN}
events:
- http:
path: /webhook
method: POST
cors: false
DevOps School Bot manage students progress and provide the report
Usage:
devops-school-bot [command]
Available Commands:
help Help about any command
start Start DevOps School Bot
version Print version
Flags:
-h, --help help for devops-school-bot
Use "devops-school-bot [command] --help" for more information about a command.
Start DevOps School Bot with config file
Simply execute devops-school-bot start -c path/to/config/file.toml
or skip this flag to use default path
Usage:
devops-school-bot start [flags]
Flags:
-c, --config-path string path to config file (default "configs/devopsschoolbot.toml")
-h, --help help for start
Availiable file formats: JSON, TOML, YAML, HCL, envfile and Java properties
example-config.toml
log_level = "info"
debug_mode = false
[apiserver]
bind_addr = ":3000"
[apiserver.cron]
enabled = true
fullreport = true
schedule = "0 15 * * FRI"
[awslambda]
enabled = false
[database]
url = "postgres://localhost/devops_school?user=postgres&password=example&sslmode=disable"
migrations = "db/migrations"
[telegram_bot]
token = "TEST_TELEGRAM_TOKEN"
verbose = false
example-config.yaml:
log_level: info
debug_mode: false
apiserver:
bind_addr: :3000
cron:
enabled: true
fullreport: true
schedule: "0 15 * * FRI"
awslambda:
enabled: false
database:
url: postgres://localhost/devops_school?user=postgres&password=example&sslmode=disable
migrations: db/migrations
telegram_bot:
token: TEST_TELEGRAM_TOKEN
verbose: false
Or, you can use ENV variables to update config:
LOG_LEVEL="debug"
DEBUG_MODE="false"
APISERVER_BIND_ADDR=":3000"
APISERVER_CRON_ENABLED="true"
APISERVER_CRON_FULLREPORT="true"
APISERVER_CRON_SCHEDULE="0 15 * * FRI"
AWSLAMBDA_ENABLED="false"
DATABASE_URL="postgres://localhost/devops_school?user=postgres&password=example&sslmode=disable"
DATABASE_MIGRATIONS="db/migrations"
TELEGRAM_BOT_TOKEN="TEST_TELEGRAM_TOKEN"
TELEGRAM_BOT_VERBOSE="false"
By default, the Bot will send a full report each Friday at 15:00 UTC time to all active school chats. It's the same report as /fullreport command. If you would like to use short report (as /report command) - set fullreport = false
version: '3.7'
services:
postgres:
image: postgres:13.4
container_name: postgres
restart: always
environment:
POSTGRES_DB: devops_school
POSTGRES_USER: postgres
POSTGRES_PASSWORD: example
volumes:
- db_data:/var/lib/postgresql/data
application:
image: to4kin/devops-school-bot:latest
container_name: devops-school-bot
restart: always
environment:
DATABASE_URL: postgres://postgres/devops_school?user=postgres&password=example&sslmode=disable
TELEGRAM_BOT_TOKEN: TELEGRAM_BOT_TOKEN
depends_on:
- postgres
volumes:
db_data:
There're two types of telegram chat where the bot is accepting commands: private chat
and group chat
/start - Add user to database [Private chat Only]
/joinstudent - Join school as student [Group chat Only]
/joinmodule - Join school as listener [Group chat Only]
/myreport - Your progress [Private chat Only]
/homeworks - Homeworks list [Private chat Only]
/help - Help message [All chats]
/schools - Manage schools [Private chat Only]
/startschool - Start school [Group chats Only]
/stopschool - Finish school [Group chats Only]
/report - School progress [All chats]
/fullreport - School progress with homework list [All chats]
/users - Manage users [Private chat Only]
/setsuperuser - Set Superuser [Private chat Only]
/unsetsuperuser - Unset Superuser [Private chat Only]
To add homework, use the work hashtag along with the #homework
, for example: #homework #cicd
start - Add user to database
joinstudent - Join school as student
joinmodule - Join school as listener
myreport - Your progress
homeworks - Homeworks list
help - Help message
When debug_mode is enabled the bot will provide additional http endpoint /debug/pprof for profiling data in the format expected by the pprof visualization tool
There're 2 types of students: full course and module course.
We have a dynamic homework list, which means that at the beginning of the school the list is empty and populated when the homework is provided by the student. This means that the student should provide all homework which was provided by other students.
On the other hand, if the student was joined for module course, the list of homework depends on the modules. The module list is also populated by students.
We need to follow one simple instruction: the homework hashtag should be #<MODULE_NAME><SEQUENTIAL_NUMBER>, for example #cicd1 #cicd2 #cloud1 #ansible1