如何在 telegraf.js 上的电报机器人中实现发送一条消息

问题描述 投票:0回答:1

告诉我为什么时事通讯对我的机器人用户不起作用?

所有用户的id都记录在bd中

const { Telegraf, Markup, Scenes, session } = require('telegraf');
const bot = new Telegraf(process.env.BOT_TOKEN);
const db = require("./database/db-pool");

我想做的是从数据库中提取每个用户并使用 /sendAd 命令向他发送消息

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.');
    }
});

请帮助我

node.js telegram telegram-bot telegraf telegraf.js
1个回答
0
投票

只是命令之前有一个块正在吞噬所有短信..

bot.on('text', async (ctx) => {
    if (ctx.session.complainStep === 'waiting_for_complaint') 

..

像这样

© www.soinside.com 2019 - 2024. All rights reserved.