For example, the result of a query to the database involves the output of 50 records. These records are issued in a single chat message, which is difficult to analyze. How to divide the result into several messages with 3 records in each?
bot.on('message', async (message) => {
const {text, chat} = message;
const {id: chatId} = chat;
let response = '';
try {
const [rows] = await sequelize.query(`SELECT book FROM books t WHERE (t.*)::text LIKE '%${text}%' LIMIT 3`);
if (rows.length) {
response = rows.map(row => row.book).join("\n");
} else {
response = 'text';
}
} catch (error) {
console.error(error.message);
response = 'book not found';
} finally {
if (response) {
bot.sendMessage(chatId, response);
}
}
})