{"record":{"id":"e1e94e97fc06d6bd","repo":"chenhg5/cc-connect","slug":"dingtalk-send-audio-request-w","errorCode":null,"errorMessage":"dingtalk: send audio request: %w","messagePattern":"dingtalk: send audio request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/dingtalk/dingtalk.go","lineNumber":1281,"sourceCode":"\tbody, err := json.Marshal(requestBody)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"dingtalk: marshal audio message: %w\", err)\n\t}\n\n\tslog.Debug(\"dingtalk: sending voice via oToMessages API\", \"media_id\", mediaID, \"duration\", durationMs, \"user_id\", rc.senderStaffId)\n\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost,\n\t\t\"https://api.dingtalk.com/v1.0/robot/oToMessages/batchSend\",\n\t\tbytes.NewReader(body))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"dingtalk: create audio request: %w\", err)\n\t}\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\treq.Header.Set(\"x-acs-dingtalk-access-token\", token)\n\n\tresp, err := p.httpClient.Do(req)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"dingtalk: send audio request: %w\", err)\n\t}\n\tdefer func() { _ = resp.Body.Close() }()\n\n\trespBody, _ := io.ReadAll(resp.Body)\n\tslog.Debug(\"dingtalk: oToMessages API response\", \"status\", resp.StatusCode, \"body\", string(respBody))\n\n\tif resp.StatusCode != 200 {\n\t\treturn fmt.Errorf(\"dingtalk: send audio failed: status=%d, body=%s\", resp.StatusCode, string(respBody))\n\t}\n\n\tslog.Info(\"dingtalk: voice message sent successfully\", \"media_id\", mediaID, \"conversation_id\", rc.conversationId)\n\treturn nil\n}\n\n// compressAudio compresses audio if it exceeds size limits.\n// Uses ffmpeg to convert WAV to MP3 format (DingTalk supported, ~10:1 compression ratio).\nfunc (p *Platform) compressAudio(ctx context.Context, audio []byte, format string) ([]byte, string, error) {\n\t// Only WAV format can be compressed to MP3","sourceCodeStart":1263,"sourceCodeEnd":1299,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/dingtalk/dingtalk.go#L1263-L1299","documentation":"This error wraps a failure from httpClient.Do when executing the audio voice-message request to DingTalk's oToMessages batchSend endpoint. The request was built but the HTTP round trip failed: DNS, connect, TLS, timeout, or context cancellation. No response was received from DingTalk.","triggerScenarios":"Calling SendAudio when the network to api.dingtalk.com is down, the context is cancelled mid-flight, the HTTP client timeout expires, TLS fails, or a proxy/firewall blocks the connection.","commonSituations":"Offline or restricted hosts, slow networks timing out during send, VPN/proxy interruptions, upstream engine cancelling the context.","solutions":["Check the wrapped error: timeout vs connection refused vs context cancelled","Test connectivity: curl -v https://api.dingtalk.com/v1.0/robot/oToMessages/batchSend","Increase the httpClient timeout and retry with backoff on transient errors","Ensure no proxy env vars (HTTP_PROXY/HTTPS_PROXY) interfere with api.dingtalk.com"],"exampleFix":"// before\nclient := &http.Client{Timeout: 5 * time.Second}\n// after\nclient := &http.Client{Timeout: 30 * time.Second}\n// plus caller-side retry\nvar err error\nfor i := 0; i < 3; i++ { if err = p.SendAudio(ctx, rc, audio, format); err == nil { break }; time.Sleep(time.Duration(1<<i) * time.Second) }","handlingStrategy":"retry","validationCode":"conn, err := net.DialTimeout(\"tcp\", \"api.dingtalk.com:443\", 5*time.Second); if err != nil { /* network unavailable */ }","typeGuard":null,"tryCatchPattern":"err := p.SendAudio(ctx, rc, audio, format)\nif err != nil {\n    var ne net.Error\n    if errors.As(err, &ne) && ne.Timeout() { /* retry with backoff */ }\n    if errors.Is(err, context.Canceled) { /* caller cancelled; don't retry */ }\n}","preventionTips":["Use a 15-30s client timeout for voice message sends","Implement exponential-backoff retries for transient network errors","Don't cancel the request context while audio is in flight","Check HTTP(S)_PROXY settings don't block api.dingtalk.com"],"tags":["dingtalk","http","network","timeout"],"backgroundTag":"network-request-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}