this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: Enhance message handling in announcements and queue helpers to manage long messages and improve error reporting

+49 -11
+34 -6
bot/telegrambot/commands/announcements.js
··· 84 84 callback_data: 'new_announcement' 85 85 } 86 86 ]); 87 - 88 - await this.bot.sendMessage(chatId, message, { 89 - parse_mode: 'Markdown', 90 - reply_markup: { 91 - inline_keyboard: inlineKeyboard 87 + 88 + try { 89 + const MAX_LENGTH = 4096; 90 + if (message.length <= MAX_LENGTH) { 91 + await this.bot.sendMessage(chatId, message, { 92 + parse_mode: 'Markdown', 93 + reply_markup: { inline_keyboard: inlineKeyboard } 94 + }); 95 + } else { 96 + // Split into chunks that fit within the limit, breaking on double newlines 97 + const chunks = []; 98 + let current = ''; 99 + for (const line of message.split('\n')) { 100 + if ((current + line + '\n').length > MAX_LENGTH) { 101 + chunks.push(current); 102 + current = ''; 103 + } 104 + current += line + '\n'; 105 + } 106 + if (current) chunks.push(current); 107 + 108 + // Send all chunks except the last without the keyboard 109 + for (let i = 0; i < chunks.length - 1; i++) { 110 + await this.bot.sendMessage(chatId, chunks[i], { parse_mode: 'Markdown' }); 111 + } 112 + // Send the last chunk with the inline keyboard 113 + await this.bot.sendMessage(chatId, chunks[chunks.length - 1], { 114 + parse_mode: 'Markdown', 115 + reply_markup: { inline_keyboard: inlineKeyboard } 116 + }); 92 117 } 93 - }); 118 + } catch (error) { 119 + console.error('Error sending announcements list:', error); 120 + await this.bot.sendMessage(chatId, `❌ Error displaying announcements: ${error.message}`); 121 + } 94 122 }); 95 123 } 96 124 }
+15 -5
bot/telegrambot/helpers/queueHelper.js
··· 127 127 } 128 128 129 129 // Send the message with inline keyboard 130 - await this.bot.sendMessage(chatId, message, { 131 - parse_mode: 'Markdown', 132 - reply_markup: { 133 - inline_keyboard 130 + try { 131 + // Truncate individual item titles if the overall message is too long 132 + const MAX_LENGTH = 4096; 133 + if (message.length > MAX_LENGTH) { 134 + message = message.substring(0, MAX_LENGTH - 100) + '\n\n_(list truncated)_'; 134 135 } 135 - }); 136 + await this.bot.sendMessage(chatId, message, { 137 + parse_mode: 'Markdown', 138 + reply_markup: { 139 + inline_keyboard 140 + } 141 + }); 142 + } catch (error) { 143 + console.error('Error sending queue page:', error); 144 + await this.bot.sendMessage(chatId, `❌ Error displaying queue: ${error.message}`); 145 + } 136 146 } 137 147 138 148 /**