Repository: voidbar/forwardgram
Branch: master
Commit: a165311f1134
Files: 5
Total size: 3.9 KB
Directory structure:
gitextract_z3u59ef3/
├── .gitignore
├── README.md
├── config.yml-sample
├── forwardgram.py
└── requirements.txt
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
*.pyc
venv
.vscode
__pycache__
*.exe
config.yml
*.session
*.session-journal
================================================
FILE: README.md
================================================
# forwardgram
Forward messages from multiple Telegram channels or chats to one (or more) chat or channel of your own!
## Prerequisites
- Python 3.6+
## Setup
- `python3 -m pip install -r requirements.txt`.
- Fill out a configuration file. An example file can be found at `config.yml-sample`.
## Run
`python3 forwardgram.py {YOUR_CONFIG_FILE}`
Please note that in the first time initializing the script, you will be requried to validate your phone number using telegram API. This happens only at the first time (per session name).
================================================
FILE: config.yml-sample
================================================
api_id: 123456 # This has to be an integer. Read more [here](https://core.telegram.org/api/obtaining_api_id)
api_hash: 'abcdefg' # Long 32 characters hash identifier. Read more [here](https://core.telegram.org/api/obtaining_api_id)
session_name: 'forwardgram' # Session name. Only one session (with a unique session name) can run at a time
# The channel names that you'd like to forward messages from.
# The user running the client must have these channels present on it's dialogs.
input_channel_names:
- 'Input Channel Name 1'
- 'Input Channel Name 2'
# The output channel names that the messages will be forwarded to.
# The user running the client must have a write access to those channels, and have the channels present on theirs dialogs.
output_channel_names:
- 'Output Channel Name 1'
- 'Output Channel Name 2'
# The channel IDs that you'd like to forward messages from. (You can get a channel ID by forwarding any message from it to @userinfobot , and removing the -100 from the start )
input_channel_ids:
- ID1 # Input Channel ID without quotes ''
- ID2
# The output channel IDs that the messages will be forwarded to. (You can get a channel ID by forwarding any message from it to @userinfobot , and removing the -100 from the start )
output_channel_ids:
- ID1 # Output Channel ID without quotes ''
- ID2
# An empty list should be set like this:
# input_channel_ids: []
================================================
FILE: forwardgram.py
================================================
from telethon import TelegramClient, events, sync
from telethon.tl.types import InputChannel
import yaml
import sys
import logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logging.getLogger('telethon').setLevel(level=logging.WARNING)
logger = logging.getLogger(__name__)
def start(config):
client = TelegramClient(config["session_name"],
config["api_id"],
config["api_hash"])
client.start()
input_channels_entities = []
output_channel_entities = []
for d in client.iter_dialogs():
if d.name in config["input_channel_names"] or d.entity.id in config["input_channel_ids"]:
input_channels_entities.append(InputChannel(d.entity.id, d.entity.access_hash))
if d.name in config["output_channel_names"] or d.entity.id in config["output_channel_ids"]:
output_channel_entities.append(InputChannel(d.entity.id, d.entity.access_hash))
if not output_channel_entities:
logger.error(f"Could not find any output channels in the user's dialogs")
sys.exit(1)
if not input_channels_entities:
logger.error(f"Could not find any input channels in the user's dialogs")
sys.exit(1)
logging.info(f"Listening on {len(input_channels_entities)} channels. Forwarding messages to {len(output_channel_entities)} channels.")
@client.on(events.NewMessage(chats=input_channels_entities))
async def handler(event):
for output_channel in output_channel_entities:
await client.forward_messages(output_channel, event.message)
client.run_until_disconnected()
if __name__ == "__main__":
if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} {{CONFIG_PATH}}")
sys.exit(1)
with open(sys.argv[1], 'rb') as f:
config = yaml.safe_load(f)
start(config)
================================================
FILE: requirements.txt
================================================
telethon
pyyaml
gitextract_z3u59ef3/ ├── .gitignore ├── README.md ├── config.yml-sample ├── forwardgram.py └── requirements.txt
SYMBOL INDEX (1 symbols across 1 files) FILE: forwardgram.py function start (line 12) | def start(config):
Condensed preview — 5 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (4K chars).
[
{
"path": ".gitignore",
"chars": 82,
"preview": "*.pyc\r\nvenv\r\n.vscode\r\n__pycache__\r\n*.exe\r\nconfig.yml\r\n*.session\r\n*.session-journal"
},
{
"path": "README.md",
"chars": 534,
"preview": "# forwardgram\nForward messages from multiple Telegram channels or chats to one (or more) chat or channel of your own!\n\n#"
},
{
"path": "config.yml-sample",
"chars": 1429,
"preview": "api_id: 123456 # This has to be an integer. Read more [here](https://core.telegram.org/api/obtaining_api_id)\r\napi_hash: "
},
{
"path": "forwardgram.py",
"chars": 1979,
"preview": "from telethon import TelegramClient, events, sync\r\nfrom telethon.tl.types import InputChannel\r\nimport yaml\r\nimport sys\r\n"
},
{
"path": "requirements.txt",
"chars": 16,
"preview": "telethon\r\npyyaml"
}
]
About this extraction
This page contains the full source code of the voidbar/forwardgram GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 5 files (3.9 KB), approximately 1.0k tokens, and a symbol index with 1 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.