diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 65ba4e9cd3f..31213dace04 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2565,6 +2565,7 @@ settings.tags.protection.none = There are no protected tags. settings.tags.protection.pattern.description = You can use a single name or a glob pattern or regular expression to match multiple tags. Read more in the protected tags guide. settings.bot_token = Bot Token settings.chat_id = Chat ID +settings.custom_host= Custom Host settings.thread_id = Thread ID settings.matrix.homeserver_url = Homeserver URL settings.matrix.room_id = Room ID diff --git a/routers/web/repo/setting/webhook.go b/routers/web/repo/setting/webhook.go index f1074497493..7e0af0c413c 100644 --- a/routers/web/repo/setting/webhook.go +++ b/routers/web/repo/setting/webhook.go @@ -425,15 +425,19 @@ func TelegramHooksEditPost(ctx *context.Context) { func telegramHookParams(ctx *context.Context) webhookParams { form := web.GetForm(ctx).(*forms.NewTelegramHookForm) + if form.CustomHost == "" { + form.CustomHost = "https://api.telegram.org" + } return webhookParams{ Type: webhook_module.TELEGRAM, - URL: fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage?chat_id=%s&message_thread_id=%s", url.PathEscape(form.BotToken), url.QueryEscape(form.ChatID), url.QueryEscape(form.ThreadID)), + URL: fmt.Sprintf("%s/bot%s/sendMessage?chat_id=%s&message_thread_id=%s", form.CustomHost, url.PathEscape(form.BotToken), url.QueryEscape(form.ChatID), url.QueryEscape(form.ThreadID)), ContentType: webhook.ContentTypeJSON, WebhookForm: form.WebhookForm, Meta: &webhook_service.TelegramMeta{ - BotToken: form.BotToken, - ChatID: form.ChatID, - ThreadID: form.ThreadID, + BotToken: form.BotToken, + ChatID: form.ChatID, + CustomHost: form.CustomHost, + ThreadID: form.ThreadID, }, } } diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index cb267f891cc..54733657b6d 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -334,9 +334,10 @@ func (f *NewDingtalkHookForm) Validate(req *http.Request, errs binding.Errors) b // NewTelegramHookForm form for creating telegram hook type NewTelegramHookForm struct { - BotToken string `binding:"Required"` - ChatID string `binding:"Required"` - ThreadID string + BotToken string `binding:"Required"` + ChatID string `binding:"Required"` + CustomHost string + ThreadID string WebhookForm } diff --git a/services/webhook/telegram.go b/services/webhook/telegram.go index fdd428b45c7..5ce03284d7a 100644 --- a/services/webhook/telegram.go +++ b/services/webhook/telegram.go @@ -30,9 +30,10 @@ type ( // TelegramMeta contains the telegram metadata TelegramMeta struct { - BotToken string `json:"bot_token"` - ChatID string `json:"chat_id"` - ThreadID string `json:"thread_id"` + BotToken string `json:"bot_token"` + ChatID string `json:"chat_id"` + CustomHost string `json:"custom_host"` + ThreadID string `json:"thread_id"` } ) diff --git a/templates/repo/settings/webhook/telegram.tmpl b/templates/repo/settings/webhook/telegram.tmpl index 5ab89b72cc0..6bac5e7dc17 100644 --- a/templates/repo/settings/webhook/telegram.tmpl +++ b/templates/repo/settings/webhook/telegram.tmpl @@ -10,6 +10,10 @@ +
+ + +