Giter VIP home page Giter VIP logo

telegram-message-forwarder-bot's Introduction

Telegram Message Forwarder Bot

A telegram bot, which can forward messages from channel, group or chat to another channel, group or chat automatically.

Deploy

Configuration

To configure this bot you have to use the file template at sample.config.toml. Rename it to config.toml and fill the values as described below. If you want to pass the values as environment variables, then pass the content of the config.toml file as environment variable CONFIG.

Pyrogram Section

  • api_id - Your Telegram API ID.
  • api_hash - Your Telegram API Hash.
  • session_string - (Optional if bot_token is provided) Session string of your Telegram account. You can get it by running get_session.py file.
  • bot_token - (Optional if session_string is provided) Bot token of your Telegram bot. You can get it by creating a bot using BotFather.
  • sudo_users - (Optional) List of user ids of users who can use the bot. You can get your user id by sending /id command to Rose.
[pyrogram]
api_id = 12345                                                      # required
api_hash = "0123456789abcdef0123456789abcdef"                       # required
bot_token = "123456789:ABCdefGhIJKlmNoPQRsTUVwxyZ"                  # either bot_token or session_string is required
session_string = "1BVn1-ABCD1234efgh5678IJKLmnoPQRsTUVwxyZxxxxxxxx" # either bot_token or session_string is required
sudo_users = [123456789, 123456789]                                 # optional

Chats Section

  • from - Chat id of the chat from which messages will be forwarded. You can get it by sending /id command to Rose.
  • to - Chat id of the chat to which messages will be forwarded. You can get it by sending /id command to Rose.
  • replace - (Optional) A dictionary of strings to replace in the message. The key is the string to be replaced and the value is the string to replace with. This is optional.

You can add multiple chats by using the following format.

[[chats]]
from = -100123456789        # required
to = 123456789              # required
replace = { "old" = "new" } # optional

[[chats]]
from = [123456789, -100123456789]               # required
to = 123456789                                  # required
replace = { "only_apply_to_this_chat" = "new" } # optional

[[chats]]
from = -100123456789            # required
to = [123456789, -100123456789] # required

Note: The chats should be in the format of int or list of int. If you want to use usernames, then you have to use the chat_id of the chat. You can get it by sending /id command to Rose.

Note

  • Supported identifier for a chat should be the chat id.
  • Use /forward command to forward older messages. For message older than 2 days you have to login as a user and set the session_string variable in pyrogram section. Command usage - /forward <Chat ID/Username/Message Link> <Limit, No. of Messages to forward> <ID of the last message of from chat to avoid repetition>

Deployment

Clone the repository

git clone <repo-url> telegram-message-forwarder-bot
cd telegram-message-forwarder-bot

Install the requirements

Install the required Python Modules in your machine.

pip3 install -r requirements.txt

Start the bot

With python3.10 or later.

python3 -m bot

Docker

Build the image.

docker build -t telegram-message-forwarder-bot .

Run the container.

docker run -d --name telegram-message-forwarder-bot telegram-message-forwarder-bot

Contributing

  • Fork the repository.
  • Create a new branch.
  • Make your changes.
  • Commit and push the changes to your fork.
  • Create a pull request.

Support

Copyright & License

telegram-message-forwarder-bot's People

Contributors

irajdeeppalsana avatar tompluess avatar viperadnan-git avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

telegram-message-forwarder-bot's Issues

Heroku/Salesforce violation of Acceptable Use and External-Facing Services Policy

First of all, many thanks for your nice code!

Disclaimer: I'm a newbie with Heroku and Telegram bots.

When I try to deploy the app on Heroku, I get a popup saying that my app cannot be deployed due to a violation of Acceptable Use and External-Facing Services Policy. Has something changed in Salesforce policies or am I doing something wrong?

Add Saved message(me) also

There is no option to add the saved messages chat in
FROM_CHATS and in TO_CHATS

So , that we can use "me" for saving in saved messages

REMOVE_STRINGS not working on some messages

the following error is generated on removing strings from some messages. any suggestion on this?
thanks
/usr/local/lib/python3.6/dist-packages/pyrogram/dispatcher.py - ERROR] 'NoneType' object has no attribute 'html' Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/pyrogram/dispatcher.py", line 223, in handler_worker *args File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run result = self.fn(*self.args, **self.kwargs) File "/root/telegram-message-forwarder-bot/bot/__main__.py", line 16, in work caption = message.caption.html.replace(string, replace_string) AttributeError: 'NoneType' object has no attribute 'html'

