aboutsummaryrefslogtreecommitdiffstats
path: root/internal/notifier/telegram
diff options
context:
space:
mode:
authorLibravatar Mo Tarbin <mhed.t91@gmail.com>2024-07-17 01:09:47 -0400
committerLibravatar Mo Tarbin <mhed.t91@gmail.com>2024-07-17 01:09:47 -0400
commitc7b29fa19510daf4e766b689c7bc105742f35119 (patch)
tree2dd135aa2269531be353ff40446c740e6ee5f6ee /internal/notifier/telegram
parent12aaa903878958505d29284ac4d0d6605ba71c48 (diff)
downloaddonetick-c7b29fa19510daf4e766b689c7bc105742f35119.tar.gz
donetick-c7b29fa19510daf4e766b689c7bc105742f35119.tar.bz2
donetick-c7b29fa19510daf4e766b689c7bc105742f35119.zip
Add CircleGroup notifications to chore notifications
Diffstat (limited to '')
-rw-r--r--internal/notifier/telegram/telegram.go31
1 files changed, 24 insertions, 7 deletions
diff --git a/internal/notifier/telegram/telegram.go b/internal/notifier/telegram/telegram.go
index 54c0905..3f064b6 100644
--- a/internal/notifier/telegram/telegram.go
+++ b/internal/notifier/telegram/telegram.go
@@ -2,6 +2,7 @@ package telegram
import (
"context"
+ "encoding/json"
"fmt"
"strconv"
@@ -49,22 +50,38 @@ func (tn *TelegramNotifier) SendChoreReminder(c context.Context, chore *chModel.
}
}
-func (tn *TelegramNotifier) SendChoreCompletion(c context.Context, chore *chModel.Chore, users []*uModel.User) {
+func (tn *TelegramNotifier) SendChoreCompletion(c context.Context, chore *chModel.Chore, user *uModel.User) {
log := logging.FromContext(c)
- for _, user := range users {
- if user.ChatID == 0 {
- continue
+ var mt *chModel.NotificationMetadata
+ if err := json.Unmarshal([]byte(*chore.NotificationMetadata), &mt); err != nil {
+ log.Error("Error unmarshalling notification metadata", err)
+ }
+
+ targets := []int64{}
+ if user.ChatID != 0 {
+ targets = append(targets, user.ChatID)
+ }
+ if mt.CircleGroup && mt.CircleGroupID != nil {
+ // attempt to parse it:
+
+ if *mt.CircleGroupID != 0 {
+ targets = append(targets, *mt.CircleGroupID)
}
- text := fmt.Sprintf("🎉 *%s* is completed! is off the list, %s! 🌟 ", chore.Name, user.DisplayName)
- msg := tgbotapi.NewMessage(user.ChatID, text)
+
+ }
+
+ text := fmt.Sprintf("🎉 *%s* is completed! is off the list, %s! 🌟 ", chore.Name, user.DisplayName)
+ for _, target := range targets {
+ msg := tgbotapi.NewMessage(target, text)
+
msg.ParseMode = "Markdown"
_, err := tn.bot.Send(msg)
if err != nil {
log.Error("Error sending message to user: ", err)
log.Debug("Error sending message, chore: ", chore.Name, " user: ", user.DisplayName, " chatID: ", user.ChatID, " user id: ", user.ID)
}
-
}
+
}
func (tn *TelegramNotifier) SendChoreOverdue(c context.Context, chore *chModel.Chore, users []*uModel.User) {