https://open.dingtalk.com/document/orgapp/chatbots-send-one-on-one-chat-messages-in-batches
(ctx context.Context, userIDs []string, title, text string)
| 103 | |
| 104 | // https://open.dingtalk.com/document/orgapp/chatbots-send-one-on-one-chat-messages-in-batches |
| 105 | func (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 | |
| 140 | func (p *provider) do(ctx context.Context, method, url string, data []byte) ([]byte, error) { |
| 141 | const maxRetries = 3 |
no test coverage detected