Multiple Channel support

can we use multiple from and multiple to's
example. What code should I give

from channel A to channel B
from channel C to channel B

Help me

Please help me i don't understand what is the actual command to start forwarding
And please give me example also while giving the solution so i will get exact idea
Screenshot_2023-12-23-21-31-14-11_74594bd74a0419242537a8d02ba17993

Forwarder don't Forward messages

image

I try to Forward messages from 1st Bot Channel, when Bot send Alarms to My own Bot channel created by bot Father.
and I have No idea why this is not working. I have check IDs, many times and is correct.

Also i tested ID from standard private conversation and seems to not working at all also.
I have connect to my Telegram bot Integromat with Token as well, but check it for unconnect token Link and seems to nothing change at all.

Did you have any idea where I make mistake with Configuration or maybe I just something mess on my telegram Bot Channels ?

delay option

hello,

can we have a delay option? so for example if multiple message are posted in "from chat" it should not flood "to chat" and should send with few seconds delay between messages

thanks

Suggestion of new feature : keeping the original author of forwarded message

Hi, thanks for develop this powerful tool to made message auto forward into an easy thing.
I came up with an idea after using this app for more then 8 months.
It will be great if we could have an option for toggle ON/OFF for keeping the original author of forwarded message.
Cause I'm using it to backup whole group chat, it's a little bit annoying to recognize the conversation...

Why does he say there is no bot file

Traceback (most recent call last):
File "C:\Users\ll\Desktop\telegram-message-forwarder-bot-main\bot_init_.py", line 7, in
from bot.helper.utils import get_formatted_chats
ModuleNotFoundError: No module named 'bot'

Unable to deploy on my local machine

I'm trying to deploy it on my pc but I couldn't
pip 22.2.2 from c:\python\python37\lib\site-packages\pip (python 3.7)
I've got this:

C:\Users\xxxx\Documents\GitHub\Telegram-signal-forwarder\telegram-message-forwarder-bot>python -m bot
[2022-08-12 13:10:00,202 - C:\Users\xxxx\Documents\GitHub\Telegram-signal-forwarder\telegram-message-forwarder-bot\bot_init_.py - INFO] Welcome, this is the telegram-message-forwarder-bot. initializing...
[2022-08-12 13:10:00,202 - C:\Users\xxxx\Documents\GitHub\Telegram-signal-forwarder\telegram-message-forwarder-bot\bot_init_.py - INFO] Bot Mode
Traceback (most recent call last):
File "C:\Python\Python37\lib\runpy.py", line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "C:\Python\Python37\lib\runpy.py", line 142, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "C:\Python\Python37\lib\runpy.py", line 109, in get_module_details
import(pkg_name)
File "C:\Users\xxxx\Documents\GitHub\Telegram-signal-forwarder\telegram-message-forwarder-bot\bot_init
.py", line 63, in
with app:
File "C:\Python\Python37\lib\site-packages\pyrogram\client.py", line 280, in enter
return self.start()
File "C:\Python\Python37\lib\site-packages\pyrogram\sync.py", line 66, in async_to_sync_wrap
return loop.run_until_complete(coroutine)
File "C:\Python\Python37\lib\asyncio\base_events.py", line 587, in run_until_complete
return future.result()
File "C:\Python\Python37\lib\site-packages\pyrogram\methods\utilities\start.py", line 58, in start
is_authorized = await self.connect()
File "C:\Python\Python37\lib\site-packages\pyrogram\methods\auth\connect.py", line 40, in connect
await self.load_session()
File "C:\Python\Python37\lib\site-packages\pyrogram\client.py", line 563, in load_session
await self.storage.open()
File "C:\Python\Python37\lib\site-packages\pyrogram\storage\file_storage.py", line 56, in open
file_exists = path.is_file()
File "C:\Python\Python37\lib\pathlib.py", line 1387, in is_file
return S_ISREG(self.stat().st_mode)
File "C:\Python\Python37\lib\pathlib.py", line 1183, in stat
return self._accessor.stat(self)

