Merge pull request #873 from Saibamen/fix_871

Fix Telegram Bot Token displayed in notification setup view
This commit is contained in:
Louis Lam 2021-12-05 18:04:54 +08:00 committed by GitHub
commit f331f1a63e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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>
<a :href="telegramGetUpdatesURL('withToken')" target="_blank" style="word-break: break-word;">{{ telegramGetUpdatesURL("masked") }}</a>
</p>
</div>
</div>
@ -40,49 +34,51 @@
<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(mode = "masked") {
let token = `<${this.$t("YOUR BOT TOKEN HERE")}>`;
if (this.$parent.notification.telegramBotToken) {
token = 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`;
},
},
methods: {
async autoGetTelegramChatID() {
try {
let res = await axios.get(this.telegramGetUpdatesURL)
let res = await axios.get(this.telegramGetUpdatesURL("withToken"));
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>