Telegram bot for controlling spam, logging, and more
Go to file
Stan James e6d001eac2 Fix problem with adding users.
Added comments too.
2018-02-22 16:36:09 -08:00
.gitignore Cleaned up README and moved config info out of version control 2018-01-28 22:29:50 -07:00
bot.py Fix problem with adding users. 2018-02-22 16:36:09 -08:00
LICENSE Initial commit 2018-01-25 19:51:46 -07:00
model.py If banned, don't bother with message check 2018-02-10 08:55:10 -07:00
mwt.py Disable checks for admins 2018-02-22 15:38:02 -08:00
Procfile Fixing Error R10 2018-01-31 08:30:07 -07:00
README.md Merge branch 'develop' of github.com:OriginProtocol/origin-telegram-logger-bot into develop 2018-02-10 22:25:16 -07:00
requirements.txt Added Unidecode to reqs 2018-02-01 21:02:19 -07:00

Telegram Bot

  • Deletes messages matching specified patterns
  • Bans users for posting messagses matching specified patterns
  • Bans users with usernames matching specified patterns
  • Records logs of converstations

Installation

  • Required: Python 3.x, pip, PostgreSQL
  • Create virtualenv
  • Clone this repo
  • pip install --upgrade -r requirements.txt

Database setup

  • Store database URL in environment variable.
export TELEGRAM_BOT_POSTGRES_URL="postgresql://<user>:<password>@localhost:5432/<databasename>"
  • Run: python model.py to setup the DB tables.

Setup

  • Create a Telegram bot by talking to @BotFather : https://core.telegram.org/bots#creating-a-new-bot
  • Use /setprivacy with @BotFather in order to allow it to see all messages in a group.
  • Store your Telegram Bot Token in environment variable TELEGRAM_BOT_TOKEN. It will look similar to this:
export TELEGRAM_BOT_TOKEN="4813829027:ADJFKAf0plousH2EZ2jBfxxRWFld3oK34ya"

Configuring patterns

  • Regex patterns will be read from the following env variables
    • MESSAGE_BAN_PATTERNS Messages matching this will ban the user.
    • MESSAGE_HIDE_PATTERNS Messages matching this will be hidden/deleted
    • NAME_BAN_PATTERNS Users with usernames or first/last names maching this will be banned from the group.
    • SAFE_USER_IDS User ID's that are except from these checkes. Note that the bot cannot ban admin users, but can delete their messages.

Sample bash file to set MESSAGE_BAN_PATTERNS:

read -r -d '' MESSAGE_BAN_PATTERNS << 'EOF'
# ETH Address
# e.g. F8C8405e85Cfe42551DEfeB2a4548A33bb3DF840
[0-9a-fA-F]{40,40}
# BTC Address
# e.g. 13qt9rCA2CQLZedmUuDiPkwdcAJLsuTvLm
|[0-9a-fA-Z]{34,34}
EOF

Running

Locally

  • Run: python bot.py to start logger
  • Messages will be displayed on stdout as they are logged.

On Heroku

  • You must enable the worker on Heroku app dashboard. (By default it is off.)