diff --git a/GUIDE.md b/GUIDE.md index a1c9401..d5779cb 100644 --- a/GUIDE.md +++ b/GUIDE.md @@ -1,5 +1,3 @@ -**English** | [简体中文](./GUIDE.zh-CN.md) - # DingTalk Channel SDK Integration Guide Connect your Agent to DingTalk for real-time conversations in **group chats and direct messages**. The SDK handles event ingestion, message parsing and deduplication, reply sending, streaming output (typewriter effect), media upload/download, and card interactions—you just need to tell it "what the user said and what the bot should respond with." diff --git a/OVERVIEW.md b/OVERVIEW.md index 9f45fee..b1c33fa 100644 --- a/OVERVIEW.md +++ b/OVERVIEW.md @@ -1,5 +1,3 @@ -**English** | [简体中文](./OVERVIEW.zh-CN.md) - # DingTalk Channel SDK Family · Project Overview > Origin issue: [DingTalk-Real-AI/dingtalk-workspace-cli#796](https://github.com/DingTalk-Real-AI/dingtalk-workspace-cli/issues/796)—"Will DingTalk offer a Channel-like integration SDK in the future?" diff --git a/SPEC.md b/SPEC.md index 1ec2b1d..15c24ae 100644 --- a/SPEC.md +++ b/SPEC.md @@ -1,5 +1,3 @@ -**English** | [简体中文](./SPEC.zh-CN.md) - # DingTalk Channel SDK — Four-Language Unified Contract (SPEC v0.1) > Positioning: **A conversation access layer decoupled from Agent runtime**. The SDK handles the dirty work of the "channel", diff --git a/src/main/java/com/dingtalk/channel/DingTalkChannel.java b/src/main/java/com/dingtalk/channel/DingTalkChannel.java index 63ce332..5ec3450 100644 --- a/src/main/java/com/dingtalk/channel/DingTalkChannel.java +++ b/src/main/java/com/dingtalk/channel/DingTalkChannel.java @@ -198,7 +198,7 @@ public byte[] downloadFile(String downloadCode, String msgId, String mediaType) try { java.net.HttpURLConnection conn = openMediaConnection(downloadUrl); try (java.io.InputStream in = conn.getInputStream()) { - return in.readAllBytes(); + return readAll(in); } finally { conn.disconnect(); } @@ -278,7 +278,7 @@ private java.net.HttpURLConnection openMediaConnection(String initialUrl) throws if (status != 200) { try (java.io.InputStream err = conn.getErrorStream()) { if (err != null) { - err.readAllBytes(); + readAll(err); } } finally { conn.disconnect(); @@ -290,6 +290,16 @@ private java.net.HttpURLConnection openMediaConnection(String initialUrl) throws throw new java.io.IOException("too many redirects"); } + private static byte[] readAll(java.io.InputStream in) throws java.io.IOException { + java.io.ByteArrayOutputStream buf = new java.io.ByteArrayOutputStream(); + byte[] chunk = new byte[8192]; + int n; + while ((n = in.read(chunk)) != -1) { + buf.write(chunk, 0, n); + } + return buf.toByteArray(); + } + /** 换取媒体下载 URL(downloadCode → downloadUrl)。 */ private String resolveDownloadUrl(String downloadCode, String msgId) { if (downloadCode == null || downloadCode.isEmpty()) { diff --git a/src/test/java/com/dingtalk/channel/safety/PolicyOverrideTest.java b/src/test/java/com/dingtalk/channel/safety/PolicyOverrideTest.java index 1e1def0..b8a1d8a 100644 --- a/src/test/java/com/dingtalk/channel/safety/PolicyOverrideTest.java +++ b/src/test/java/com/dingtalk/channel/safety/PolicyOverrideTest.java @@ -4,8 +4,8 @@ import com.dingtalk.channel.IncomingMessage; import org.junit.Test; +import java.util.Arrays; import java.util.HashMap; -import java.util.List; import java.util.Map; import static org.junit.Assert.assertEquals; @@ -29,7 +29,7 @@ public void overrideAdmitsGroupInAllowlistMode() { Map ov = new HashMap<>(); ov.put("cid-other", new PolicyConfig.GroupOverride()); PolicyGate gate = new PolicyGate(new PolicyConfig() - .groupAllowlist(List.of("cid-allowed")) + .groupAllowlist(Arrays.asList("cid-allowed")) .groupOverrides(ov)); assertTrue(gate.evaluate(msg("cid-other", "staff-1", true)).allowed); assertEquals(RejectReason.GROUP_NOT_ALLOWED, gate.evaluate(msg("cid-unknown", "staff-1", true)).reason); @@ -40,7 +40,7 @@ public void blocklistNeverOverridden() { Map ov = new HashMap<>(); ov.put("cid-bad", new PolicyConfig.GroupOverride().enabled(true)); PolicyGate gate = new PolicyGate(new PolicyConfig() - .groupBlocklist(List.of("cid-bad")) + .groupBlocklist(Arrays.asList("cid-bad")) .groupOverrides(ov)); assertEquals(RejectReason.GROUP_BLOCKED, gate.evaluate(msg("cid-bad", "staff-1", true)).reason); } @@ -66,8 +66,8 @@ public void overrideDisableAndRequireMention() { public void overrideAllowFromAndBlockFrom() { Map ov = new HashMap<>(); ov.put("cid-1", new PolicyConfig.GroupOverride() - .allowFrom(List.of("staff-1", "staff-2")) - .blockFrom(List.of("staff-2"))); + .allowFrom(Arrays.asList("staff-1", "staff-2")) + .blockFrom(Arrays.asList("staff-2"))); PolicyGate gate = new PolicyGate(new PolicyConfig().groupOverrides(ov)); assertTrue(gate.evaluate(msg("cid-1", "staff-1", true)).allowed); assertEquals(RejectReason.SENDER_NOT_ALLOWED, gate.evaluate(msg("cid-1", "staff-9", true)).reason);