'Python Telegram Bot Read Large Message
I am trying to create a Telegram bot using python-telegram-bot that will read in a large message (~12K characters) and save the output to a file.
The relevant code I have is:
updater = Updater(token='XXXXXXXXXXXXXXXXXX')
dispatcher = updater.dispatcher
def runMe(update, context):
received_message = update.message.text
print("Received message with length %d" % len(received_message))
# Save (full) message to file
arg_handler = MessageHandler(Filters.text, runMe)
dispatcher.add_handler(arg_handler)
However when I do this, Telegram splits the messages into chunks of 4,096 (max message size)
Received message with length 4096
Received message with length 4096
Received message with length 4095 (Not sure why this is 4095)
Received message with length 24
How do I modify the bot so that although the messages are sent in chunks, I am able to combine all of these to create the single original message with no modification to the formatting.
My original idea was to create a global variable and append each message chunk to a list but I am not sure how to achieve this short of sending a command like /startMessage and /endMessage to signify when the message is sent. This method seems inefficient.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
