voidbar / forwardgram

Forward messages from multiple Telegram channels to one of your own!
154 stars 183 forks source link

Use channel ID or link as input_channel #7

Closed DaDaDa12138 closed 4 years ago

DaDaDa12138 commented 4 years ago

Hi there, thanks for providing this great script firstly.

I faced a problem when I use this script, some channels may change their names sometimes, and then I need to manually change that in the config file. So is that possible to use Channel Id or link in the config file as input channel.

Thanks for your helping.

JuanMiguelPR commented 4 years ago

Yeah, using the channel id directly is completely possible. You just need to use the name once to get the id, you can print it and then copy it into the script.

JuanMiguelPR commented 4 years ago

Also, if you leave the script running around the clock (wich will be logic for me, as you want to forward the messages automatically) and they change the name, then no action is required. The id is already taken. It's needed to reconfigure the name in the config file only if you stop the code and run it again.

DaDaDa12138 commented 4 years ago

Thanks for your quick replying.

I tried to copy the channel ID into the config file like

 input_channel_names:
  - '-1001001142398'  

but the terminal shows there is no channel listening. am I doing any wrong format?

JuanMiguelPR commented 4 years ago

You are giving an id into a name variable. You must make changes in the main file to use the id directly. Maybe changing in the config file "input_channel_names:" to input_channel_ids" so it keeps the logic too.

DaDaDa12138 commented 4 years ago
input_channels_entities = []
    output_channel_entity = None
    for d in client.iter_dialogs():
        if d.name in config["input_channel_ids"]:
            input_channels_entities.append(InputChannel(d.entity.id, d.entity.access_hash))
        if d.name == config["output_channel_name"]:
            output_channel_entity = InputChannel(d.entity.id, d.entity.access_hash)

simplly change both to "input_channel_ids" , not work, seems I need to change something in this part, I tried few times but still failed. Any suggestions on that?

JuanMiguelPR commented 4 years ago

Changing the name of the variable will obviously not work, I suggested that just for keeping the logic.

With the channel id and the access hash you don't even need to inter through d. You just give the input channel directly, with the append, the id and access hash.

voidbar commented 4 years ago

You are more then welcome to open a PR :)