rahiel / telegram-send

Send messages and files over Telegram from the command-line.
https://www.rahielkasim.com/telegram-send/
GNU General Public License v3.0
938 stars 105 forks source link

cannot import name 'MAX_MESSAGE_LENGTH' from 'telegram.constants' #115

Closed rdlmda closed 1 year ago

rdlmda commented 1 year ago

pip install --user --upgrade --force-reinstall telegram-send && telegram-send --configure

ImportError: cannot import name 'MAX_MESSAGE_LENGTH' from 'telegram.constants' (/home/user/.local/lib/python3.10/site-packages/telegram/constants.py)

mazwettler commented 1 year ago

having the same issue, experimented a bit and I think its related to verison 20.0 of python-telegram-bot beeing published 16 hours ago. At least for me following downgrade fixed it: pip3 install --force-reinstall -v "python-telegram-bot==13.5"

anasrih commented 1 year ago

Thank you @mazwettler

viper7882 commented 1 year ago

I faced the same issue. The problem seems caused by MAX_MESSAGE_LENGTH constant has been renamed to MAX_TEXT_LENGTH inside MessageLimit class in python-telegram-bot.

It seems like the fix is to import MessageLimit class and then access the constant via MessageLimit.MAX_TEXT_LENGTH. A couple lines of code changes needed in order to accomplish this fix.

The workaround that's working for me is as following:

from telegram.constants import MessageLimit
.
.
.
            if len(m) > MessageLimit.MAX_TEXT_LENGTH:
                warn(markup(
                    f"Message longer than MAX_TEXT_LENGTH={MessageLimit.MAX_TEXT_LENGTH}, splitting into smaller messages.",
                    "red"))
                ms = split_message(m, MessageLimit.MAX_TEXT_LENGTH)
george-gca commented 1 year ago

@viper7882 create a PR with this code, maybe @rahiel could approve it to master

DeadNews commented 1 year ago

@rahiel Please review PR https://github.com/rahiel/telegram-send/pull/124.

Or at least specify a valid range of python-telegram-bot versions. https://github.com/rahiel/telegram-send/blob/34d7703754d441a6f4c4a7b5b3210759d36078e2/setup.py#L22 It should be, for example, >=13.0,<14.0.

chrischma commented 1 year ago

pip3 install --force-reinstall -v "python-telegram-bot==13.5"

thank you. 👍

rahiel commented 1 year ago

This is fixed with the recently merged PR #124, a new release will be out shortly.