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

Function postDirectMessage

backend/plugin/webhook/feishu/feishu.go:128–177  ·  view source on GitHub ↗
(webhookCtx webhook.Context)

Source from the content-addressed store, hash-verified

126}
127
128func 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
179func postMessage(context webhook.Context) error {
180 post := Webhook{

Callers 1

PostMethod · 0.70

Calls 7

RetryFunction · 0.92
BBErrorFunction · 0.92
getFeishuConfigFunction · 0.85
newProviderFunction · 0.70
getMessageCardFunction · 0.70
getIDByEmailMethod · 0.45
sendMessageMethod · 0.45

Tested by

no test coverage detected