admin管理员组文章数量:1353308
Is there any way using Python / JS to forward messages which I, as a member, do receive in a private read-only group? I'm trying to set it up using python-telegram-bot but it seems I gotta add the bot to the group to have it interact with the contents sent in the group. But I can't as Im just a reading / receiving member...
Is there maybe a way without using the Telegram API, but using some sort of JS Browser automation to forward those? This is the only thing which es to my mind... Thanks in advance!
Is there any way using Python / JS to forward messages which I, as a member, do receive in a private read-only group? I'm trying to set it up using python-telegram-bot but it seems I gotta add the bot to the group to have it interact with the contents sent in the group. But I can't as Im just a reading / receiving member...
Is there maybe a way without using the Telegram API, but using some sort of JS Browser automation to forward those? This is the only thing which es to my mind... Thanks in advance!
Share Improve this question edited May 19, 2021 at 8:30 tim asked May 18, 2021 at 18:16 timtim 10k22 gold badges86 silver badges145 bronze badges2 Answers
Reset to default 6Answering my own question in case someone needs it.
As @CallMeStag pointed out, one needs a library which support "User bots". These are librarys directly implementing the MTProto.
For python, e.g. Pyrogram is suitable and very easy to use.
First of all, one needs an API key and API hash to identify the Python Script on the Telegram server to municate in the MTProto.
https://my.telegram/auth?to=apps -> Login using your credentials and create an "App". Define those into API_ID
and API_HASH
below.
Now, I use this code to copy messages from the SOURCE_CHAT
to the TARGET_chat
:
#!/usr/bin/env python3
from pyrogram import Client
from pyrogram import filters
# ~~~~~~ CONFIG ~~~~~~~~ #
ACCOUNT = "@xy"
PHONE_NR = '+49....'
# https://my.telegram/auth?to=apps
API_ID = 1111111
API_HASH = "your_hash"
# CHAT ID
SOURCE_CHAT = -11111
TARGET_CHAT = -22222
# ~~~~~~~~~~~~~~~~~~~~~~ #
app = Client(
ACCOUNT,
phone_number=PHONE_NR,
api_id=API_ID,
api_hash=API_HASH
)
# filters.chat(SOURCE_CHAT)
@app.on_message(filters.chat(SOURCE_CHAT))
def my_handler(client, message):
message.copy( # copy() so there's no "forwarded from" header
chat_id=TARGET_CHAT, # the channel you want to post to
caption="Copied from XYZ" # Caption
)
app.run()
To find out the CHAT_ID
of Source and Target, I temporarly disabled the Filter, and printed the message.
@app.on_message()
def my_handler(client, message):
print(message)
Doing so, enables you to: whenever receiving a message in the specific group, you can find message.chat.id
(attention: negative Values!). Configure those for SOURCE_CHAT
and TARGET_CHAT
in the full script above.
EDIT: Another option to get all chat IDs for all dialogues without first needing someone to send a message in the channel/group/private/chat:
def getAllChatIDs():
for x in app.get_dialogs():
print (x.chat.type, x.chat.title, x.chat.id)
Simply call it once and you'll get a list of dialogues :)
It's indeed not possible with Telegram Bots - you'd have to add them to the group. You can however automate your personal account using so called "user bots". Here is an article about them.
本文标签: javascriptTelegram Bot Forwarding Messages from Private GroupStack Overflow
版权声明:本文标题:javascript - Telegram Bot: Forwarding Messages from Private Group - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743924537a2562715.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论