sendMessageToConversation sends an Adaptive Card message to a conversation via Bot Framework.
(ctx context.Context, conversationID string, card *AdaptiveCard)
| 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 { |
| 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 | |
| 548 | func (p *provider) doBotRequest(ctx context.Context, method, apiURL string, data []byte) ([]byte, error) { |
| 549 | const maxRetries = 3 |
no test coverage detected