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

Method sendMessage

backend/plugin/webhook/dingtalk/app.go:105–138  ·  view source on GitHub ↗

https://open.dingtalk.com/document/orgapp/chatbots-send-one-on-one-chat-messages-in-batches

(ctx context.Context, userIDs []string, title, text string)

Source from the content-addressed store, hash-verified

103
104// https://open.dingtalk.com/document/orgapp/chatbots-send-one-on-one-chat-messages-in-batches
105func (p *provider) sendMessage(ctx context.Context, userIDs []string, title, text string) error {
106 const url = "https://api.dingtalk.com/v1.0/robot/oToMessages/batchSend"
107 markdown, err := json.Marshal(struct {
108 Title string `json:"title"`
109 Text string `json:"text"`
110 }{
111 Title: title,
112 Text: text,
113 })
114 if err != nil {
115 return errors.Wrapf(err, "failed to marshal markdown")
116 }
117 payload := struct {
118 RobotCode string `json:"robotCode"`
119 UserIDs []string `json:"userIds"`
120 MsgKey string `json:"msgKey"`
121 MsgParam string `json:"msgParam"`
122 }{
123 RobotCode: p.robot,
124 UserIDs: userIDs,
125 MsgKey: "sampleMarkdown",
126 MsgParam: string(markdown),
127 }
128 payloadJSON, err := json.Marshal(payload)
129 if err != nil {
130 return errors.Wrapf(err, "failed to marshal payload")
131 }
132 _, err = p.do(ctx, http.MethodPost, url, payloadJSON)
133 if err != nil {
134 return errors.Wrapf(err, "failed to send text message")
135 }
136
137 return nil
138}
139
140func (p *provider) do(ctx context.Context, method, url string, data []byte) ([]byte, error) {
141 const maxRetries = 3

Callers 2

sendDirectMessageFunction · 0.45
ValidateFunction · 0.45

Calls 1

doMethod · 0.95

Tested by

no test coverage detected