ehForwarderBot / efb-telegram-master

EFB Telegram Master Channel, a channel for EH Forwarder Bot.
GNU Affero General Public License v3.0
223 stars 78 forks source link

[FR] automatic group creating feature #126

Open QQ-War opened 2 years ago

QQ-War commented 2 years ago

Currently, for each contact or group in slave channel, we need to create new group and use /link command to link out. I am thinking of some ways to make it automaticly. I find Pyrogram has this kind of interface and we can make use of it. The idea is like to at least to change 3 parts in the code:

  1. configuration part and class init, need to use a parameter to enable this feature or not. if enable, need to provide api id and api hash, then initiate the client.
  2. message send out part, need to add some mechanism to check if this chat has already link to a group, othewise will use the interface provided by pyrogram to create one and make the link, then update_info of that group.
  3. database part, currently allow 1 group to link more than 1 slave group. maybe need to change 1 to 1. otherwise, I have not think of an idea how to do it.

There are some other issues may need to consider, but to realize it will make life happy. I am trying to read the code of this project, and maybe I will offer some help to submit on PR later. but what will others think of it?

blueset commented 2 years ago

Thank you for the suggestion. Automatically creating a Telegram group while trying to link a slave chat is definitely a great feature to have. However, Telegram does not allow a bot to create groups, no matter if it is using the HTTP interface (via python-telegram-bot) or using MTProto (via Pyrogram, Telethon, etc.). Group creation is only possible for normal users that registered with a phone number.

The only way to incorporate such feature, without any privacy concern, would be to ask the user to setup a “user bot” using their own phone number. Including such feature into ETM would require:

If you feel this is doable, feel free to send in your PRs. I’m glad to answer any question you might have in mind.

QQ-War commented 2 years ago

Thanks very much . One friend already prepared one version of code, and test running well , except there are 2 issues, we are not very clear how to solve. the address is: https://github.com/QQ-War/efb-telegram-master?organization=QQ-War&organization=QQ-War

issue 1: (solved) after automatic new created one telegram group, the first message send to this slave group, still will be send by the wechat bot, not inside that group, it is very strange. the code position is below: https://github.com/QQ-War/efb-telegram-master/blob/21cc99146fa07ae3c1f808268e762c11edcb522c/efb_telegram_master/slave_message.py#L247

issue 2: to update the group name and group image, better to use update_group_info in ChatBindingManager class, but we are not quite clear how to pass the parameters update and context. so we use the pyrogram itself and create some method. it is not graceful and not very efficient, since sometimes it fails. the code position is below, if possible, better change this function to the same position of issue 1. https://github.com/QQ-War/efb-telegram-master/blob/21cc99146fa07ae3c1f808268e762c11edcb522c/efb_telegram_master/auto_tg_manager.py#L90

could you help to check? Thanks.

chern91552 commented 1 year ago

@QQ-War Thank you for your development. I want to feed back two bugs

  1. Issue 1 which your marked solved still appears
  2. Some friends can't use update_ Info, show:Chat linked (c941b0c2) is not found in the slave channel (WeChat Slave, blueset. wechat)
blueset commented 1 year ago

For issue 2, if you already have a user bot, it might be easier to just issue an /update_info command to EFB through the user. Alternatively, you can consider constructing an Update object mimicking an /update_info message sent to the bot. It is technically possible since these objects are constructed from plain JSON objects, but it might require more effort than simply sending a message.