JoaoPito / ayanami-bot

Your AI-powered assistant that customizes itself to automate your tasks, conveniently in a Telegram bot
GNU General Public License v3.0
0 stars 0 forks source link

Issue: It cannot split messages bigger than 4096 characters #3

Closed JoaoPito closed 4 months ago

JoaoPito commented 4 months ago

Sometimes the AI can generate messages bigger than 4096, but the telegram API does not support it. To solve this issue, the text generated by the AI can be split into multiple messages, each smaller than 4096 characters. A solution for this can be:

# In the TelegramChat class:
async def __send_message_directly__(self, context, chat_id, text, connect_timeout=60):
    await context.bot.send_message(chat_id=chat_id, text=text, connect_timeout=connect_timeout)

def __split_and_send_message__(long_message, max_length=4096):
    parts = [long_message[i:i+max_length] for i in range(0, len(long_message), max_length)]

def send_message(self, context, chat_id, text, connect_timeout=60):
    splitted_msgs = self.__split_and_send_message__(text)
    for msg in splitted_msgs:
        self.__send_message_directly__(context, chat_id, msg,connect_timeout)
JoaoPito commented 4 months ago

Fixed in commit 93011b5