Barbot is a Telegram bot that automates decision making for our weekly bar night.
This is the environment file used by AWS SAM for setting the function's environment variables. The file will look something like this:
{
"WebhookFunction": {
"MAIN_CHAT_ID": "<XXXXX>",
"TELEGRAM_BOT_TOKEN": "<XXXXX>:<XXXXX>",
"BAR_SPREADSHEET": "https://docs.google.com/spreadsheets/d/<XXXXX>/",
"SELENIUM_SERVER_URL": "http://<XXXXX>:4444"
}
}
Make sure the telegram bot and main chat id in env.json are different than the live bot's.
Local development will nuke the webhook information for that bot.
- Set the
NGROK_AUTHTOKENenviornment variable.
You need a free ngrok token for development - this is so telegram can talk to your local webhook handler.
- Run
./run-local.py
This takes care of setting up the helper services, building the application, running it, and pointing telegram to the local instance.
- Duplicate the
"WebhookFunction"object inenv.jsonunder the keySequenceFunction.
This is an unfortunate limitation of SAM:
{
"WebhookFunction": {"a": "b", "c": "d"},
"SequenceFunction": {"a": "b", "c": "d"},
}
- Run
sam local invoke
WARNING: Make sure you've run ./run-local.py before invoking sam, because ./run-local.py is what builds the image that sam uses (otherwise, you'll be using an outdated barbot).
An invocation should look something like this:
echo '{"barnight_event_type": "CreatePoll"}' | sam local invoke SequenceFunction --docker-network barbot --env-vars env.json -e -
-
Install the version of python currently being targeted by the lambda runtime (See lambda.tf. At the time of writing, this is Python 3.12)
-
Create a virtual environment using that python version.
python3.12 -m venv venv -
Activate the virtual environment and run ./build.py
-
In the
terraformdirectory, Copy a template .tfvars file to terraform.tfvars. Set the empty values. -
Use
terraform workspace showandterraform workspace selectto choose the correct terraform state to use.defaultworkspace is used for prod, andtestis used for the 'testing' bot and channel.