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

Method sendMessage

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

sendMessage sends a message to a user via Bot Framework. It ensures the Teams app is installed for the user first, then sends the message using the chat ID obtained from the installation.

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

Source from the content-addressed store, hash-verified

483// It ensures the Teams app is installed for the user first, then sends the message
484// using the chat ID obtained from the installation.
485func (p *provider) sendMessage(ctx context.Context, userAADID string, card *AdaptiveCard) error {
486 // First, ensure we have a Graph token.
487 if p.graphToken == "" {
488 if err := p.refreshGraphToken(ctx); err != nil {
489 return errors.Wrapf(err, "failed to refresh graph token")
490 }
491 }
492
493 // Get the Teams app ID from the app catalog.
494 teamsAppID, err := p.getTeamsAppID(ctx)
495 if err != nil {
496 return errors.Wrapf(err, "failed to get Teams app ID from catalog")
497 }
498
499 // Ensure the app is installed for the user.
500 installationID, err := p.ensureAppInstalledForUser(ctx, userAADID, teamsAppID)
501 if err != nil {
502 return errors.Wrapf(err, "failed to ensure app is installed for user")
503 }
504
505 // Get the chat ID for the user's app installation.
506 chatID, err := p.getChatIDForUser(ctx, userAADID, installationID)
507 if err != nil {
508 return errors.Wrapf(err, "failed to get chat ID for user")
509 }
510
511 // Send the message via Bot Framework using the chat ID as conversation ID.
512 return p.sendMessageToConversation(ctx, chatID, card)
513}
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 {

Callers 1

postDirectMessageFunction · 0.45

Calls 5

refreshGraphTokenMethod · 0.95
getTeamsAppIDMethod · 0.95
getChatIDForUserMethod · 0.95

Tested by

no test coverage detected