Created
October 2, 2023 07:38
-
-
Save gordinmitya/c332c213e312585641b19f9abc38eab1 to your computer and use it in GitHub Desktop.
Python bot to get user_id by forwarded message
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
""" | |
pip install python-telegram-bot | |
""" | |
from telegram import Update | |
from telegram.ext import ApplicationBuilder, MessageHandler, ContextTypes | |
import telegram.ext.filters as filters | |
async def any_message_handler(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: | |
msg = f'Your user id is `{update.effective_user.id}`\n' | |
if update.message.forward_from: | |
user_id = update.message.forward_from.id | |
msg += f'You forwarded a message from `{user_id}`' | |
await update.message.reply_markdown(msg, reply_to_message_id=update.message.message_id) | |
app = ApplicationBuilder().token("TOKEN HERE").build() | |
app.add_handler(MessageHandler(filters.ALL, any_message_handler)) | |
app.run_polling() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment