Skip to content

Commit

Permalink
feat(*): create group messages
Browse files Browse the repository at this point in the history
  • Loading branch information
aronbergman committed May 9, 2024
1 parent 2a11b2c commit 03815d9
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions bot/commands/admin/sendMessage.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
import { INITIAL_SESSION } from '../../constants/index.js'
import { db } from '../../db/index.js'
// TODO: сделать цикл и возможность отправки сообщений группам пользователей
export const sendMessage = bot => {
bot.onText(/^\/msg+/ig, async msg => {
if (msg?.chat?.id == process.env.NOTIF_GROUP) {
if (msg?.chat?.id === process.env.NOTIF_GROUP) {
const text = msg.text.split('&&')
const { id: chatId } = msg.chat
const options = {
parse_mode: 'HTML'
}
msg['ctx'] = INITIAL_SESSION
try {
await bot.sendMessage(
text[1],
`🤖\n${text[2]}`,
options
)
if (text[1] === 'all') {
const subscribers = await db.subscriber.findAll({
subQuery: false,
order: [['createdAt', 'DESC']]
})

if (msg['reply_to_message'].photo.length) {
console.log('msg[\'reply_to_message\'].photo', msg['reply_to_message'].photo)
// отправить всем пользователям сообщение с картинкой
// subscribers.map(user => bot.sendPhoto(user['chat_id']))
} else {
subscribers.map(user => bot.sendMessage(user.chat_id, '🔮'))
}
} else {
await bot.sendMessage(
text[1],
`🤖\n${text[2]}`,
options
)
}
} catch (error) {
await bot.sendMessage(chatId, `${error.message}`, options)
}
Expand Down

0 comments on commit 03815d9

Please sign in to comment.