├── Procfile ├── README.md ├── app.json ├── main.py └── requirements.txt /Procfile: -------------------------------------------------------------------------------- 1 | worker: python3 main.py 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Channel Auto Message Post 2 | 3 | A script to automate fowarding all new messages from one/many channel(s) to another channel(s), without the forwarded tag. 4 | 5 | 6 | ## Config vars 7 | > `APP_ID` and `API_HASH` - Get it from my.telegram.org 8 | 9 | > `SESSION` - A telethon session string, get it from @stringsessionbot 10 | 11 | > `FROM_CHANNEL` - Channel ID(s) split by space or just one channel ID. 12 | 13 | > `TO_CHANNEL` - Channel ID(s) split by space or just one channel ID. 14 | 15 | 16 | # Usage 17 | All new messages will be auto-posted!! Join the channel from you want the posts to be taken. Join as admin in the channel where you want the posts to be sent to. 18 | 19 | 20 | ## Deploy to Heroku 21 | 22 | [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/samadii/ChannelAutoCopy) 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Channel Auto Forward", 3 | "description": "Telegram Bot To Forward Msg.", 4 | "env": { 5 | "API_HASH": { 6 | "description": "You API HASH from my.telegram.org", 7 | "value": "" 8 | }, 9 | "APP_ID": { 10 | "description": "You API ID from my.telegram.org", 11 | "value": "" 12 | }, 13 | "SESSION": { 14 | "description": "enter your Telethon string session, you can get it from @stringsessionbot.", 15 | "value": "" 16 | }, 17 | "FROM_CHANNEL": { 18 | "description": "enter the channel ID(s) here, separate by space, get it from @chnlidbot", 19 | "value": "" 20 | }, 21 | "TO_CHANNEL": { 22 | "description": "enter your channel ID(s) here, separate by space, get it from @chnlidbot", 23 | "value": "" 24 | } 25 | }, 26 | "buildpacks": [ 27 | { 28 | "url": "heroku/python" 29 | } 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from telethon import TelegramClient, events 4 | from decouple import config 5 | import logging 6 | from telethon.sessions import StringSession 7 | 8 | logging.basicConfig(format='[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s', level=logging.WARNING) 9 | 10 | print("Starting...") 11 | 12 | # Basics 13 | APP_ID = config("APP_ID", default=None, cast=int) 14 | API_HASH = config("API_HASH", default=None) 15 | FROM_ = config("FROM_CHANNEL") 16 | TO_ = config("TO_CHANNEL") 17 | string = os.environ.get('SESSION') 18 | 19 | FROM = [int(i) for i in FROM_.split()] 20 | TO = [int(i) for i in TO_.split()] 21 | 22 | try: 23 | Bot = TelegramClient(StringSession(string), APP_ID, API_HASH) 24 | Bot.start() 25 | except Exception as ap: 26 | print(f"ERROR - {ap}") 27 | exit(1) 28 | 29 | @Bot.on(events.NewMessage(incoming=True, chats=FROM)) 30 | async def send(event): 31 | for i in TO: 32 | try: 33 | if event.poll: 34 | return 35 | if event.photo: 36 | photo = event.media.photo 37 | await Bot.send_file(i, photo, caption = event.text, link_preview = False) 38 | elif event.media: 39 | try: 40 | if event.media.webpage: 41 | await Bot.send_message(i, event.text, link_preview = False) 42 | return 43 | except: 44 | media = event.media.document 45 | await Bot.send_file(i, media, caption = event.text, link_preview = False) 46 | return 47 | else: 48 | await Bot.send_message(i, event.text, link_preview = False) 49 | 50 | except Exception as e: 51 | print(e) 52 | 53 | print("Bot has started.") 54 | Bot.run_until_disconnected() 55 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | python-decouple 2 | telethon 3 | --------------------------------------------------------------------------------