This Telegram bot was the main point of contact with participants for them to submit their video/photo proof of their ascent, and send any inquiries to us. Telegram was chosen for its unlimited storage, 2GB file size limits, and mature bot API.
This bot relies on Telegram-Python-Bot and gspread
library. gspread
was used as a database for graders to grade submissions. It is developed within a Docker container for ease of installation and deployment. Due to time constraints, it was created using the polling approach, ie while True
. The bot is then deployed on heroku, which is free and easy to use.
.env
file
SHEET_URL= # database for user ID, submissions, leaderboard, ... rows/cols hardcoded and should be changed. MUST BE non-xlsx
BOT_TOKEN= # get from botfather
# Find the channel/grp ID with https://stackoverflow.com/questions/33858927/how-to-obtain-the-chat-id-of-a-private-telegram-channel
ANNOUNCE_CHANNEL= # ^ for announcements to IDs saved in sheet
SUBMISSION_CHANNEL= # ^ for forwarded submissions to channel
ASK_GROUP= # ^ for forwarded questions to group
TEST=true # true = announce to self, false = announce to all
# App
TZ=Asia/Singapore
DEBUGGER_ID= # announce to self
ANNOUNCE_PREFIX=Announce: # used in ANNOUNCE_CHANNEL to prevent accidental broadcasts
START_TIMESTAMP=1638547200 # event start
END_TIMESTAMP=1639065600 # event end
client_secret.json
file - follow https://docs.gspread.org/en/latest/oauth2.html#for-bots-using-service-account
- Create a heroku account. Then create an app to be linked to our container.
- Install
heroku
CLI from https://devcenter.heroku.com/articles/heroku-cli - Change execute permissions with
sudo chmod +x deploy.sh
- Run
./deploy.sh
with the app name
- You can run using
venv
ordocker-compose up
(https://docs.docker.com/compose/install/). - To change bot states, edit
bot.py
. - To change each state behavior, edit
handler.py
. To schedule announcements, editAnyone can schedule announcements inschedule.py
.ANNOUNCE_CHANNEL
! No need to wait for the developer.- To persistent data across restart, edit
db.py
to save inSHEET_URL
. - If you make any changes to
Dockerfile
orrequirements.txt
, rebuild the image to see your changes, by runningdocker-compose build
- Credentials MUST be stored in
.env
which will be loaded indocker-compose
and heroku. Access them usingos.getenv(NAME)
. - Don't
print()
, uselogging.info()
- No
@run_async
for critical states, eg submissions, questions @sidecar
for state callbacks' lifecycle checksescape_markdown(text, version=2)
for texts withMarkdownV2
Upper_case
for public functionslower_case
for local functionsUPPER_CASE
for constants, eg states- Annotate parameter types for sanity
- Design bot to be stateless for easier deployment