Telegram bot that lets you guess the location of a random photo.
You can start by sending /random
command to receive a random photo. Then you can enter your guess and send it as a message to receive feedback (true/false). You can also use /filter
command to filter with prefixes for intermediate directories, for example for year it will be /filter 2022 2023
. Made with python-telegram-bot. Inspired by another game of mine guess-where.
There are 2 scripts that use the Telegram API in 2 different ways.
guess_where_telegram_bot.py
: This is using the polling method (fetching new messages from Telegram API periodically) with python-telegram-bot library (getUpdates
). It needs to be run on a server (e.g. AWS EC2).guess_where_telegram_bot_lambda_function.py
: This is used as a webhook that will be called by Telegram to receive new messages. It needs to be run as a function (e.g. AWS Lambda).
pipenv install
pipenv shell # without this you can also do: pipenv run python3 guess_where_telegram_bot.py
python3 guess_where_telegram_bot.py
Following environment variables have to be set.
- S3_BUCKET
- S3_BUCKET_PREFIX
- AWS_ACCESS_KEY
- AWS_SECRET_ACCESS_KEY
- TELEGRAM_BOT_TOKEN
It is using the following AWS services.
- Lambda to run the Python script
- DynamoDB to store the last location and current filter
- S3 to store the current set of paths of photos in a JSON file
- Systems Manager Parameter Store to store the
TELEGRAM_BOT_TOKEN
- CloudWatch to store the logs
AWS services need to be set up with Terraform using main.tf
.
Telegram webhook needs to be set as following.
POST https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/setWebhook?url={LAMBDA_FUNCTION_URL}
Photos can only be read if they are structured in a specific way.
{PATH}/{COUNTRY}/{CITY}/**/{PHOTO}.jpg
City or country directory name should be guessed. {COUNTRY}
DOESN'T have to be country, it can be anything. It is just my current setup. **
in between can contain any number of directories from 0 to N.
{PATH}/{DATE} - {ORDER} - {COUNTRY} - {CITY}/**/{PHOTO}.jpg
City or country name should be guessed. {DATE} - {ORDER} - {COUNTRY}
part DOESN'T have to be in that structure as long as elements are separated with -
and city is the last element. It is just my current setup. **
in between can contain any number of directories from 0 to N.
Photos can be read from S3 bucket.
Use with or without prefix, for example s3://{BUCKET}
or s3://{BUCKET}/{PREFIX}/
There must be at least one directory between bucket and photo directories in your structure, for example s3://{BUCKET}/Photos/{COUNTRY}/{CITY}/**/{PHOTO}.jpg
or s3://{BUCKET}/Photos/2022/{DATE} - {ORDER} - {COUNTRY} - {CITY}/**/{PHOTO}.jpg
It is setup using GitHub Actions in lint
job in .github/workflows/lint_and_deploy.yml
guess_where_telegram_bot_lambda_function.py
is deployed to AWS Lambda automatically using GitHub Actions in deploy
job in .github/workflows/lint_and_deploy.yml
Feel free to contribute.
You can distribute this software freely under GNU GPL v3.0.