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

Method sendMessage

backend/plugin/webhook/wecom/app.go:175–200  ·  view source on GitHub ↗

https://developer.work.weixin.qq.com/document/path/90236

(ctx context.Context, userIDs []string, markdown *WebhookMarkdown)

Source from the content-addressed store, hash-verified

173
174// https://developer.work.weixin.qq.com/document/path/90236
175func (p *provider) sendMessage(ctx context.Context, userIDs []string, markdown *WebhookMarkdown) error {
176 url, err := url.Parse("https://qyapi.weixin.qq.com/cgi-bin/message/send")
177 if err != nil {
178 return errors.Wrapf(err, "failed to parse url")
179 }
180
181 requestBody, err := json.Marshal(struct {
182 ToUser string `json:"touser"`
183 MsgType string `json:"msgtype"`
184 AgentID int `json:"agentid"`
185 Markdown *WebhookMarkdown `json:"markdown"`
186 }{
187 ToUser: strings.Join(userIDs, "|"),
188 MsgType: "markdown",
189 AgentID: p.agentID,
190 Markdown: markdown,
191 })
192 if err != nil {
193 return errors.Wrapf(err, "failed to marshal request body")
194 }
195
196 if _, err := p.do(ctx, http.MethodPost, url, requestBody); err != nil {
197 return errors.Wrapf(err, "failed to send message")
198 }
199 return nil
200}
201
202func (p *provider) do(ctx context.Context, method string, url *url.URL, data []byte) ([]byte, error) {
203 if p.token == "" {

Callers

nothing calls this directly

Calls 2

doMethod · 0.95
JoinMethod · 0.80

Tested by

no test coverage detected