[400 PEER_ID_INVALID]

2021-04-12T04:34:21.469747+00:00 app[worker.1]: Licensed under the terms of the GNU Lesser General Public License v3 or later (LGPLv3+)
2021-04-12T04:34:21.469749+00:00 app[worker.1]:
2021-04-12T04:34:32.222167+00:00 app[worker.1]: [2021-04-12 04:34:32,221 - /app/bot/main.py - ERROR] [400 PEER_ID_INVALID]: The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it

I have logged in as a user
I got this error when the FROM_CHATS Id is of CHANNEL_ID, and
TO_CHATS id is of my another Telegram account ID
After getting this issue in logs,I send a message to my another account,and
when file received in FROM_CHATS Channel id,it send to my another Telegram account.

Is this step necessary (sending a random message to my another Telegram account)
Everytime, whenever bot restarts??

unpack requires a buffer of 271 bytes

python3 -m bot
[INFO] Loaded config.toml
[INFO] Initalizing bot...
[INFO] Monitored chats: -1001974992618
[INFO] Chats map: {-xxxxxxx: {'to': {-yyyyy}, 'replace': None}}
[INFO] Bot Started
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "/home/user/telegram-message-forwarder-bot/bot/main.py", line 66, in
app.run()
File "/home/user/venv/lib/python3.11/site-packages/pyrogram/methods/utilities/run.py", line 84, in run
self.start()
File "/home/user/venv/lib/python3.11/site-packages/pyrogram/sync.py", line 66, in async_to_sync_wrap
return loop.run_until_complete(coroutine)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/home/user/venv/lib/python3.11/site-packages/pyrogram/methods/utilities/start.py", line 58, in start
is_authorized = await self.connect()
^^^^^^^^^^^^^^^^^^^^
File "/home/user/venv/lib/python3.11/site-packages/pyrogram/methods/auth/connect.py", line 40, in connect
await self.load_session()
File "/home/user/venv/lib/python3.11/site-packages/pyrogram/client.py", line 616, in load_session
await self.storage.open()
File "/home/user/venv/lib/python3.11/site-packages/pyrogram/storage/memory_storage.py", line 59, in open
dc_id, api_id, test_mode, auth_key, user_id, is_bot = struct.unpack(
^^^^^^^^^^^^^^
struct.error: unpack requires a buffer of 271 bytes
`

sqlite3.OperationalError: unable to open database file

On my computer, I can't work.

[...]
  File "C:\Users\---\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyrogram\storage\file_storage.py", line 58, in open
    self.conn = sqlite3.connect(str(path), timeout=1, check_same_thread=False)
sqlite3.OperationalError: unable to open database file

İnstalL not found?

Hi. İm noob :)
İ can speak english a little :)

python3 install -r requirements.txt

python3: can't open file '/data/data/com.termux/files/home/telegram-message-forwarder-bot/install': [Errno 2] No such file or directory

QUESTION

Hey sir. Is it possible to forward the message to a robot?

Order of messages in FROM_CHAT not being preserved in TO_CHAT

I’ve found that when the internet connection breaks and messages are sent in the meantime to the FROM_CHAT, then after the internet connection comes back, the bot copies those messages to the TO_CHAT, but they may not be sent in the same order as they were in the FROM_CHAT. I've also found that this occurs when multiple messages are forwarded from some chat to the FROM_CHAT; the bot copies all those messages to the TO_CHAT but it may not be in the same order as in the FROM_CHAT. Is there anything that can be done to preserve the order of the messages as they are sent in teh FROM_CHAT?

Error when forwarding poll/quiz

2021-04-11T04:01:03.790280+00:00 heroku[worker.1]: Starting process with command python3 -m bot
2021-04-11T04:01:04.649398+00:00 heroku[worker.1]: State changed from starting to up
2021-04-11T04:01:09.151090+00:00 app[worker.1]: [2021-04-11 04:01:09,150 - /app/bot/init.py - INFO] [-1001278299702]
2021-04-11T04:01:09.157193+00:00 app[worker.1]: [2021-04-11 04:01:09,151 - /app/bot/init.py - INFO] [-1001321563599]
2021-04-11T04:01:10.336203+00:00 app[worker.1]: Pyrogram v1.2.8, Copyright (C) 2017-2021 Dan https://github.com/delivrance
2021-04-11T04:01:10.336228+00:00 app[worker.1]: Licensed under the terms of the GNU Lesser General Public License v3 or later (LGPLv3+)
2021-04-11T04:01:10.336229+00:00 app[worker.1]:
2021-04-11T04:04:44.883063+00:00 app[worker.1]: [2021-04-11 04:04:44,881 - /app/.heroku/python/lib/python3.7/site-packages/pyrogram/dispatcher.py - ERROR] 'NoneType' object has no attribute 'html'
2021-04-11T04:04:44.883089+00:00 app[worker.1]: Traceback (most recent call last):
2021-04-11T04:04:44.883090+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.7/site-packages/pyrogram/dispatcher.py", line 223, in handler_worker
2021-04-11T04:04:44.883091+00:00 app[worker.1]: *args
2021-04-11T04:04:44.883093+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.7/concurrent/futures/thread.py", line 57, in run
2021-04-11T04:04:44.883093+00:00 app[worker.1]: result = self.fn(*self.args, **self.kwargs)
2021-04-11T04:04:44.883094+00:00 app[worker.1]: File "/app/bot/main.py", line 11, in work
2021-04-11T04:04:44.883094+00:00 app[worker.1]: caption = message.caption.html.replace(remove_string, replace_string)
2021-04-11T04:04:44.883095+00:00 app[worker.1]: AttributeError: 'NoneType' object has no attribute 'html'
2021-04-11T04:04:45.518226+00:00 app[worker.1]: [2021-04-11 04:04:45,517 - /app/.heroku/python/lib/python3.7/site-packages/pyrogram/dispatcher.py - ERROR] 'NoneType' object has no attribute 'html'
2021-04-11T04:04:45.518237+00:00 app[worker.1]: Traceback (most recent call last):
2021-04-11T04:04:45.518238+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.7/site-packages/pyrogram/dispatcher.py", line 223, in handler_worker
2021-04-11T04:04:45.518239+00:00 app[worker.1]: *args
2021-04-11T04:04:45.518240+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.7/concurrent/futures/thread.py", line 57, in run
2021-04-11T04:04:45.518240+00:00 app[worker.1]: result = self.fn(*self.args, **self.kwargs)
2021-04-11T04:04:45.518241+00:00 app[worker.1]: File "/app/bot/main.py", line 11, in work
2021-04-11T04:04:45.518241+00:00 app[worker.1]: caption = message.caption.html.replace(remove_string, replace_string)
2021-04-11T04:04:45.518242+00:00 app[worker.1]: AttributeError: 'NoneType' object has no attribute 'html'

Please fix this.

Messages not getting forwarded

Hi,

I was trying to set this up on Heroku.. there were no errors.. but it just sits here and the messages do not get forwarded.. is there something else that we need to do?

Below is the extract from the logs.. let me know if you need any other details.

2021-05-04T16:11:40.983172+00:00 heroku[worker.1]: Stopping all processes with SIGTERM
2021-05-04T16:11:41.116429+00:00 heroku[worker.1]: Process exited with status 143
2021-05-04T16:11:45.661667+00:00 heroku[worker.1]: Starting process with command python3 -m bot
2021-05-04T16:11:46.302173+00:00 heroku[worker.1]: State changed from starting to up
2021-05-04T16:11:56.164946+00:00 app[worker.1]: Pyrogram v1.2.9, Copyright (C) 2017-2021 Dan https://github.com/delivrance
2021-05-04T16:11:56.165014+00:00 app[worker.1]: Licensed under the terms of the GNU Lesser General Public License v3 or later (LGPLv3+)
2021-05-04T16:11:56.165021+00:00 app[worker.1]:
2021-05-04T16:12:02.731343+00:00 app[worker.1]: [2021-05-04 16:12:02,731 - /app/bot/init.py - INFO] Sudo users - [11922955]
2021-05-04T16:12:02.731534+00:00 app[worker.1]: [2021-05-04 16:12:02,731 - /app/bot/init.py - INFO] [14270915]
2021-05-04T16:12:02.731671+00:00 app[worker.1]: [2021-05-04 16:12:02,731 - /app/bot/init.py - INFO] {14270915: [12629845, 13922525]}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.