telegram-hcaptcha-bot
Workflow
Screenshots
Landing page | Verified | Failed to verify |
---|---|---|
![]() |
![]() |
![]() |
How everything is connected
Setup:
- Create your telegram bot (please check section below).
- Signup to hCaptcha to get your site key and secret (please check section below) .
- Install dependencies:
pipenv install --dev
(make sure to havepipenv
installed). - Copy
.env.sample
to.env
and add:TELEGRAM_USERNAME
,TELEGRAM_TOKEN
,HCAPTCHA_SECRET
andHCAPTCHA_SITE_KEY
.
HCAPTCHA_SECRET
& HCAPTCHA_SITE_KEY
Where to get - Signup to hCaptcha.
- To get
HCAPTCHA_SECRET
: go the Settings tab. - To get
HCAPTCHA_SITE_KEY
: go to Sites tab and create a new site key.
Run application locally
cd app && FLASK_APP=wsgi.py FLASK_DEBUG=1 python3 -m flask run
Running the app inside docker container:
# start
docker-compose up
# stop
docker-compose down
Run on heroku
Incase you need to run your the application on heroku:
heroku create <dev_instance_name> --remote development
- Add
APP_URL
with your dev instance link
Signup for a new Telegram bot
- Create a new bot on telegram and note the
secret token
and the botusername
: Creating a new bot - Telegram documentation - Create a new account on hCaptcha and note the
sitekey
and thesecret token
- Invite the bot to your Telegram channel and set it as admin
Run tests
pipenv run python -m pytest
- With coverage:
pipenv run coverage run --include="app/*" -m pytest
- Show report:
pipenv run coverage report -m
or as html:pipenv run coverage html && open htmlcov/index.html
- Run single test method: e.g.
python -m pytest app/tests/test_bot.py -k 'test_is_verified'
- Rung single test with
ipdb
breakpoint:python -m pytest -s app/tests/bot_handlers/test_handle_invitation.py
Deploying
How to deploy automatically
Staging
Simply merge all your changes to staging
branch, and it will be deployed to the staging heroku on successful builds and tests passing in github.
Production
Merge all your changes to master
and it will be deployed to the prod environment.
How to deploy manually
-
Check the "Setup" section above and make sure that tests passes locally.
-
If using the
herkou
cli approach, be sure to run this first:heroku login
-
Make sure you've already remote tracking for your target env (one of):
git remote add <env> https://git.heroku.com/<app>.git
heroku git:remote -a staging-hcaptcha-telegram-bot
heroku git:remote -a prod-hcaptcha-telegram-bot
- If using the heroku command, you may want to rename the envs appropriately as they will all be called
heroku
git remote rename heroku staging
- If using the heroku command, you may want to rename the envs appropriately as they will all be called
-
Deploy code changes:
git push <env> your_dev_branch:master
(push specified branch)git push staging master:master
(push master from origin to staging remote master)
-
Run DB migrations:
heroku run "python manage.py db upgrade -d app/migrations/" --remote <env>
-
If DB migration was needed you may need to manually start up the app:
heroku run web --remote <env>
(start up app inline)heroku ps:scale web=1 --remote <env>
(start up more instances of the app)
Environments
- Prod:
- Bot name:
hCaptchaBot
- URL: https://prod-hcaptcha-telegram-bot.herokuapp.com/
- Bot name:
- Staging:
- Bot name:
yellow_tg_bot
- URL: https://staging-hcaptcha-telegram-bot.herokuapp.com/
- Bot name:
Troubleshooting
- Check logs on heroku:
heroku logs --tail --remote <env>
- The bot must be in a supergroup and the bot must be have admin permissions.