Skip to content

Commit a0e90c2

Browse files
committed
新增对Telegram 自定义代理域名的设置
Added support for custom Telegram proxy domain names
1 parent c72e1a7 commit a0e90c2

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,6 +2433,7 @@ settings.tags.protection.none = There are no protected tags.
24332433
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 <a target="_blank" rel="noopener" href="https://docs.gitea.com/usage/protected-tags">protected tags guide</a>.
24342434
settings.bot_token = Bot Token
24352435
settings.chat_id = Chat ID
2436+
settings.custom_domain= Custom Domain
24362437
settings.thread_id = Thread ID
24372438
settings.matrix.homeserver_url = Homeserver URL
24382439
settings.matrix.room_id = Room ID

routers/web/repo/setting/webhook.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,15 +425,19 @@ func TelegramHooksEditPost(ctx *context.Context) {
425425
func telegramHookParams(ctx *context.Context) webhookParams {
426426
form := web.GetForm(ctx).(*forms.NewTelegramHookForm)
427427

428+
if form.CustomDomain == "" {
429+
form.CustomDomain = "api.telegram.org"
430+
}
428431
return webhookParams{
429432
Type: webhook_module.TELEGRAM,
430-
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)),
433+
URL: fmt.Sprintf("https://%s/bot%s/sendMessage?chat_id=%s&message_thread_id=%s", url.PathEscape(form.CustomDomain), url.PathEscape(form.BotToken), url.QueryEscape(form.ChatID), url.QueryEscape(form.ThreadID)),
431434
ContentType: webhook.ContentTypeJSON,
432435
WebhookForm: form.WebhookForm,
433436
Meta: &webhook_service.TelegramMeta{
434-
BotToken: form.BotToken,
435-
ChatID: form.ChatID,
436-
ThreadID: form.ThreadID,
437+
BotToken: form.BotToken,
438+
ChatID: form.ChatID,
439+
CustomDomain: form.CustomDomain,
440+
ThreadID: form.ThreadID,
437441
},
438442
}
439443
}

services/forms/repo_form.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,10 @@ func (f *NewDingtalkHookForm) Validate(req *http.Request, errs binding.Errors) b
350350

351351
// NewTelegramHookForm form for creating telegram hook
352352
type NewTelegramHookForm struct {
353-
BotToken string `binding:"Required"`
354-
ChatID string `binding:"Required"`
355-
ThreadID string
353+
BotToken string `binding:"Required"`
354+
ChatID string `binding:"Required"`
355+
CustomDomain string
356+
ThreadID string
356357
WebhookForm
357358
}
358359

services/webhook/telegram.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ type (
2626

2727
// TelegramMeta contains the telegram metadata
2828
TelegramMeta struct {
29-
BotToken string `json:"bot_token"`
30-
ChatID string `json:"chat_id"`
31-
ThreadID string `json:"thread_id"`
29+
BotToken string `json:"bot_token"`
30+
ChatID string `json:"chat_id"`
31+
CustomDomain string `json:"custom_domain"`
32+
ThreadID string `json:"thread_id"`
3233
}
3334
)
3435

templates/repo/settings/webhook/telegram.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
<label for="chat_id">{{ctx.Locale.Tr "repo.settings.chat_id"}}</label>
1111
<input id="chat_id" name="chat_id" type="text" value="{{.TelegramHook.ChatID}}" required>
1212
</div>
13+
<div class="field {{if .Err_CustomDomain}}error{{end}}">
14+
<label for="custom_domain">{{ctx.Locale.Tr "repo.settings.custom_domain"}}</label>
15+
<input id="custom_domain" name="custom_domain" type="text" value="{{.TelegramHook.CustomDomain}}" placeholder="api.telegram.org">
16+
</div>
1317
<div class="field {{if .Err_ThreadID}}error{{end}}">
1418
<label for="thread_id">{{ctx.Locale.Tr "repo.settings.thread_id"}}</label>
1519
<input id="thread_id" name="thread_id" type="text" value="{{.TelegramHook.ThreadID}}">

0 commit comments

Comments
 (0)