Tell me why the newsletter does not work for my bot users?
All users are recorded in bd with their id
const { Telegraf, Markup, Scenes, session } = require('telegraf');
const bot = new Telegraf(process.env.BOT_TOKEN);
const db = require("./database/db-pool");
what I’m trying to do is pull each user from the database and send him a message using the /sendAd command
bot.command('sendAd', async (ctx) => {
try {
const conn = await db.getConnection();
const [rows] = await conn.query('SELECT * FROM users');
conn.release();
for (const row of rows) {
console.log(`Sending a message to a user chatId: ${row.chatId}`);
await ctx.telegram.sendMessage(row.chatId, 'Your advertising message is here');
}
ctx.reply('Advertising sent to all users');
} catch (error) {
console.error(error);
ctx.reply('There was an error sending the ad.');
}
});
please help me