Telegram bot to remove spam

    UPD: The latest bot documentation is located at https://tgdev.io/bot/daysandbox_bot


    I decided to write this publication because tired of explaining the same thing to people who want to use my telegram bot @daysandbox_bot . So, a few months ago I developed a bot for removing spam by a very simple criterion: if a person went into chat and spent less than a day in it, then any links or forward messages from this person are deleted. Everything. No neural networks, frequency analysis, moderated white and black lists and other complicated things. Surprisingly, the bot has gained some popularity and is already working in more than six hundred chat rooms. Next, I will try to describe in detail the principle of the bot to give a link to this article in the future.


    The principle of the bot


    From the moment it is added to the chat, the bot keeps track of the events when new users entered the group and thereby knows when someone went into the chat and how much time he already spent in the chat. Due to the limitations of the telegram API, I can’t find out when those users who were already at the time the bot was added to the chat joined the chat. The bot does not analyze messages from users existing at the time the bot was added. So, the bot knows when new users entered the chat. If the bot sees that the user spent less than a day in the chat and posted a message that meets the definition of spam, then the bot deletes the message. It does not ban the user, does not give him read-only rights, the bot simply deletes the spam message. If the user posts a non-spam message, it will be published. What messages are considered spam? Firstly, any messages containing a link:username . Secondly, any forward messages i.e. Messages sent from another chat. There is an exception to the username rule; if username refers to a user, then such a message is allowed. The bot deletes only those messages with username that refer to the group or channel. This is done so that there are no false positives when a new user simply tries to contact some chat participant by his username.


    What the daysandbox_bot bot does NOT


    • The bot does not ban anyone and never
    • The bot does not filter messages from those chat participants who were already in the chat at the time the bot was added
    • The bot only filters messages from users who have spent less than 24 hours in a chat. If the user spent more than a day in the chat, his messages are not processed by the bot
    • The bot does not analyze the text of the message, it simply deletes the messages with links. Everything.

    How to add bot to chat properly


    I describe the algorithm for the desktop client. It is understood that you are the admin of the chat room and you can add other admins to it.


    • We go into the chat room, click on the name of the chat room on top
    • In the window that opens, to the right of the inscription "Group Information", click on the icon from three points
    • In the menu that opens, click on "Group Management"
    • In the menu that opens, click on "Administrators"
    • In the window that opens below, click on "Add administrator"
    • In the window that opens, enter daysandbox_bot in the search bar
    • In the updated search results, click on the DaySandBox bot, it should have a yellow pacman icon.
    • In the window that opens, set the bot to delete messages, disable all other rights.
    • Click "Save"

    Bot settings


    The bot has several settings.


    Write in a chat room /daysandbox_set safe_hours=Nto set the time during which messages from new users are analyzed for signs of spam. By default, this period is equal to days. You can specify the number of hours from zero to 8760 (one year). A period of zero hours essentially deactivates the bot.


    Write in a chat room /daysandbox_set publog=yesto allow the bot to write messages to the chat that a user’s message has been deleted. By default, the bot does just that.


    The current values ​​of these two settings can be obtained with the command /daysandbox_config.


    Some statistics


    I am too lazy to draw beautiful graphics, I can only say that the bot removes 10 to 15 thousand messages per day and works in more than 600 chat rooms.


    Open source


    The bot source is publicly available on github .
    UPD (February 11, 2019): at the moment, the source code for the outdated version of the bot is in the repository. I do not provide the source code for the current version of the bot.


    My other bots


    You might be interested in other bots that I developed. You can find the full list of bots at https://tgdev.io


    Contacts for communication


    Groups for discussion of my bots:



    UPD: The latest bot documentation is located at https://tgdev.io/bot/daysandbox_bot


    Also popular now: