notify users #25

Merged
romanskijdev merged 1 commits from fix-permissions into main 2026-06-24 16:48:16 +03:00
1 changed files with 33 additions and 1 deletions

View File

@ -39,7 +39,8 @@ func NewUpdateHandler(ipc *types.InternalProviderControl) *UpdateHandler {
}
// TODO: вызывается только после обновлений
go handler.broadcastBotUpdated()
//go handler.broadcastBotUpdated()
go handler.broadcastBotMessage()
return handler
}
@ -78,3 +79,34 @@ func (s *UpdateHandler) broadcastBotUpdated() {
logrus.Infof("broadcastBotUpdated: отправлено %d пользователям", len(users))
}
func (s *UpdateHandler) broadcastBotMessage() {
ctx := context.Background()
bot := s.ipc.TGBotClient.Bot()
users, _, err := s.ipc.Database.User.GetUsersListDB(ctx, typescore.ListDbOptions{})
if err != nil {
logrus.Errorf("broadcastBotUpdated: GetUsersListDB err=%v", err)
return
}
text := "Привет! 👋 \n\n" +
"Я твой новый помощник для согласования большинства рабочих вопросов. \n" +
"Во мне предусмотрены все чаты согласований, которые ранее использовались в компании. \n" +
"Пожалуйста, создавай все заявки на согласование вместе со мной. 🤝 \n" +
"Иначе мне будет очень грустно и одиноко 😢, а заявки, скорее всего, не будут рассмотрены. \n"
for _, user := range users {
if user.TelegramID == nil {
continue
}
msg := tgbotapi.NewMessage(*user.TelegramID, text)
msg.ParseMode = "HTML"
if _, err := bot.Send(msg); err != nil {
logrus.Warnf("broadcastBotUpdated: Send to telegramID=%d err=%v", *user.TelegramID, err)
}
time.Sleep(50 * time.Millisecond)
}
logrus.Infof("broadcastBotUpdated: отправлено %d пользователям", len(users))
}