MCPcopy Create free account
hub / github.com/bytebase/bytebase / postDirectMessage

Function postDirectMessage

backend/plugin/webhook/teams/teams.go:162–215  ·  view source on GitHub ↗
(webhookCtx webhook.Context)

Source from the content-addressed store, hash-verified

160}
161
162func postDirectMessage(webhookCtx webhook.Context) bool {
163 teams := getTeamsConfig(webhookCtx.IMSetting)
164 if teams == nil {
165 return false
166 }
167
168 p := newProvider(teams.TenantId, teams.ClientId, teams.ClientSecret)
169 ctx := context.Background()
170
171 sent := map[string]bool{}
172
173 if err := common.Retry(ctx, func() error {
174 var errs error
175
176 var emails []string
177 for _, u := range webhookCtx.MentionEndUsers {
178 if sent[u.Email] {
179 continue
180 }
181 emails = append(emails, u.Email)
182 }
183
184 idByEmail, err := p.getIDByEmail(ctx, emails)
185 if err != nil {
186 return errors.Wrapf(err, "failed to get id by email")
187 }
188
189 for _, u := range webhookCtx.MentionEndUsers {
190 if sent[u.Email] {
191 continue
192 }
193 id, ok := idByEmail[u.Email]
194 if !ok {
195 continue
196 }
197
198 err := p.sendMessage(ctx, id, getAdaptiveCard(webhookCtx))
199 if err != nil {
200 slog.Error("Teams failed to send message",
201 slog.String("email", u.Email),
202 log.BBError(err))
203 err = errors.Wrapf(err, "failed to send message to %s", u.Email)
204 multierr.AppendInto(&errs, err)
205 }
206 sent[u.Email] = true
207 }
208 return errs
209 }); err != nil {
210 slog.Warn("failed to send direct message to Teams user", log.BBError(err))
211 return false
212 }
213
214 return true
215}
216
217func postMessage(context webhook.Context) error {
218 factList := []WebhookSectionFact{}

Callers 1

PostMethod · 0.70

Calls 9

RetryFunction · 0.92
BBErrorFunction · 0.92
getTeamsConfigFunction · 0.85
getAdaptiveCardFunction · 0.85
newProviderFunction · 0.70
StringMethod · 0.65
getIDByEmailMethod · 0.45
sendMessageMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected