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.
.envfile
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 endclient_secret.jsonfile - 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
herokuCLI from https://devcenter.heroku.com/articles/heroku-cli - Change execute permissions with
sudo chmod +x deploy.sh - Run
./deploy.shwith the app name
- You can run using
venvordocker-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.pyto save inSHEET_URL. - If you make any changes to
Dockerfileorrequirements.txt, rebuild the image to see your changes, by runningdocker-compose build
- Credentials MUST be stored in
.envwhich will be loaded indocker-composeand heroku. Access them usingos.getenv(NAME). - Don't
print(), uselogging.info() - No
@run_asyncfor critical states, eg submissions, questions @sidecarfor state callbacks' lifecycle checksescape_markdown(text, version=2)for texts withMarkdownV2Upper_casefor public functionslower_casefor local functionsUPPER_CASEfor constants, eg states- Annotate parameter types for sanity
- Design bot to be stateless for easier deployment