Skip to content

Instantly share code, notes, and snippets.

@devstar0209
Last active March 4, 2024 02:17
Show Gist options
  • Save devstar0209/84feaa044003191ba2b508a70915459d to your computer and use it in GitHub Desktop.
Save devstar0209/84feaa044003191ba2b508a70915459d to your computer and use it in GitHub Desktop.
Notify to me when a specific users makes a comment in a group in telegram
# pip install python-telegram-bot
from telegram.ext import Updater, MessageHandler, Filters
from telegram import ParseMode
import logging
# Set your Telegram bot token
TOKEN = 'your_bot_token'
# Set the user ID you want to monitor
target_user_id = 'target_user_id' # You can get this by sending a message to the bot and checking the updates
# Set the group chat ID where you want to monitor comments
group_chat_id = -1001234567890 # Replace with your group chat ID
# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
# Define the function to handle incoming messages
def check_comments(update, context):
message = update.message
# Check if the message is a reply
if message.reply_to_message and message.reply_to_message.from_user.id == target_user_id:
# Notify the user about the comment
context.bot.send_message(chat_id=group_chat_id, text=f"{message.from_user.username} commented on {message.reply_to_message.from_user.username}'s message:\n\n{message.text}", parse_mode=ParseMode.MARKDOWN)
# Set up the updater with your bot token
updater = Updater(token=TOKEN, use_context=True)
# Get the dispatcher to register handlers
dp = updater.dispatcher
# Register the check_comments function to handle text messages
dp.add_handler(MessageHandler(Filters.text & Filters.chat(chat_id=group_chat_id), check_comments))
# Start the Bot
updater.start_polling()
# Run the bot until you send a signal to stop it
updater.idle()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment