ehForwarderBot / efb-telegram-master

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

[BUG] Using telegram bot local server can't send / receive Files #133

Open kettly1260 opened 1 year ago

kettly1260 commented 1 year ago
**Describe the bug** Using telegram bot local server can't send / receive Files **To Reproduce** Steps to reproduce the behavior: 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' 4. See error **Expected behavior** When I change the telegram api to the local server,the bot can received the text,but when I sent the pictures or any files, the bot prompts that "Unknown error has occurred while trying to process this message. See log for details. InvalidToken() " 。 When I received files, nothing prompted and couldn't receive them **Screenshots** If applicable, add screenshots to help explain your problem. **Version information (please complete the following information):** - OS: [e.g. iOS] - Detailed Python, EFB and module versions: (you can obtain this by running `ehforwarderbot --version`) ``` EH Forwarder Bot Version: 2.1.1 Python version: 3.8 Master channel: EFB Telegram Master Channel 2.3.1 Slave channel: WeChat Slave (blueset.wechat, 2.0.6.dev10) Middleware: - MP InstantView Middleware (catbaron.mp_instantview, 0.3.1) - Search Message Middleware (catbaron.search_msg, 0.1.0) ``` **Additional context** elete_chat_photo': False, 'channel_chat_created': False, 'caption_entities': [], 'from': {'id': xxxxx, 'is_bot': False, 'first_name': 'xxxx', 'language_code': 'zh-hans'}}, 'update_id': xxxxx}. Traceback (most recent call last): File "/home/ubuntu/.local/lib/python3.8/site-packages/efb_telegram_master/master_message.py", line 103, in message_worker self.msg(update, context) File "/home/ubuntu/.local/lib/python3.8/site-packages/efb_telegram_master/master_message.py", line 207, in msg return self.process_telegram_message(update, context, destination, quote=quote, edited=edited) File "/home/ubuntu/.local/lib/python3.8/site-packages/efb_telegram_master/master_message.py", line 426, in process_telegram_message if m.file: File "/home/ubuntu/.local/lib/python3.8/site-packages/efb_telegram_master/message.py", line 130, in get_file self._load_file() File "/home/ubuntu/.local/lib/python3.8/site-packages/efb_telegram_master/message.py", line 77, in _load_file file_meta.download(out=file) File "/home/ubuntu/.local/lib/python3.8/site-packages/telegram/files/file.py", line 148, in download buf = self.bot.request.retrieve(url) File "/home/ubuntu/.local/lib/python3.8/site-packages/telegram/utils/request.py", line 385, in retrieve return self._request_wrapper('GET', url, **urlopen_kwargs) File "/home/ubuntu/.local/lib/python3.8/site-packages/telegram/utils/request.py", line 281, in _request_wrapper raise InvalidToken() telegram.error.InvalidToken: Invalid token
zeXtreme commented 1 year ago

我也遇到这个问题,但是我可以接收文件,但是发送文件时会提示

Message is not sent.

InvalidToken()

以下是我使用的主端和从端版本

您正在使用 EFB Telegram 主端 2.3.1,运行于默认配置档案与实例、EFB 版本 2.1.1。
已激活 1 个从端:
- 💬 WeChat Slave (blueset.wechat, 2.0.7)

日志

stderr: 2023-09-05 08:47:10,448 [ERROR]: efb_telegram_master.master_message (master_message.process_telegram_message; master_message.py:422)
stderr:     Message is not sent. (update: {'message': {'caption_entities': [], 'message_id': 941506, 'new_chat_members': [], 'new_chat_photo': [], 'entities': [], 'reply_to_message': {'edit_date': 1693874817, 'caption_entities': [], 'message_id': 941505, 'new_chat_members': [], 'new_chat_photo': [], 'entities': [], 'text': '回复该消息以与 ‘文件传输助手’ @ ‘💬 WeChat Slave’ 对话。', 'delete_chat_photo': False, 'chat': {'first_name': 'xxxxxx', 'type': 'private', 'id': xxxxxxxxxxx}, 'channel_chat_created': False, 'group_chat_created': False, 'photo': [], 'date': 1693874813, 'supergroup_chat_created': False, 'from': {'is_bot': True, 'first_name': 'xxxxxxxxxxx', 'id': xxxxxxxxxxx, 'username': 'xxxxxxxxx'}}, 'delete_chat_photo': False, 'chat': {'first_name': 'xxxxxxxxx', 'type': 'private', 'id': xxxxxxxxx}, 'channel_chat_created': False, 'group_chat_created': False, 'photo': [], 'date': 1693874826, 'supergroup_chat_created': False, 'document': {'file_unique_id': 'AgADEgsAAkmOuFc', 'file_size': 13654, 'mime_type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'file_name': 'xxxxxx.xlsx', 'file_id': 'BQACAgUAAxkBAAEOXcJk9nqKu2CLCBtVrMU6VtqIOAaDPAACEgsAAkmOuFc2BlO2pnttLjAE'}, 'from': {'is_bot': False, 'first_name': 'xxxxxxxxx', 'id': xxxxxxxxxxxxx, 'language_code': 'zh-hans'}}, 'update_id': 299213794}, exception: Invalid token)
stderr: Traceback (most recent call last):
stderr:   File "/app/.venv/lib/python3.10/site-packages/efb_telegram_master/master_message.py", line 405, in process_telegram_message
stderr:     slave_msg = coordinator.send_message(m)
stderr:   File "/app/.venv/lib/python3.10/site-packages/ehforwarderbot/coordinator.py", line 108, in send_message
stderr:     msg.verify()
stderr:   File "/app/.venv/lib/python3.10/site-packages/ehforwarderbot/message.py", line 519, in verify
stderr:     assert hasattr(self.file, "read") or not hasattr(self.file, "close"), \
stderr:   File "/app/.venv/lib/python3.10/site-packages/efb_telegram_master/message.py", line 130, in get_file
stderr:     self._load_file()
stderr:   File "/app/.venv/lib/python3.10/site-packages/efb_telegram_master/message.py", line 77, in _load_file
stderr:     file_meta.download(out=file)
stderr:   File "/app/.venv/lib/python3.10/site-packages/telegram/files/file.py", line 148, in download
stderr:     buf = self.bot.request.retrieve(url)
stderr:   File "/app/.venv/lib/python3.10/site-packages/telegram/utils/request.py", line 385, in retrieve
stderr:     return self._request_wrapper('GET', url, **urlopen_kwargs)
stderr:   File "/app/.venv/lib/python3.10/site-packages/telegram/utils/request.py", line 281, in _request_wrapper
stderr:     raise InvalidToken()
stderr: telegram.error.InvalidToken: Invalid token
stderr: 2023-09-05 08:47:10,862 [ERROR]: efb_telegram_master.master_message (master_message.message_worker; master_message.py:105)
stderr:     Error [InvalidToken()] occurred while processing update {'message': {'caption_entities': [], 'message_id': 941506, 'new_chat_members': [], 'new_chat_photo': [], 'entities': [], 'reply_to_message': {'edit_date': 1693874817, 'caption_entities': [], 'message_id': 941505, 'new_chat_members': [], 'new_chat_photo': [], 'entities': [], 'text': '回复该消息以与 ‘文件传输助手’ @ ‘💬 WeChat Slave’ 对话。', 'delete_chat_photo': False, 'chat': {'first_name': 'xxxxxx', 'type': 'private', 'id': xxxxxxx}, 'channel_chat_created': False, 'group_chat_created': False, 'photo': [], 'date': 1693874813, 'supergroup_chat_created': False, 'from': {'is_bot': True, 'first_name': 'xxxxxxxxxxx', 'id': xxxxxxxxxxxx, 'username': 'xxxxxxxxx'}}, 'delete_chat_photo': False, 'chat': {'first_name': 'xxxxxxxxx', 'type': 'private', 'id': xxxxxxxxxxxxx}, 'channel_chat_created': False, 'group_chat_created': False, 'photo': [], 'date': 1693874826, 'supergroup_chat_created': False, 'document': {'file_unique_id': 'AgADEgsAAkmOuFc', 'file_size': 13654, 'mime_type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'file_name': 'xxxx.xlsx', 'file_id': 'BQACAgUAAxkBAAEOXcJk9nqKu2CLCBtVrMU6VtqIOAaDPAACEgsAAkmOuFc2BlO2pnttLjAE'}, 'from': {'is_bot': False, 'first_name': 'xxxxxxx', 'id': xxxxxxxx, 'language_code': 'zh-hans'}}, 'update_id': 299213794}.
stderr: Traceback (most recent call last):
stderr:   File "/app/.venv/lib/python3.10/site-packages/efb_telegram_master/master_message.py", line 103, in message_worker
stderr:     self.msg(update, context)
stderr:   File "/app/.venv/lib/python3.10/site-packages/efb_telegram_master/master_message.py", line 207, in msg
stderr:     return self.process_telegram_message(update, context, destination, quote=quote, edited=edited)
stderr:   File "/app/.venv/lib/python3.10/site-packages/efb_telegram_master/master_message.py", line 426, in process_telegram_message
stderr:     if m.file:
stderr:   File "/app/.venv/lib/python3.10/site-packages/efb_telegram_master/message.py", line 130, in get_file
stderr:     self._load_file()
stderr:   File "/app/.venv/lib/python3.10/site-packages/efb_telegram_master/message.py", line 77, in _load_file
stderr:     file_meta.download(out=file)
stderr:   File "/app/.venv/lib/python3.10/site-packages/telegram/files/file.py", line 148, in download
stderr:     buf = self.bot.request.retrieve(url)
stderr:   File "/app/.venv/lib/python3.10/site-packages/telegram/utils/request.py", line 385, in retrieve
stderr:     return self._request_wrapper('GET', url, **urlopen_kwargs)
stderr:   File "/app/.venv/lib/python3.10/site-packages/telegram/utils/request.py", line 281, in _request_wrapper
stderr:     raise InvalidToken()
stderr: telegram.error.InvalidToken: Invalid token
zeXtreme commented 1 year ago

我参考这个用nginx将接收到的文件暴露出来解决了问题

pangxiezhou commented 7 months ago

问题1:发送文件失败,提示 FileNotFoundError: [Errno 2] No such file or directory: 'file:///tmp/tmpp5_qox2o’

解决方法:efb_telegram_master/slave_message.py文件中process_file_obj 修改为:

def process_file_obj(self, file: IO[bytes], path: Union[str, Path]) -> Union[IO[bytes], str]:
    return file

问题2:接收文件失败,提示invalid Token

解决方法:profiles/default/blueset.telegram/config.yaml 中 api_base_file_url 填写telegram bot api的work dir,例如:

api_base_file_url: "/home/pangxiezhou/.telegram_bot_server/"