Created
March 22, 2020 22:12
-
-
Save maxtacu/e1492563aef108b02172037149439617 to your computer and use it in GitHub Desktop.
Telegram webhook bot for cleaning forwarded channel messages in discussion group
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import telebot, os | |
from flask import Flask, request | |
__location__ = os.path.realpath( | |
os.path.join(os.getcwd(), os.path.dirname(__file__))) | |
keyfile = open(os.path.join(__location__, 'apiKey.txt'), "r") | |
token = keyfile.read().replace('\n', '') | |
secret = 'SECRET-URL-PATH' # for example: 2412qweh15sf14s234jeqwe | |
url = 'YOUR-URL/' + secret | |
bot = telebot.TeleBot(token, threaded=False) | |
bot.remove_webhook() | |
bot.set_webhook(url=url) | |
app = Flask(__name__) | |
@app.route('/'+secret, methods=['POST']) | |
def webhook(): | |
update = telebot.types.Update.de_json(request.stream.read().decode('utf-8')) | |
bot.process_new_updates([update]) | |
return 'ok', 200 | |
@bot.message_handler(commands=['start']) | |
def start(message): | |
bot.send_message(message.chat.id, 'Hello, welcome to Discussion Cleaner bot!') | |
@bot.message_handler(func=lambda message: message.forward_from_chat, content_types=["text", "document", "sticker", "pinned_message", "photo", "audio", "video"]) | |
def message(message): | |
bot.delete_message(message.chat.id, message.message_id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment