Skip to content

Instantly share code, notes, and snippets.

@maxtacu
Created March 22, 2020 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxtacu/e1492563aef108b02172037149439617 to your computer and use it in GitHub Desktop.
Save maxtacu/e1492563aef108b02172037149439617 to your computer and use it in GitHub Desktop.
Telegram webhook bot for cleaning forwarded channel messages in discussion group
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