Giter Site home page Giter Site logo

kasugano-soraa / telegram-bot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hcaptcha/telegram-bot

1.0 0.0 0.0 2.78 MB

A bot to reduce spam on Telegram by showing hCaptcha challenges

License: MIT License

Shell 0.22% Python 96.93% CSS 0.79% HTML 1.28% Mako 0.50% Dockerfile 0.28%

telegram-bot's Introduction

telegram-hcaptcha-bot

Workflow

Screenshots

Landing page Verified Failed to verify

How everything is connected

Setup:

  1. Create your telegram bot (please check section below).
  2. Signup to hCaptcha to get your site key and secret (please check section below) .
  3. Install dependencies: pipenv install --dev (make sure to have pipenv installed).
  4. Copy .env.sample to .env and add: TELEGRAM_USERNAME, TELEGRAM_TOKEN, HCAPTCHA_SECRET and HCAPTCHA_SITE_KEY.

Where to get HCAPTCHA_SECRET & HCAPTCHA_SITE_KEY

  1. Signup to hCaptcha.
  2. To get HCAPTCHA_SECRET: go the Settings tab.
  3. 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:

  1. heroku create <dev_instance_name> --remote development
  2. Add APP_URL with your dev instance link

Signup for a new Telegram bot

  1. Create a new bot on telegram and note the secret token and the bot username: Creating a new bot - Telegram documentation
  2. Create a new account on hCaptcha and note the sitekey and the secret token
  3. Invite the bot to your Telegram channel and set it as admin

Run tests

  1. pipenv run python -m pytest
  2. With coverage:
  3. pipenv run coverage run --include="app/*" -m pytest
  4. Show report: pipenv run coverage report -m or as html: pipenv run coverage html && open htmlcov/index.html
  5. Run single test method: e.g. python -m pytest app/tests/test_bot.py -k 'test_is_verified'
  6. 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
  • 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

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.