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

Method sendMessage

backend/plugin/webhook/wecom/wecom.go:104–148  ·  view source on GitHub ↗
(context webhook.Context)

Source from the content-addressed store, hash-verified

102}
103
104func (*Receiver) sendMessage(context webhook.Context) error {
105 post := Webhook{
106 MessageType: "markdown",
107 Markdown: getMessageCard(context),
108 }
109 body, err := json.Marshal(post)
110 if err != nil {
111 return errors.Wrapf(err, "failed to marshal webhook POST request to %s", context.URL)
112 }
113 req, err := http.NewRequest("POST",
114 context.URL, bytes.NewBuffer(body))
115 if err != nil {
116 return errors.Wrapf(err, "failed to construct webhook POST request to %s", context.URL)
117 }
118
119 req.Header.Set("Content-Type", "application/json")
120 client := &http.Client{
121 Timeout: webhook.Timeout,
122 }
123 resp, err := client.Do(req)
124 if err != nil {
125 return errors.Wrapf(err, "failed to POST webhook to %s", context.URL)
126 }
127
128 b, err := io.ReadAll(resp.Body)
129 if err != nil {
130 return errors.Wrapf(err, "failed to read POST webhook response from %s", context.URL)
131 }
132 defer resp.Body.Close()
133
134 if resp.StatusCode != http.StatusOK {
135 return errors.Errorf("failed to POST webhook to %s, status code: %d, response body: %s", context.URL, resp.StatusCode, b)
136 }
137
138 webhookResponse := &WebhookResponse{}
139 if err := json.Unmarshal(b, webhookResponse); err != nil {
140 return errors.Wrapf(err, "malformed webhook response from %s", context.URL)
141 }
142
143 if webhookResponse.ErrorCode != 0 {
144 return errors.Errorf("%s", webhookResponse.ErrorMessage)
145 }
146
147 return nil
148}
149
150// sendDirectMessage sends direct message to users.
151// returns `true` if successfully sends messages to all users.

Callers 2

PostMethod · 0.95
sendDirectMessageMethod · 0.45

Implementers 8

Receiverbackend/plugin/webhook/discord/discord
feishuReceiverbackend/plugin/webhook/feishu/feishu.g
Receiverbackend/plugin/webhook/dingtalk/dingta
Receiverbackend/plugin/webhook/wecom/wecom.go
Receiverbackend/plugin/webhook/slack/slack.go
Receiverbackend/plugin/webhook/teams/teams.go
Receiverbackend/plugin/webhook/googlechat/goog
larkReceiverbackend/plugin/webhook/lark/lark.go

Calls 6

DoMethod · 0.80
ErrorfMethod · 0.80
UnmarshalMethod · 0.80
getMessageCardFunction · 0.70
CloseMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected