Skip to content

Commit 50fc22e

Browse files
earl-warrenneveraskedtoexist
and
neveraskedtoexist
authored
Add ThreadID parameter for Telegram webhooks (#25996)
Telegram has recently implemented threads (channels) for group chats. Co-authored-by: neveraskedtoexist <[email protected]>
1 parent 82ea557 commit 50fc22e

File tree

5 files changed

+9
-1
lines changed

5 files changed

+9
-1
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,6 +2314,7 @@ settings.tags.protection.none = There are no protected tags.
23142314
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.io/en-us/protected-tags/">protected tags guide</a>.
23152315
settings.bot_token = Bot Token
23162316
settings.chat_id = Chat ID
2317+
settings.thread_id = Thread ID
23172318
settings.matrix.homeserver_url = Homeserver URL
23182319
settings.matrix.room_id = Room ID
23192320
settings.matrix.message_type = Message Type

routers/web/repo/setting/webhook.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,13 @@ func telegramHookParams(ctx *context.Context) webhookParams {
425425

426426
return webhookParams{
427427
Type: webhook_module.TELEGRAM,
428-
URL: fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage?chat_id=%s", url.PathEscape(form.BotToken), url.QueryEscape(form.ChatID)),
428+
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)),
429429
ContentType: webhook.ContentTypeJSON,
430430
WebhookForm: form.WebhookForm,
431431
Meta: &webhook_service.TelegramMeta{
432432
BotToken: form.BotToken,
433433
ChatID: form.ChatID,
434+
ThreadID: form.ThreadID,
434435
},
435436
}
436437
}

services/forms/repo_form.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ func (f *NewDingtalkHookForm) Validate(req *http.Request, errs binding.Errors) b
353353
type NewTelegramHookForm struct {
354354
BotToken string `binding:"Required"`
355355
ChatID string `binding:"Required"`
356+
ThreadID string
356357
WebhookForm
357358
}
358359

services/webhook/telegram.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type (
2828
TelegramMeta struct {
2929
BotToken string `json:"bot_token"`
3030
ChatID string `json:"chat_id"`
31+
ThreadID string `json:"thread_id"`
3132
}
3233
)
3334

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">{{.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_ThreadID}}error{{end}}">
14+
<label for="thread_id">{{.locale.Tr "repo.settings.thread_id"}}</label>
15+
<input id="thread_id" name="thread_id" type="text" value="{{.TelegramHook.ThreadID}}">
16+
</div>
1317
{{template "repo/settings/webhook/settings" .}}
1418
</form>
1519
{{end}}

0 commit comments

Comments
 (0)