如何在1分钟内向10个chatIds发送1条消息,并在一分钟后再发送给10个下一个chatIds,直到我的chatIds结束? 我的意思是我想要以1分钟的延迟
向所有chatIds发送消息$chatIds = array("xxx","xxx","xxx",......);
此代码只向1个人发送1条消息(msg.chat.id)
const StartKeyboard = [
['a', 'b'],
['send']
]
bot.onText(/\/send/, (msg) => {
const opts = {
reply_to_message_id: msg.message_id,
reply_markup: JSON.stringify({
keyboard: StartKeyboard,
resize_keyboard: true,
one_time_keyboard: true
})
};
bot.sendMessage(msg.chat.id, `Hello`, opts);
});
我想使用一些(foreach($chatIds as $chatId) {)
和(setInterval)
但我不知道应该如何使用。
答案 0 :(得分:1)
如果是这样的chatIds对象:
chatIds = [{message_id: 123, chat: {id : 456}}, {message_id: 234, chat: {id : 567}} ];
你可能会做的是:
setInterval(() => {
chatIds.splice(0,10).forEach((msg) => {
const opts = {
reply_to_message_id: msg.message_id,
reply_markup: JSON.stringify({
keyboard: StartKeyboard,
resize_keyboard: true,
one_time_keyboard: true
})
};
bot.sendMessage(msg.chat.id, `Hello`, opts);
});}, 60000);