diff --git a/libs/bot4j-v1.0.0.jar b/libs/bot4j-v1.0.0.jar index 2dc5d9a..294a9e2 100644 Binary files a/libs/bot4j-v1.0.0.jar and b/libs/bot4j-v1.0.0.jar differ diff --git a/plugin/src/main/groovy/org/botwrap4j/service/TelegramWrapService.java b/plugin/src/main/groovy/org/botwrap4j/service/TelegramWrapService.java index d40e75e..38bed41 100644 --- a/plugin/src/main/groovy/org/botwrap4j/service/TelegramWrapService.java +++ b/plugin/src/main/groovy/org/botwrap4j/service/TelegramWrapService.java @@ -1,6 +1,7 @@ package org.botwrap4j.service; import org.bot4j.telegram.common.Telegram4j; +import org.bot4j.telegram.message.MessageBuilder; import org.botwrap4j.model.request.TelegramClustersRequest; public interface TelegramWrapService { @@ -13,16 +14,24 @@ public interface TelegramWrapService { void sendMessageSilent(String key, String message); + void sendMessageSilent(String key, MessageBuilder message); + void sendMessageSilentAfterWaitSec(String key, long seconds, String message); + void sendMessageSilentAfterWaitSec(String key, long seconds, MessageBuilder message); + void sendMessageSilent(String key, StringBuilder message); void sendMessageSilent(String key, Object message); void sendMessageSilent(String key, String clusterId, String message); + void sendMessageSilent(String key, String clusterId, MessageBuilder message); + void sendMessageSilentAfterWaitSec(String key, String clusterId, long seconds, String message); + void sendMessageSilentAfterWaitSec(String key, String clusterId, long seconds, MessageBuilder message); + void sendMessageSilent(String key, String clusterId, StringBuilder message); void sendMessageSilent(String key, String clusterId, Object message); diff --git a/plugin/src/main/groovy/org/botwrap4j/service/impl/TelegramWrapServiceImpl.java b/plugin/src/main/groovy/org/botwrap4j/service/impl/TelegramWrapServiceImpl.java index eaa0b03..7d5a8a9 100644 --- a/plugin/src/main/groovy/org/botwrap4j/service/impl/TelegramWrapServiceImpl.java +++ b/plugin/src/main/groovy/org/botwrap4j/service/impl/TelegramWrapServiceImpl.java @@ -1,6 +1,7 @@ package org.botwrap4j.service.impl; import org.bot4j.telegram.common.Telegram4j; +import org.bot4j.telegram.message.MessageBuilder; import org.bot4j.telegram.model.builder.TelegramConnectionBuilder; import org.botwrap4j.common.BotWrap4j; import org.botwrap4j.model.request.TelegramClustersRequest; @@ -12,6 +13,7 @@ import org.springframework.stereotype.Service; import org.unify4j.common.Class4j; import org.unify4j.common.Json4j; +import org.unify4j.common.String4j; import org.unify4j.common.Time4j; import java.util.Optional; @@ -91,6 +93,18 @@ public void sendMessageSilent(String key, String message) { telegram4j.requestId(BotWrap4j.getCurrentSessionId()).sendMessageSilent(); } + /** + * @param key - the key configured for telegram clusters + * @param message - the message builder, class {@link MessageBuilder} + */ + @Override + public void sendMessageSilent(String key, MessageBuilder message) { + if (!botWrapService.isEnabled() || message == null) { + return; + } + this.sendMessageSilent(key, message.toString()); + } + /** * @param key - the key configured for telegram clusters, * @param seconds - the second after waiting @@ -98,7 +112,7 @@ public void sendMessageSilent(String key, String message) { */ @Override public void sendMessageSilentAfterWaitSec(String key, long seconds, String message) { - if (!botWrapService.isEnabled()) { + if (!botWrapService.isEnabled() || seconds < 0 || String4j.isEmpty(message)) { return; } new Thread(() -> { @@ -118,6 +132,19 @@ public void sendMessageSilentAfterWaitSec(String key, long seconds, String messa }).start(); } + /** + * @param key - the key configured for telegram clusters, + * @param seconds - the second after waiting + * @param message - the message will be sent, class {@link MessageBuilder} + */ + @Override + public void sendMessageSilentAfterWaitSec(String key, long seconds, MessageBuilder message) { + if (!botWrapService.isEnabled() || seconds < 0 || message == null) { + return; + } + this.sendMessageSilentAfterWaitSec(key, seconds, message.toString()); + } + /** * @param key - the key configured for telegram clusters, * @param message - the message will be sent @@ -143,7 +170,7 @@ public void sendMessageSilent(String key, Object message) { */ @Override public void sendMessageSilent(String key, String clusterId, String message) { - if (!botWrapService.isEnabled()) { + if (!botWrapService.isEnabled() || String4j.isEmpty(clusterId)) { return; } Telegram4j telegram4j = this.valueOf(key, clusterId, message); @@ -153,6 +180,19 @@ public void sendMessageSilent(String key, String clusterId, String message) { telegram4j.requestId(BotWrap4j.getCurrentSessionId()).sendMessageSilent(); } + /** + * @param key - the key configured for telegram clusters, + * @param message - the message will be sent + * @param clusterId - the cluster_id + */ + @Override + public void sendMessageSilent(String key, String clusterId, MessageBuilder message) { + if (!botWrapService.isEnabled() || String4j.isEmpty(clusterId) || message == null) { + return; + } + this.sendMessageSilent(key, clusterId, message.toString()); + } + /** * @param key - the key configured for telegram clusters, * @param message - the message will be sent @@ -161,7 +201,7 @@ public void sendMessageSilent(String key, String clusterId, String message) { */ @Override public void sendMessageSilentAfterWaitSec(String key, String clusterId, long seconds, String message) { - if (!botWrapService.isEnabled()) { + if (!botWrapService.isEnabled() || String4j.isEmpty(clusterId) || seconds < 0) { return; } new Thread(() -> { @@ -181,6 +221,20 @@ public void sendMessageSilentAfterWaitSec(String key, String clusterId, long sec }).start(); } + /** + * @param key - the key configured for telegram clusters, + * @param message - the message will be sent + * @param clusterId - the cluster_id + * @param seconds - the second after waiting + */ + @Override + public void sendMessageSilentAfterWaitSec(String key, String clusterId, long seconds, MessageBuilder message) { + if (!botWrapService.isEnabled() || String4j.isEmpty(clusterId) || seconds < 0 || message == null) { + return; + } + this.sendMessageSilentAfterWaitSec(key, clusterId, seconds, message.toString()); + } + /** * @param key - the key configured for telegram clusters, * @param message - the message will be sent