diff --git a/plugin/src/main/groovy/org/bot4j/telegram/message/MessageFactory.java b/plugin/src/main/groovy/org/bot4j/telegram/message/MessageFactory.java index e64985a..0582970 100644 --- a/plugin/src/main/groovy/org/bot4j/telegram/message/MessageFactory.java +++ b/plugin/src/main/groovy/org/bot4j/telegram/message/MessageFactory.java @@ -5,7 +5,7 @@ public abstract class MessageFactory { /** * Create a MarkdownBuilder instance. * - * @return MarkdownBuilder instance + * @return MarkdownBuilder instance, class {@link MarkdownBuilder} */ public static MarkdownBuilder markdown() { return new MarkdownBuilder(); @@ -14,9 +14,27 @@ public static MarkdownBuilder markdown() { /** * Create a HtmlBuilder instance. * - * @return HtmlBuilder instance + * @return HtmlBuilder instance, class {@link HtmlBuilder} */ public static HtmlBuilder html() { return new HtmlBuilder(); } + + /** + * Create a HttpBuilder instance. + * + * @return HttpBuilder instance, class {@link HttpBuilder} + */ + public static HttpBuilder http() { + return new HttpBuilder(); + } + + /** + * Create a HttpBuilder instance. + * + * @return HttpBuilder instance, class {@link NotifyBuilder} + */ + public static NotifyBuilder reveal() { + return new NotifyBuilder(); + } } diff --git a/plugin/src/main/groovy/org/bot4j/telegram/message/NotifyBuilder.java b/plugin/src/main/groovy/org/bot4j/telegram/message/NotifyBuilder.java new file mode 100644 index 0000000..702e752 --- /dev/null +++ b/plugin/src/main/groovy/org/bot4j/telegram/message/NotifyBuilder.java @@ -0,0 +1,34 @@ +package org.bot4j.telegram.message; + +import org.alpha4j.common.Map4j; + +public class NotifyBuilder extends MarkdownBuilder { + protected final Map4j placeholders; + + public NotifyBuilder() { + super(); + this.placeholders = new Map4j<>(); + } + + protected static class Index { + public static final String CAUSE_INDEX = "cause_index"; + } + + public NotifyBuilder cause(Throwable e) { + if (e == null) { + return this; + } + this.placeholders.put(Index.CAUSE_INDEX, e.getMessage()); + return this; + } + + @Override + public String toString() { + if (this.placeholders.containsKey(Index.CAUSE_INDEX)) { + this.line().bold("Cause:") + .preformatted("bash", (String) this.placeholders.get(Index.CAUSE_INDEX)) + .line(); + } + return super.toString(); + } +}