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

Function postPowerAutomateMessage

backend/plugin/webhook/teams/teams.go:119–160  ·  view source on GitHub ↗

postPowerAutomateMessage sends a webhook message to a Power Automate Workflow URL using the Adaptive Card format wrapped in a message envelope.

(context webhook.Context)

Source from the content-addressed store, hash-verified

117// postPowerAutomateMessage sends a webhook message to a Power Automate Workflow URL
118// using the Adaptive Card format wrapped in a message envelope.
119func postPowerAutomateMessage(context webhook.Context) error {
120 card := getAdaptiveCard(context)
121 msg := activity{
122 Type: "message",
123 Attachments: []attachment{
124 {
125 ContentType: "application/vnd.microsoft.card.adaptive",
126 Content: card,
127 },
128 },
129 }
130
131 body, err := json.Marshal(msg)
132 if err != nil {
133 return errors.Wrapf(err, "failed to marshal webhook POST request to %s", context.URL)
134 }
135 req, err := http.NewRequest("POST", context.URL, bytes.NewBuffer(body))
136 if err != nil {
137 return errors.Wrapf(err, "failed to construct webhook POST request to %s", context.URL)
138 }
139
140 req.Header.Set("Content-Type", "application/json")
141 client := &http.Client{
142 Timeout: webhook.Timeout,
143 }
144 resp, err := client.Do(req)
145 if err != nil {
146 return errors.Wrapf(err, "failed to POST webhook to %s", context.URL)
147 }
148
149 b, err := io.ReadAll(resp.Body)
150 if err != nil {
151 return errors.Wrapf(err, "failed to read POST webhook response from %s", context.URL)
152 }
153 defer resp.Body.Close()
154
155 if resp.StatusCode < 200 || resp.StatusCode >= 300 {
156 return errors.Errorf("failed to POST webhook %s, status code: %d, response body: %s", context.URL, resp.StatusCode, b)
157 }
158
159 return nil
160}
161
162func postDirectMessage(webhookCtx webhook.Context) bool {
163 teams := getTeamsConfig(webhookCtx.IMSetting)

Callers 1

PostMethod · 0.85

Calls 5

getAdaptiveCardFunction · 0.85
DoMethod · 0.80
ErrorfMethod · 0.80
CloseMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected