diff --git a/README.md b/README.md
index f83eea43..e088c47f 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
# Allure notifications
-**Allure notifications** - это библиотека, позволяющая выполнять автоматическое оповещение о результатах прохождения автотестов, которое направляется в нужный вам мессенджер (Telegram, Slack, Skype, Email, Mattermost, Discord, Loop).
+**Allure notifications** - это библиотека, позволяющая выполнять автоматическое оповещение о результатах прохождения автотестов, которое направляется в нужный вам мессенджер (Telegram, Slack, Skype, Email, Mattermost, Discord, Loop, Rocket.Chat).
Languages: 🇬🇧 🇫🇷 🇷🇺 🇺🇦 🇧🇾 🇨🇳
@@ -92,6 +92,12 @@ Languages: 🇬🇧 🇫🇷 🇷🇺 🇺🇦 🇧🇾 🇨🇳
"token": "",
"chat": ""
},
+ "rocketChat" : {
+ "url": "",
+ "auth_token": "",
+ "user_id": "",
+ "channel": ""
+ },
"skype": {
"appId": "",
"appSecret": "",
@@ -246,4 +252,19 @@ java "-DconfigFile=notifications/config.json" -jar ../allure-notifications-4.2.1
Click "Save".
Copy URL of webhook.
+
++
+ Rocket.Chat config
+ To enable Rocket.Chat notifications it's required to provide 4 configuration parameters:
+ url
, auth_token
,user_id
,channel
+
+ -
+
+ - First of all you need to generate auth_token from user setting.
+ - After generation you can get auth_token and user_id.
+ - You can get the channel parameter using previously generated tokens and following the documentation.
++ (Channels info docs)
+
+
+
\ No newline at end of file
diff --git a/src/main/java/guru/qa/allure/notifications/clients/ClientFactory.java b/src/main/java/guru/qa/allure/notifications/clients/ClientFactory.java
index cc054287..4314050d 100644
--- a/src/main/java/guru/qa/allure/notifications/clients/ClientFactory.java
+++ b/src/main/java/guru/qa/allure/notifications/clients/ClientFactory.java
@@ -1,5 +1,6 @@
package guru.qa.allure.notifications.clients;
+import guru.qa.allure.notifications.clients.rocket.RocketChatClient;
import java.util.ArrayList;
import java.util.List;
@@ -40,6 +41,9 @@ public static List from(Config config) {
if (config.getLoop() != null) {
notifiers.add(new LoopClient(messageData, config.getLoop()));
}
+ if (config.getRocketChat() != null) {
+ notifiers.add(new RocketChatClient(messageData, config.getRocketChat()));
+ }
return notifiers;
}
}
diff --git a/src/main/java/guru/qa/allure/notifications/clients/rocket/RocketChatClient.java b/src/main/java/guru/qa/allure/notifications/clients/rocket/RocketChatClient.java
new file mode 100644
index 00000000..51cf3499
--- /dev/null
+++ b/src/main/java/guru/qa/allure/notifications/clients/rocket/RocketChatClient.java
@@ -0,0 +1,49 @@
+package guru.qa.allure.notifications.clients.rocket;
+
+import guru.qa.allure.notifications.clients.Notifier;
+import guru.qa.allure.notifications.config.rocket.RocketChat;
+import guru.qa.allure.notifications.exceptions.MessagingException;
+import guru.qa.allure.notifications.template.RocketTemplate;
+import guru.qa.allure.notifications.template.data.MessageData;
+import java.io.ByteArrayInputStream;
+import java.util.HashMap;
+import java.util.Map;
+import kong.unirest.ContentType;
+import kong.unirest.Unirest;
+
+public class RocketChatClient implements Notifier {
+
+ private final RocketChat rocketChat;
+ private final RocketTemplate template;
+
+ public RocketChatClient(MessageData messageData, RocketChat rocket) {
+ this.rocketChat = rocket;
+ this.template = new RocketTemplate(messageData);
+ }
+
+ @Override
+ public void sendText() throws MessagingException {
+ Map body = new HashMap<>();
+ body.put("channel", rocketChat.getChannel());
+ body.put("text", template.create());
+ Unirest.post(rocketChat.getUrl() + "/api/v1/chat.postMessage")
+ .header("X-Auth-Token", rocketChat.getToken())
+ .header("X-User-Id", rocketChat.getUserId())
+ .header("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
+ .body(body)
+ .asString()
+ .getBody();
+ }
+
+ @Override
+ public void sendPhoto(byte[] chartImage) throws MessagingException {
+ sendText();
+ String url = String.format("%s/api/v1/rooms.upload/%s", rocketChat.getUrl(), rocketChat.getChannel());
+ Unirest.post(url)
+ .header("X-Auth-Token", rocketChat.getToken())
+ .header("X-User-Id", rocketChat.getUserId())
+ .field("file", new ByteArrayInputStream(chartImage), ContentType.IMAGE_PNG, "chart.png")
+ .asString()
+ .getBody();
+ }
+}
diff --git a/src/main/java/guru/qa/allure/notifications/config/Config.java b/src/main/java/guru/qa/allure/notifications/config/Config.java
index 065cf4d9..b239b29d 100644
--- a/src/main/java/guru/qa/allure/notifications/config/Config.java
+++ b/src/main/java/guru/qa/allure/notifications/config/Config.java
@@ -7,6 +7,7 @@
import guru.qa.allure.notifications.config.mail.Mail;
import guru.qa.allure.notifications.config.mattermost.Mattermost;
import guru.qa.allure.notifications.config.proxy.Proxy;
+import guru.qa.allure.notifications.config.rocket.RocketChat;
import guru.qa.allure.notifications.config.skype.Skype;
import guru.qa.allure.notifications.config.slack.Slack;
import guru.qa.allure.notifications.config.telegram.Telegram;
@@ -35,6 +36,8 @@ public class Config {
private Discord discord;
@SerializedName("loop")
private Loop loop;
+ @SerializedName("rocketChat")
+ private RocketChat rocketChat;
@SerializedName("proxy")
private Proxy proxy;
}
diff --git a/src/main/java/guru/qa/allure/notifications/config/rocket/RocketChat.java b/src/main/java/guru/qa/allure/notifications/config/rocket/RocketChat.java
new file mode 100644
index 00000000..73c175b2
--- /dev/null
+++ b/src/main/java/guru/qa/allure/notifications/config/rocket/RocketChat.java
@@ -0,0 +1,17 @@
+package guru.qa.allure.notifications.config.rocket;
+
+import com.google.gson.annotations.SerializedName;
+import lombok.Getter;
+
+@Getter
+public class RocketChat {
+
+ @SerializedName("url")
+ private String url;
+ @SerializedName("auth_token")
+ private String token;
+ @SerializedName("user_id")
+ private String userId;
+ @SerializedName("channel")
+ private String channel;
+}
diff --git a/src/main/java/guru/qa/allure/notifications/template/RocketTemplate.java b/src/main/java/guru/qa/allure/notifications/template/RocketTemplate.java
new file mode 100644
index 00000000..f07f79e8
--- /dev/null
+++ b/src/main/java/guru/qa/allure/notifications/template/RocketTemplate.java
@@ -0,0 +1,17 @@
+package guru.qa.allure.notifications.template;
+
+import guru.qa.allure.notifications.exceptions.MessageBuildException;
+import guru.qa.allure.notifications.template.data.MessageData;
+
+public class RocketTemplate {
+
+ private final MessageData messageData;
+
+ public RocketTemplate(MessageData messageData) {
+ this.messageData = messageData;
+ }
+
+ public String create() throws MessageBuildException {
+ return new MessageTemplate(messageData).of("rocket.ftl");
+ }
+}
diff --git a/src/main/resources/templates/rocket.ftl b/src/main/resources/templates/rocket.ftl
new file mode 100644
index 00000000..da00d574
--- /dev/null
+++ b/src/main/resources/templates/rocket.ftl
@@ -0,0 +1,13 @@
+<#compress>
+ **${results}:**
+ **-${environment}:** ${env}
+ **-${comment}:** ${comm}
+ **-${duration}:** **${time}**
+ **-${totalScenarios}:** ${total}
+ <#if passed != 0 > **-${totalPassed}:** ${passed} **(${passedPercentage} %)**#if>
+ <#if failed != 0 > **-${totalFailed}:** ${failed} **(${failedPercentage} %)** #if>
+ <#if broken != 0 > **-${totalBroken}:** ${broken} #if>
+ <#if unknown != 0 > **-${totalUnknown}:** ${unknown} #if>
+ <#if skipped != 0 > **-${totalSkipped}:** ${skipped} #if>
+ <#if reportLink??>**${reportAvailableAtLink}:** ${reportLink}#if>
+#compress>
\ No newline at end of file