From f046f698eb8e6775e061754801f9e6391d711083 Mon Sep 17 00:00:00 2001 From: Chenyang Ji Date: Wed, 11 Jan 2023 14:25:21 -0800 Subject: [PATCH 1/4] fix workflow failure on Cypress cache (#603) Signed-off-by: Chenyang Ji Signed-off-by: Chenyang Ji Co-authored-by: Chenyang Ji Signed-off-by: danielkyalo599 --- .../dashboards-notifications-test-and-build-workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dashboards-notifications-test-and-build-workflow.yml b/.github/workflows/dashboards-notifications-test-and-build-workflow.yml index 0ebe4ce6..2d3c456e 100644 --- a/.github/workflows/dashboards-notifications-test-and-build-workflow.yml +++ b/.github/workflows/dashboards-notifications-test-and-build-workflow.yml @@ -153,7 +153,7 @@ jobs: uses: actions/cache@v2 with: path: ${{ matrix.cypress_cache_folder }} - key: cypress-cache-v2-${{ runner.os }}-${{ hashFiles('**/package.json') }} + key: cypress-cache-v2-${{ runner.os }}-${{ hashFiles('OpenSearch-Dashboards/plugins/dashboards-notifications/package.json') }} - name: Reset npm's script shell if: ${{ matrix.os == 'windows-latest' }} From c6012c27bbca24f3582de14aca12fcf44e5659b4 Mon Sep 17 00:00:00 2001 From: danielkyalo599 Date: Fri, 10 Feb 2023 23:40:11 +0300 Subject: [PATCH 2/4] Added a class of telegram destination to support a new channel and custom webhook to select message Signed-off-by: danielkyalo599 --- .../notifications/spi/model/destination/TelegramDestination.kt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create 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/destination/TelegramDestination.kt b/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/TelegramDestination.kt new file mode 100644 index 00000000..e69de29b From a8817977008a8949a600577fcfff244fd730b8f4 Mon Sep 17 00:00:00 2001 From: danielkyalo599 Date: Fri, 10 Feb 2023 23:42:28 +0300 Subject: [PATCH 3/4] Added a class of telegram destination to support a new channel and custom webhook to select message Signed-off-by: danielkyalo599 --- .../spi/model/destination/DestinationType.kt | 2 +- .../spi/model/destination/TelegramDestination.kt | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/DestinationType.kt b/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/DestinationType.kt index f915e174..a989144e 100644 --- a/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/DestinationType.kt +++ b/notifications/core-spi/src/main/kotlin/org/opensearch/notifications/spi/model/destination/DestinationType.kt @@ -8,5 +8,5 @@ package org.opensearch.notifications.spi.model.destination * Supported notification destinations */ enum class DestinationType { - CHIME, SLACK, CUSTOM_WEBHOOK, SMTP, SES, SNS + CHIME, SLACK, CUSTOM_WEBHOOK, SMTP, SES, SNS, TELEGRAM } 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 index e69de29b..5dfd957b 100644 --- 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 @@ -0,0 +1,14 @@ +/* + * 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) From 893e378b76da7c9bde95e7ea770a8d9aa953c321 Mon Sep 17 00:00:00 2001 From: danielkyalo599 Date: Mon, 13 Feb 2023 09:14:19 +0300 Subject: [PATCH 4/4] Added support for hmtl format Signed-off-by: danielkyalo599 --- .../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)