2021-09-07 15:32:05 +00:00
|
|
|
<template>
|
2021-09-08 02:25:03 +00:00
|
|
|
<div class="mb-3">
|
2021-09-21 05:02:41 +00:00
|
|
|
<label for="telegram-bot-token" class="form-label">{{ $t("Bot Token") }}</label>
|
2022-10-13 11:28:02 +00:00
|
|
|
<HiddenInput id="telegram-bot-token" v-model="$parent.notification.telegramBotToken" :required="true" autocomplete="new-password"></HiddenInput>
|
2021-10-12 08:29:18 +00:00
|
|
|
<i18n-t tag="div" keypath="wayToGetTelegramToken" class="form-text">
|
|
|
|
<a href="https://t.me/BotFather" target="_blank">https://t.me/BotFather</a>
|
|
|
|
</i18n-t>
|
2021-09-08 02:25:03 +00:00
|
|
|
</div>
|
2021-09-07 15:32:05 +00:00
|
|
|
|
2021-09-08 02:25:03 +00:00
|
|
|
<div class="mb-3">
|
2021-09-21 05:02:41 +00:00
|
|
|
<label for="telegram-chat-id" class="form-label">{{ $t("Chat ID") }}</label>
|
2021-09-07 15:32:05 +00:00
|
|
|
|
2021-09-08 02:25:03 +00:00
|
|
|
<div class="input-group mb-3">
|
|
|
|
<input id="telegram-chat-id" v-model="$parent.notification.telegramChatID" type="text" class="form-control" required>
|
|
|
|
<button v-if="$parent.notification.telegramBotToken" class="btn btn-outline-secondary" type="button" @click="autoGetTelegramChatID">
|
|
|
|
{{ $t("Auto Get") }}
|
|
|
|
</button>
|
|
|
|
</div>
|
2021-09-07 15:32:05 +00:00
|
|
|
|
2021-09-08 02:25:03 +00:00
|
|
|
<div class="form-text">
|
2021-09-21 05:02:41 +00:00
|
|
|
{{ $t("supportTelegramChatID") }}
|
2021-09-07 15:32:05 +00:00
|
|
|
|
2021-09-08 02:25:03 +00:00
|
|
|
<p style="margin-top: 8px;">
|
2021-09-21 05:02:41 +00:00
|
|
|
{{ $t("wayToGetTelegramChatID") }}
|
2021-09-08 02:25:03 +00:00
|
|
|
</p>
|
2021-09-07 15:32:05 +00:00
|
|
|
|
2021-09-08 02:25:03 +00:00
|
|
|
<p style="margin-top: 8px;">
|
2021-12-05 09:40:13 +00:00
|
|
|
<a :href="telegramGetUpdatesURL('withToken')" target="_blank" style="word-break: break-word;">{{ telegramGetUpdatesURL("masked") }}</a>
|
2021-09-08 02:25:03 +00:00
|
|
|
</p>
|
2021-09-07 15:32:05 +00:00
|
|
|
</div>
|
2022-11-20 00:10:30 +00:00
|
|
|
|
2023-02-23 12:59:24 +00:00
|
|
|
<label for="message_thread_id" class="form-label">{{ $t("telegramMessageThreadID") }}</label>
|
|
|
|
<input id="message_thread_id" v-model="$parent.notification.telegramMessageThreadID" type="text" class="form-control">
|
|
|
|
<p class="form-text">{{ $t("telegramMessageThreadIDDescription") }}</p>
|
2023-02-24 08:42:57 +00:00
|
|
|
|
2022-11-20 00:10:30 +00:00
|
|
|
<div class="form-check form-switch">
|
|
|
|
<input v-model="$parentnotification.telegramSendSilently" class="form-check-input" type="checkbox">
|
|
|
|
<label class="form-check-label">{{ $t("Send Silently") }}</label>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="form-text">
|
|
|
|
{{ $t("telegramSendSilentlyDescription") }}
|
|
|
|
</div>
|
2021-09-08 02:25:03 +00:00
|
|
|
</div>
|
2021-09-07 15:32:05 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import HiddenInput from "../HiddenInput.vue";
|
|
|
|
import axios from "axios";
|
2021-11-03 23:19:04 +00:00
|
|
|
import { useToast } from "vue-toastification";
|
2021-09-07 15:32:05 +00:00
|
|
|
const toast = useToast();
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
HiddenInput,
|
|
|
|
},
|
2021-11-03 23:19:04 +00:00
|
|
|
methods: {
|
2023-01-05 22:55:51 +00:00
|
|
|
/**
|
|
|
|
* Get the URL for telegram updates
|
|
|
|
* @param {string} [mode=masked] Should the token be masked?
|
|
|
|
* @returns {string} formatted URL
|
|
|
|
*/
|
2021-12-05 09:40:13 +00:00
|
|
|
telegramGetUpdatesURL(mode = "masked") {
|
2021-11-03 23:19:04 +00:00
|
|
|
let token = `<${this.$t("YOUR BOT TOKEN HERE")}>`;
|
2021-09-07 15:32:05 +00:00
|
|
|
|
2021-12-05 09:40:13 +00:00
|
|
|
if (this.$parent.notification.telegramBotToken) {
|
|
|
|
if (mode === "withToken") {
|
|
|
|
token = this.$parent.notification.telegramBotToken;
|
|
|
|
} else if (mode === "masked") {
|
|
|
|
token = "*".repeat(this.$parent.notification.telegramBotToken.length);
|
|
|
|
}
|
2021-09-07 15:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return `https://api.telegram.org/bot${token}/getUpdates`;
|
|
|
|
},
|
2023-01-05 22:55:51 +00:00
|
|
|
|
|
|
|
/** Get the telegram chat ID */
|
2021-09-07 15:32:05 +00:00
|
|
|
async autoGetTelegramChatID() {
|
|
|
|
try {
|
2021-12-05 09:40:13 +00:00
|
|
|
let res = await axios.get(this.telegramGetUpdatesURL("withToken"));
|
2021-09-07 15:32:05 +00:00
|
|
|
|
|
|
|
if (res.data.result.length >= 1) {
|
2021-11-03 23:19:04 +00:00
|
|
|
let update = res.data.result[res.data.result.length - 1];
|
2021-09-07 15:32:05 +00:00
|
|
|
|
|
|
|
if (update.channel_post) {
|
2022-02-15 15:30:07 +00:00
|
|
|
this.$parent.notification.telegramChatID = update.channel_post.chat.id;
|
2021-09-07 15:32:05 +00:00
|
|
|
} else if (update.message) {
|
2022-02-15 15:30:07 +00:00
|
|
|
this.$parent.notification.telegramChatID = update.message.chat.id;
|
2021-09-07 15:32:05 +00:00
|
|
|
} else {
|
2021-11-03 23:19:04 +00:00
|
|
|
throw new Error(this.$t("chatIDNotFound"));
|
2021-09-07 15:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2021-11-03 23:19:04 +00:00
|
|
|
throw new Error(this.$t("chatIDNotFound"));
|
2021-09-07 15:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} catch (error) {
|
2021-11-03 23:19:04 +00:00
|
|
|
toast.error(error.message);
|
2021-09-07 15:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
2021-11-03 23:19:04 +00:00
|
|
|
};
|
2021-09-07 15:32:05 +00:00
|
|
|
</script>
|