Skip to content

Commit 03815d9

Browse files
committed
feat(*): create group messages
1 parent 2a11b2c commit 03815d9

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

bot/commands/admin/sendMessage.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
11
import { INITIAL_SESSION } from '../../constants/index.js'
2+
import { db } from '../../db/index.js'
23
// TODO: сделать цикл и возможность отправки сообщений группам пользователей
34
export const sendMessage = bot => {
45
bot.onText(/^\/msg+/ig, async msg => {
5-
if (msg?.chat?.id == process.env.NOTIF_GROUP) {
6+
if (msg?.chat?.id === process.env.NOTIF_GROUP) {
67
const text = msg.text.split('&&')
78
const { id: chatId } = msg.chat
89
const options = {
910
parse_mode: 'HTML'
1011
}
1112
msg['ctx'] = INITIAL_SESSION
1213
try {
13-
await bot.sendMessage(
14-
text[1],
15-
`🤖\n${text[2]}`,
16-
options
17-
)
14+
if (text[1] === 'all') {
15+
const subscribers = await db.subscriber.findAll({
16+
subQuery: false,
17+
order: [['createdAt', 'DESC']]
18+
})
19+
20+
if (msg['reply_to_message'].photo.length) {
21+
console.log('msg[\'reply_to_message\'].photo', msg['reply_to_message'].photo)
22+
// отправить всем пользователям сообщение с картинкой
23+
// subscribers.map(user => bot.sendPhoto(user['chat_id']))
24+
} else {
25+
subscribers.map(user => bot.sendMessage(user.chat_id, '🔮'))
26+
}
27+
} else {
28+
await bot.sendMessage(
29+
text[1],
30+
`🤖\n${text[2]}`,
31+
options
32+
)
33+
}
1834
} catch (error) {
1935
await bot.sendMessage(chatId, `${error.message}`, options)
2036
}

0 commit comments

Comments
 (0)