Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6d621e5
feat(#open source) : init
Sep 20, 2023
4d2f8b0
Merge branch 'main' of github.com:open-dingtalk/dingtalk-stream-sdk-j…
Sep 20, 2023
7974d35
fix(#init) : init
Sep 20, 2023
b7ac889
feat: 支持自动化构建
chzealot Sep 21, 2023
0cf5203
feat: 升级至 1.0.8-SNAPSHOT
chzealot Sep 21, 2023
ec40f4e
feat: 更换 JDK 为 temurin
chzealot Sep 21, 2023
1e001e7
fix: 修复 GPG 签名问题
chzealot Sep 21, 2023
1148011
fix: 修复 GPG 签名问题
chzealot Sep 21, 2023
195a683
debug: 调试 gpg 流程
chzealot Sep 21, 2023
5db6d62
feat: 支持 settings 文件用于 maven deploy
chzealot Sep 21, 2023
aea4a76
fix: 修复 maven deploy 错误,指定 settings
chzealot Sep 21, 2023
21e6f01
feat: 增加 release 触发构建
chzealot Sep 21, 2023
08b03f5
Merge branch 'main' into develop
chzealot Sep 21, 2023
1529dd0
feat: 定义机器人消息类型
chzealot Sep 21, 2023
9a02e64
feat: 优化 workflow:如果是develop分支,仅当当前的maven 模块版本号以 SNAPSHOT 后缀时候才执行,否则不…
chzealot Sep 21, 2023
7cd531c
feat: 非 main 分支仅构建 SNAPSHOT 分支
chzealot Sep 21, 2023
313c7f7
fix: 添加 getter / setter
chzealot Sep 21, 2023
6e1ef66
fix: implement Serializable
chzealot Sep 21, 2023
6294aa6
feat: 为 MessageContent 字段补充 getter 和 setter
chzealot Sep 21, 2023
f0c7367
feat: 严格遵守协议,null 值一样输出
chzealot Sep 21, 2023
0eeefcf
feat: 升级版本号为 1.0.9
chzealot Sep 22, 2023
51b1ebc
Merge branch 'main' into develop
chzealot Sep 22, 2023
e9d9aef
Merge branch 'main' into develop
chzealot Nov 10, 2023
ec815a2
feat: 支持快速回复机器人消息
chzealot Nov 10, 2023
3b9a899
feat: 将 SNAPSHOT 版本号更新为正式版本
chzealot Nov 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app-stream-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>open-app-stream-client</artifactId>
<groupId>com.dingtalk.open</groupId>
<version>1.1.0</version>
<version>1.2.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package com.dingtalk.open.app.api.chatbot;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.dingtalk.open.app.api.open.http.HttpConstants;
import com.dingtalk.open.app.api.util.IoUtils;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BotReplier {
private final String webhook;
private final int timeout = 60000;

public BotReplier(String webhook) {
this.webhook = webhook;
}

public static BotReplier fromWebhook(String webhook) {
return new BotReplier(webhook);
}

public String replyText(String text) throws IOException {
return replyText(text, null);
}
public String replyMarkdown(String title, String text) throws IOException {
return replyMarkdown(title, text, null);
}

public String replyText(String text, List<String> atUserIds) throws IOException {
final HttpURLConnection connection = getHttpURLConnection();

Map<String, Object> textContent = new HashMap<>();
textContent.put("content", text);
Map<String, Object> request = new HashMap<>();
request.put("msgtype", "text");
request.put("text", textContent);
if (atUserIds != null && atUserIds.size() > 0) {
Map<String, Object> atContent = new HashMap<>();
atContent.put("atUserIds", Collections.singletonList(""));
request.put("at", atContent);
}
connection.getOutputStream().write(JSON.toJSONBytes(request, SerializerFeature.WriteEnumUsingToString));
connection.getOutputStream().flush();
if (connection.getResponseCode() == HttpConstants.STATUS_OK) {
try {
byte[] bytes = IoUtils.readAll(connection.getInputStream());
return new String(bytes, StandardCharsets.UTF_8);
} catch (Exception e) {
throw new IOException(e.getMessage());
}
} else {
try {
byte[] bytes = IoUtils.readAll(connection.getErrorStream());
throw new IOException(String.format("status=%s, msg=%s", connection.getResponseCode(), bytes != null ? new String(bytes) : ""));
} catch (Exception e) {
throw new IOException(e.getMessage());
}
}
}


public String replyMarkdown(String title, String text, List<String> atUserIds) throws IOException {
final HttpURLConnection connection = getHttpURLConnection();
Map<String, Object> markdownContent = new HashMap<>();
markdownContent.put("title", title);
markdownContent.put("text", text);
Map<String, Object> request = new HashMap<>();
request.put("msgtype", "markdown");
request.put("markdown", markdownContent);
if (atUserIds != null && atUserIds.size() > 0) {
Map<String, Object> atContent = new HashMap<>();
atContent.put("atUserIds", Collections.singletonList(""));
request.put("at", atContent);
}
connection.getOutputStream().write(JSON.toJSONBytes(request, SerializerFeature.WriteEnumUsingToString));
connection.getOutputStream().flush();
if (connection.getResponseCode() == HttpConstants.STATUS_OK) {
try {
byte[] bytes = IoUtils.readAll(connection.getInputStream());
return new String(bytes, StandardCharsets.UTF_8);
} catch (Exception e) {
throw new IOException(e.getMessage());
}
} else {
try {
byte[] bytes = IoUtils.readAll(connection.getErrorStream());
throw new IOException(String.format("status=%s, msg=%s", connection.getResponseCode(), bytes != null ? new String(bytes) : ""));
} catch (Exception e) {
throw new IOException(e.getMessage());
}
}
}

private HttpURLConnection getHttpURLConnection() throws IOException {
final HttpURLConnection connection = (HttpURLConnection) new URL(webhook).openConnection();
connection.setRequestMethod(HttpConstants.METHOD_POST);
connection.setReadTimeout(this.timeout);
connection.setConnectTimeout(this.timeout);
connection.setRequestProperty(HttpConstants.HEADER_CONTENT_TYPE, HttpConstants.CONTENT_TYPE_APPLICATION_JSON);
connection.setRequestProperty(HttpConstants.HEADER_ACCEPT, "application/json");
connection.setDoInput(true);
connection.setDoOutput(true);
connection.connect();
return connection;
}
}
4 changes: 2 additions & 2 deletions app-stream-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<parent>
<groupId>com.dingtalk.open</groupId>
<artifactId>open-app-stream-client</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>app-stream-client</artifactId>
<packaging>jar</packaging>
<version>1.1.0</version>
<version>1.2.0</version>
<name>app-stream-client</name>

<dependencies>
Expand Down
4 changes: 2 additions & 2 deletions app-stream-network/app-stream-network-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<parent>
<groupId>com.dingtalk.open</groupId>
<artifactId>app-stream-network</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>app-stream-network-api</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
<packaging>jar</packaging>

<name>app-stream-network-api</name>
Expand Down
2 changes: 1 addition & 1 deletion app-stream-network/app-stream-network-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.dingtalk.open</groupId>
<artifactId>app-stream-network</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion app-stream-network/app-stream-network-rsocket/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.dingtalk.open</groupId>
<artifactId>app-stream-network</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion app-stream-network/app-stream-network-ws/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.dingtalk.open</groupId>
<artifactId>app-stream-network</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion app-stream-network/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>open-app-stream-client</artifactId>
<groupId>com.dingtalk.open</groupId>
<version>1.1.0</version>
<version>1.2.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion app-stream-protocol/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.dingtalk.open</groupId>
<artifactId>open-app-stream-client</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
</parent>

<artifactId>app-stream-protocol</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions dingtalk-stream/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<parent>
<groupId>com.dingtalk.open</groupId>
<artifactId>open-app-stream-client</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>dingtalk-stream</artifactId>
<packaging>jar</packaging>
<version>1.1.0</version>
<version>1.2.0</version>
<name>app-stream-client</name>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>com.dingtalk.open</groupId>
<artifactId>open-app-stream-client</artifactId>
<packaging>pom</packaging>
<version>1.1.0</version>
<version>1.2.0</version>
<modules>
<module>app-stream-client</module>
<module>app-stream-api</module>
Expand Down
2 changes: 1 addition & 1 deletion version.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

mvn versions:set -DnewVersion=1.1.0
mvn versions:set -DnewVersion=1.2.0