From e10c4f1380dfaf1c268cc17fe7ae3ef71ce2278f Mon Sep 17 00:00:00 2001 From: danielkyalo599 Date: Mon, 13 Feb 2023 09:14:19 +0300 Subject: [PATCH] Added support for hmtl format --- .../notifications/spi/model/MessageContent.kt | 10 ++++++++-- .../spi/model/destination/TelegramDestination.kt | 14 -------------- 2 files changed, 8 insertions(+), 16 deletions(-) delete mode 100644 notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/TelegramDestination.kt diff --git a/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/MessageContent.kt b/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/MessageContent.kt index f10b6ccc..f577ad6a 100644 --- a/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/MessageContent.kt +++ b/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/MessageContent.kt @@ -23,10 +23,16 @@ class MessageContent( init { require(!Strings.isNullOrEmpty(title)) { "title is null or empty" } - require(!Strings.isNullOrEmpty(textDescription)) { "text message part is null or empty" } + require(!Strings.isNullOrEmpty(textDescription) || !Strings.isNullOrEmpty(htmlDescription)) { + "text message part and html message part are both null or empty" + } } fun buildMessageWithTitle(): String { - return "$title\n\n$textDescription" + return if (htmlDescription != null) { + htmlDescription + } else { + "$title\n\n$textDescription" + } } } diff --git a/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/TelegramDestination.kt b/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/TelegramDestination.kt deleted file mode 100644 index 5dfd957b..00000000 --- a/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/TelegramDestination.kt +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.notifications.spi.model.destination -/* -This class holds the contents of a Telegram destination - */ -class TelegramDestination( - val token: String, - val chatId: Long, - val url: String = "https://api.telegram.org/bot$token/sendMessage?chat_id=$chatId" -) : WebhookDestination(url, DestinationType.TELEGRAM)