(webhookCtx webhook.Context)
| 160 | } |
| 161 | |
| 162 | func 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 | |
| 217 | func postMessage(context webhook.Context) error { |
| 218 | factList := []WebhookSectionFact{} |
no test coverage detected