add admin_forward
Marco Andronaco andronacomarco@gmail.com
Sat, 24 Jun 2023 13:59:17 +0200
3 files changed,
39 insertions(+),
2 deletions(-)
M
main.py
→
main.py
@@ -14,6 +14,13 @@
await update.channel_post.forward(GROUP_ID) return logger.info("Forwarded a message.") +async def admin_forward(update: Update, _): + try: + await update.message.forward(ADMIN_ID) + return logger.info(f"Forwarded this message to admin: {update.message.text}") + except: + return logger.error(f"Couldn't forward this update to admin: {update}") + def config_error(): logger.error("Please create and fill the .env file.") exit(1)@@ -27,12 +34,14 @@ try:
TOKEN = str(getenv("token")) GROUP_ID = int(getenv("group_id")) CHANNEL_ID = int(getenv("channel_id")) + ADMIN_ID = int(getenv("admin_id")) except TypeError: config_error() - if '' in [TOKEN, GROUP_ID, CHANNEL_ID]: + if '' in [TOKEN, GROUP_ID, CHANNEL_ID, ADMIN_ID]: config_error() application = ApplicationBuilder().token(TOKEN).build() application.add_handler(MessageHandler(filters.ChatType.CHANNEL, forward)) + application.add_handler(MessageHandler(filters.ChatType.PRIVATE, admin_forward)) application.run_polling()
M
send.py
→
send.py
@@ -9,11 +9,38 @@ "chat_id": getenv("group_id"),
"text": "Hello world!", "parse_mode": "markdown", - "reply_to_message_id": None, + "reply_to_message_id": "", "disable_web_page_preview": False, "disable_notification": False, } ## Config end + +''' EXAMPLES + +endpoint = "sendVideo" +payload = { + "chat_id": getenv("group_id"), + "video": "https://media.tenor.com/zKYNgCu5TjYAAAAC/ness-pk-fire.gif", + "caption": "Test caption", + + "parse_mode": "markdown", + "reply_to_message_id": "", + "disable_web_page_preview": False, + "disable_notification": False, +} + +endpoint = "sendPhoto" +payload = { + "chat_id": getenv("group_id"), + "photo": "https://media.tenor.com/zKYNgCu5TjYAAAAC/ness-pk-fire.gif", + "caption": "Test caption", + + "parse_mode": "markdown", + "reply_to_message_id": "", + "disable_web_page_preview": False, + "disable_notification": False, +} +''' from requests import post response = post(f"https://api.telegram.org/bot{getenv('token')}/{endpoint}", json=payload,