Skip to content

Commit ac1f734

Browse files
authored
Merge pull request #9 from ipfs-force-community/feat/mentioned
feat: support mentioned
2 parents 9c1323e + 0819998 commit ac1f734

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

notifier/notification.go

+26-24
Original file line numberDiff line numberDiff line change
@@ -89,43 +89,53 @@ func (r *DingNotificationBuilder) Build(m *models.WebhookMessage) (*models.DingT
8989
}
9090

9191
func (r *DingNotificationBuilder) BuildWeChat(m *models.WebhookMessage) (*models.WeChatNotification, error) {
92-
if r.target.Mention != nil {
93-
m.AtMobiles = append(m.AtMobiles, r.target.Mention.Mobiles...)
94-
}
95-
9692
content, err := r.renderText(m)
9793
if err != nil {
9894
return nil, err
9995
}
10096

97+
// Build mention
98+
if r.target.Mention != nil {
99+
if r.target.Mention.All {
100+
content = fmt.Sprintf("%s\n%s ", content, "<@all>")
101+
} else {
102+
var m string
103+
for _, mobile := range r.target.Mention.Mobiles {
104+
m += fmt.Sprintf("<@%s> ", mobile)
105+
}
106+
content = fmt.Sprintf("%s\n%s", content, m)
107+
}
108+
}
109+
101110
notification := &models.WeChatNotification{
102111
MessageType: "markdown",
103112
Markdown: &models.WeChatNotificationMarkdown{
104113
Content: content,
105114
},
106115
}
107116

108-
// Build mention
109-
if r.target.Mention != nil {
110-
notification.At = &models.DingTalkNotificationAt{
111-
IsAtAll: r.target.Mention.All,
112-
AtMobiles: r.target.Mention.Mobiles,
113-
}
114-
}
115-
116117
return notification, nil
117118
}
118119

119120
func (r *DingNotificationBuilder) BuildLark(m *models.WebhookMessage) (*models.LarkNotification, error) {
120-
if r.target.Mention != nil {
121-
m.AtMobiles = append(m.AtMobiles, r.target.Mention.Mobiles...)
122-
}
123-
124121
content, err := r.renderText(m)
125122
if err != nil {
126123
return nil, err
127124
}
128125

126+
// Build mention
127+
if r.target.Mention != nil {
128+
if r.target.Mention.All {
129+
content = fmt.Sprintf("%s\n%s ", content, "<at id=all></at>")
130+
} else {
131+
var m string
132+
for _, mobile := range r.target.Mention.Mobiles {
133+
m += fmt.Sprintf("<at id=%s></at> ", mobile)
134+
}
135+
content = fmt.Sprintf("%s %s", content, m)
136+
}
137+
}
138+
129139
notification := &models.LarkNotification{
130140
MessageType: "interactive",
131141
Card: models.LarkNotificationCard{
@@ -138,14 +148,6 @@ func (r *DingNotificationBuilder) BuildLark(m *models.WebhookMessage) (*models.L
138148
},
139149
}
140150

141-
// Build mention
142-
if r.target.Mention != nil {
143-
notification.At = &models.DingTalkNotificationAt{
144-
IsAtAll: r.target.Mention.All,
145-
AtMobiles: r.target.Mention.Mobiles,
146-
}
147-
}
148-
149151
return notification, nil
150152
}
151153

0 commit comments

Comments
 (0)