(webhookCtx webhook.Context)
| 126 | } |
| 127 | |
| 128 | func postDirectMessage(webhookCtx webhook.Context) bool { |
| 129 | feishu := getFeishuConfig(webhookCtx.IMSetting) |
| 130 | if feishu == nil { |
| 131 | return false |
| 132 | } |
| 133 | p := newProvider(feishu.AppId, feishu.AppSecret) |
| 134 | |
| 135 | ctx := context.Background() |
| 136 | |
| 137 | sent := map[string]bool{} |
| 138 | |
| 139 | if err := common.Retry(ctx, func() error { |
| 140 | var errs error |
| 141 | |
| 142 | var emails []string |
| 143 | for _, u := range webhookCtx.MentionEndUsers { |
| 144 | if sent[u.Email] { |
| 145 | continue |
| 146 | } |
| 147 | emails = append(emails, u.Email) |
| 148 | } |
| 149 | |
| 150 | idByEmail, err := p.getIDByEmail(ctx, emails) |
| 151 | if err != nil { |
| 152 | return errors.Wrapf(err, "failed to get id by email") |
| 153 | } |
| 154 | |
| 155 | for _, u := range webhookCtx.MentionEndUsers { |
| 156 | if sent[u.Email] { |
| 157 | continue |
| 158 | } |
| 159 | id, ok := idByEmail[u.Email] |
| 160 | if !ok { |
| 161 | continue |
| 162 | } |
| 163 | err := p.sendMessage(ctx, id, getMessageCard(webhookCtx)) |
| 164 | if err != nil { |
| 165 | err = errors.Wrapf(err, "failed to send message") |
| 166 | multierr.AppendInto(&errs, err) |
| 167 | } |
| 168 | sent[u.Email] = true |
| 169 | } |
| 170 | return errs |
| 171 | }); err != nil { |
| 172 | slog.Warn("failed to send direct message to feishu user", log.BBError(err)) |
| 173 | return false |
| 174 | } |
| 175 | |
| 176 | return true |
| 177 | } |
| 178 | |
| 179 | func postMessage(context webhook.Context) error { |
| 180 | post := Webhook{ |
no test coverage detected