From b0610c02acb2091cc5e08d249785798f0f9749e1 Mon Sep 17 00:00:00 2001
From: RaminMT <RaminMT007@gmail.com>
Date: Fri, 21 Mar 2025 06:38:20 +0330
Subject: [PATCH] Add Telegram custom bot api server support (#5668)

---
 server/notification-providers/telegram.js |  2 +-
 src/components/notifications/Telegram.vue | 20 +++++++++++++++++++-
 src/lang/en.json                          |  2 ++
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/server/notification-providers/telegram.js b/server/notification-providers/telegram.js
index 62263db07..04117e65a 100644
--- a/server/notification-providers/telegram.js
+++ b/server/notification-providers/telegram.js
@@ -9,7 +9,7 @@ class Telegram extends NotificationProvider {
      */
     async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
         const okMsg = "Sent Successfully.";
-        const url = "https://api.telegram.org";
+        const url = notification.telegramServerUrl ?? "https://api.telegram.org";
 
         try {
             let params = {
diff --git a/src/components/notifications/Telegram.vue b/src/components/notifications/Telegram.vue
index 7f04e44c8..145a5c94e 100644
--- a/src/components/notifications/Telegram.vue
+++ b/src/components/notifications/Telegram.vue
@@ -32,6 +32,21 @@
         <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>
+
+        <label for="server_url" class="form-label">{{ $t("telegramServerUrl") }}</label>
+        <input id="server_url" v-model="$parent.notification.telegramServerUrl" type="text" class="form-control">
+        <div class="form-text">
+            <i18n-t keypath="telegramServerUrlDescription">
+                <a
+                    href="https://core.telegram.org/bots/api#using-a-local-bot-api-server"
+                    target="_blank"
+                >{{ $t("here") }}</a>
+                <a
+                    href="https://api.telegram.org"
+                    target="_blank"
+                >https://api.telegram.org</a>
+            </i18n-t>
+        </div>
     </div>
 
     <div class="mb-3">
@@ -111,6 +126,9 @@ Uptime Kuma Alert{% if monitorJSON %} - {{ monitorJSON['name'] }}{% endif %}
             ]);
         }
     },
+    mounted() {
+        this.$parent.notification.telegramServerUrl ||= "https://api.telegram.org";
+    },
     methods: {
         /**
          * Get the URL for telegram updates
@@ -128,7 +146,7 @@ Uptime Kuma Alert{% if monitorJSON %} - {{ monitorJSON['name'] }}{% endif %}
                 }
             }
 
-            return `https://api.telegram.org/bot${token}/getUpdates`;
+            return `${this.$parent.notification.telegramServerUrl}/bot${token}/getUpdates`;
         },
 
         /**
diff --git a/src/lang/en.json b/src/lang/en.json
index c0bf639c8..cb704b0fe 100644
--- a/src/lang/en.json
+++ b/src/lang/en.json
@@ -429,6 +429,8 @@
     "telegramTemplateFormatDescription": "Telegram allows using different markup languages for messages, see Telegram {0} for specifc details.",
     "supportTelegramChatID": "Support Direct Chat / Group / Channel's Chat ID",
     "wayToGetTelegramChatID": "You can get your chat ID by sending a message to the bot and going to this URL to view the chat_id:",
+    "telegramServerUrl": "(Optional) Server Url",
+    "telegramServerUrlDescription": "To lift Telegram's bot api limitations or gain access in blocked areas (China, Iran, etc). For more information click {0}. Default: {1}",
     "YOUR BOT TOKEN HERE": "YOUR BOT TOKEN HERE",
     "chatIDNotFound": "Chat ID is not found; please send a message to this bot first",
     "disableCloudflaredNoAuthMsg": "You are in No Auth mode, a password is not required.",