A. Telegram Assistant: Brief Description
Telegram Assistant is a bot that monitors messages in your Telegram group around the clock.
Each time a keyword from your list is found in messages, the bot sends you a notification.
Also, the bot can automatically delete messages, such as spam, hate or swearing.
In addition, the bot can remove the authors of such messages from the group and block them.
Or vice versa, you may receive notifications of messages on a topic of interest to you.
Of course the owner of a chat or group can keep track of the necessary messages, but with a large number of group members, this is difficult, so the bot can be of great help here.
You can replenish or change the list of keywords at any time, as well as set the type of reaction to such messages (Notification, Deletion, Blocking).
- Install Telegram Assistant add-on if you haven’t already.
- Create a copy of the Telegram Assistant (WebApp) spreadsheet.
Please DO NOT rename the «DebugLog» and «Settings» sheets.
- Create a Telegram bot according to How to create a bot? and BotFather.
- In cell A2 Settings sheet enter the bot’s API Token.
- Make the bot the admin of the group it should monitor.
- In the bot settings in the group, allow it to delete messages.
- In the created copy of the Telegram Assistant (WebApp) spreadsheet, select the menu item Extensions / Apps Script.
- Deploy the script as a web application with permissions: Execute as: Me, Who has access: Anyone.
- Give all necessary permissions. This is done 1 time at the first start.
- Copy the web application URL and paste into cell C2 Settings sheet.
- Now set up a trigger that will watch for new messages in the DebugLog sheet and look for keywords in them. To do this, Extensions / Telegram Assistant menu select Set Up. Give all necessary permissions.
- Check if everything is done correctly. To do this, send any text to the group.
- A new line appears in the DebugLog sheet. In the Date column — the date the message was sent, in Chat Name — the name of the group, in Chat Id — its identifier, in User First name — the sender’s name, in User Id — the sender’s identifier, in Message — the text of the message, in Message Id — the message identifier.
- Since you sent this message, the User Id is your identifier. Paste your ID into cell B2 Settings sheet. So the bot will know who to send notifications to.
- Enter your keywords in cells A6, A7 and below.
- Check the appropriate boxes in the columns Alarm, Delete and Ban next to the keywords. If you check the Alarm, then when a keyword is found in the message text, an alarm message will be sent to you. If you check the Delete, then when a keyword is found in the message text, this message will be deleted automatically. If you check the Ban, then when a keyword is found in the message text, this user will be blocked automatically.
- Do another check. To do this, send a text to the group containing one of the keywords, which has a checkmark in the Alarm. A notification will be sent to you.
- Send text to the group that contains one of the keywords that has a checkmark in the Delete. This message will be removed from the group automatically.
- Send a text to the group that contains one of the keywords that is checked in the Alarm and in the Ban. An alert message will be sent to you, and the user itself will be blocked in the group automatically. Note that the group owner cannot be blocked. Therefore, for verification, you can ask someone else to write the forbidden word.
- To unlock, the user must write any message to the bot. After that, make sure that the row with its message is the last row on the DebugLog sheet. To do this, you can delete the extra or copy the row with its data to the end of the sheet. Then, in the Extensions / Telegram Assistant menu, select UnBan User. The user will be unblocked and sent a message with an invitation link to join the group.
Video for those who like to watch😉
May 21, 2022, updates:
- The sequence of actions has been shortened, the Set Webhook and Set trigger items have been merged into one Set Up.
- Added the ability to automatically block a user and unblock him from the menu.
Video 2 — updated procedure + lock/unlock.