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)
| 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. |
| 485 | func (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. |
| 516 | func (p *provider) sendMessageToConversation(ctx context.Context, conversationID string, card *AdaptiveCard) error { |
no test coverage detected