From 314fa18bdcdab25147d4df3ca3ed754888188e3f Mon Sep 17 00:00:00 2001 From: Adam Stachowicz <adam.stachowicz@fingo.info> Date: Thu, 4 Nov 2021 00:19:04 +0100 Subject: [PATCH 1/3] Fix #871 --- src/components/notifications/Telegram.vue | 32 +++++++++-------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/components/notifications/Telegram.vue b/src/components/notifications/Telegram.vue index 3fe287eee..0fa4dd55e 100644 --- a/src/components/notifications/Telegram.vue +++ b/src/components/notifications/Telegram.vue @@ -25,13 +25,7 @@ </p> <p style="margin-top: 8px;"> - <template v-if="$parent.notification.telegramBotToken"> - <a :href="telegramGetUpdatesURL" target="_blank" style="word-break: break-word;">{{ telegramGetUpdatesURL }}</a> - </template> - - <template v-else> - {{ telegramGetUpdatesURL }} - </template> + {{ telegramGetUpdatesURL() }} </p> </div> </div> @@ -40,49 +34,47 @@ <script> import HiddenInput from "../HiddenInput.vue"; import axios from "axios"; -import { useToast } from "vue-toastification" +import { useToast } from "vue-toastification"; const toast = useToast(); export default { components: { HiddenInput, }, - computed: { - telegramGetUpdatesURL() { - let token = `<${this.$t("YOUR BOT TOKEN HERE")}>` + methods: { + telegramGetUpdatesURL(withToken = false) { + let token = `<${this.$t("YOUR BOT TOKEN HERE")}>`; - if (this.$parent.notification.telegramBotToken) { + if (this.$parent.notification.telegramBotToken && withToken) { token = this.$parent.notification.telegramBotToken; } return `https://api.telegram.org/bot${token}/getUpdates`; }, - }, - methods: { async autoGetTelegramChatID() { try { - let res = await axios.get(this.telegramGetUpdatesURL) + let res = await axios.get(this.telegramGetUpdatesURL(true)); if (res.data.result.length >= 1) { - let update = res.data.result[res.data.result.length - 1] + let update = res.data.result[res.data.result.length - 1]; if (update.channel_post) { this.notification.telegramChatID = update.channel_post.chat.id; } else if (update.message) { this.notification.telegramChatID = update.message.chat.id; } else { - throw new Error(this.$t("chatIDNotFound")) + throw new Error(this.$t("chatIDNotFound")); } } else { - throw new Error(this.$t("chatIDNotFound")) + throw new Error(this.$t("chatIDNotFound")); } } catch (error) { - toast.error(error.message) + toast.error(error.message); } }, } -} +}; </script> From ba46fb6b1c126838eae55ed6b5a87de937e00ed7 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz <adam.stachowicz@fingo.info> Date: Wed, 10 Nov 2021 09:11:19 +0100 Subject: [PATCH 2/3] Clickable URL --- src/components/notifications/Telegram.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/notifications/Telegram.vue b/src/components/notifications/Telegram.vue index 0fa4dd55e..55ff7ec45 100644 --- a/src/components/notifications/Telegram.vue +++ b/src/components/notifications/Telegram.vue @@ -25,7 +25,7 @@ </p> <p style="margin-top: 8px;"> - {{ telegramGetUpdatesURL() }} + <a :href="telegramGetUpdatesURL(true)" target="_blank" style="word-break: break-word;">{{ telegramGetUpdatesURL() }}</a> </p> </div> </div> From d645e29455e850792d63d01bb3d26080878f5993 Mon Sep 17 00:00:00 2001 From: Louis <louislam@users.noreply.github.com> Date: Sun, 5 Dec 2021 17:40:13 +0800 Subject: [PATCH 3/3] mask telegram api url with asterisk --- src/components/notifications/Telegram.vue | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/components/notifications/Telegram.vue b/src/components/notifications/Telegram.vue index 55ff7ec45..d263f636f 100644 --- a/src/components/notifications/Telegram.vue +++ b/src/components/notifications/Telegram.vue @@ -25,7 +25,7 @@ </p> <p style="margin-top: 8px;"> - <a :href="telegramGetUpdatesURL(true)" target="_blank" style="word-break: break-word;">{{ telegramGetUpdatesURL() }}</a> + <a :href="telegramGetUpdatesURL('withToken')" target="_blank" style="word-break: break-word;">{{ telegramGetUpdatesURL("masked") }}</a> </p> </div> </div> @@ -42,18 +42,22 @@ export default { HiddenInput, }, methods: { - telegramGetUpdatesURL(withToken = false) { + telegramGetUpdatesURL(mode = "masked") { let token = `<${this.$t("YOUR BOT TOKEN HERE")}>`; - if (this.$parent.notification.telegramBotToken && withToken) { - token = this.$parent.notification.telegramBotToken; + if (this.$parent.notification.telegramBotToken) { + if (mode === "withToken") { + token = this.$parent.notification.telegramBotToken; + } else if (mode === "masked") { + token = "*".repeat(this.$parent.notification.telegramBotToken.length); + } } return `https://api.telegram.org/bot${token}/getUpdates`; }, async autoGetTelegramChatID() { try { - let res = await axios.get(this.telegramGetUpdatesURL(true)); + let res = await axios.get(this.telegramGetUpdatesURL("withToken")); if (res.data.result.length >= 1) { let update = res.data.result[res.data.result.length - 1];