From 29f07765497989a09305e5696583772eb8860ee2 Mon Sep 17 00:00:00 2001 From: romanskijdev Date: Wed, 24 Jun 2026 16:47:52 +0300 Subject: [PATCH] notify users --- .../telegram_service/common/update/0_init.go | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/service/telegram_service/common/update/0_init.go b/service/telegram_service/common/update/0_init.go index c60d312..1d955ab 100644 --- a/service/telegram_service/common/update/0_init.go +++ b/service/telegram_service/common/update/0_init.go @@ -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)) +} -- 2.43.0