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

Method sendMessageToConversation

backend/plugin/webhook/teams/app.go:516–546  ·  view source on GitHub ↗

sendMessageToConversation sends an Adaptive Card message to a conversation via Bot Framework.

(ctx context.Context, conversationID string, card *AdaptiveCard)

Source from the content-addressed store, hash-verified

514
515// sendMessageToConversation sends an Adaptive Card message to a conversation via Bot Framework.
516func (p *provider) sendMessageToConversation(ctx context.Context, conversationID string, card *AdaptiveCard) error {
517 if p.botToken == "" {
518 if err := p.refreshBotToken(ctx); err != nil {
519 return errors.Wrapf(err, "failed to refresh bot token")
520 }
521 }
522
523 apiURL := fmt.Sprintf("%s/v3/conversations/%s/activities", serviceURL, conversationID)
524
525 act := activity{
526 Type: "message",
527 Attachments: []attachment{
528 {
529 ContentType: "application/vnd.microsoft.card.adaptive",
530 Content: card,
531 },
532 },
533 }
534
535 data, err := json.Marshal(act)
536 if err != nil {
537 return errors.Wrapf(err, "failed to marshal activity")
538 }
539
540 _, err = p.doBotRequest(ctx, http.MethodPost, apiURL, data)
541 if err != nil {
542 return errors.Wrapf(err, "failed to send message to conversation")
543 }
544
545 return nil
546}
547
548func (p *provider) doBotRequest(ctx context.Context, method, apiURL string, data []byte) ([]byte, error) {
549 const maxRetries = 3

Callers 1

sendMessageMethod · 0.95

Calls 2

refreshBotTokenMethod · 0.95
doBotRequestMethod · 0.95

Tested by

no test coverage detected