Skip to content

Commit

Permalink
Add ThreadID parameter for Telegram webhooks (#25996)
Browse files Browse the repository at this point in the history
Telegram has recently implemented threads (channels) for group chats.

Co-authored-by: neveraskedtoexist <matikot415@gmail.com>
  • Loading branch information
earl-warren and neveraskedtoexist authored Aug 13, 2023
1 parent 82ea557 commit 50fc22e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2314,6 +2314,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 <a target="_blank" rel="noopener" href="https://docs.gitea.io/en-us/protected-tags/">protected tags guide</a>.
settings.bot_token = Bot Token
settings.chat_id = Chat ID
settings.thread_id = Thread ID
settings.matrix.homeserver_url = Homeserver URL
settings.matrix.room_id = Room ID
settings.matrix.message_type = Message Type
Expand Down
3 changes: 2 additions & 1 deletion routers/web/repo/setting/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,13 @@ func telegramHookParams(ctx *context.Context) webhookParams {

return webhookParams{
Type: webhook_module.TELEGRAM,
URL: fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage?chat_id=%s", url.PathEscape(form.BotToken), url.QueryEscape(form.ChatID)),
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)),
ContentType: webhook.ContentTypeJSON,
WebhookForm: form.WebhookForm,
Meta: &webhook_service.TelegramMeta{
BotToken: form.BotToken,
ChatID: form.ChatID,
ThreadID: form.ThreadID,
},
}
}
Expand Down
1 change: 1 addition & 0 deletions services/forms/repo_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ func (f *NewDingtalkHookForm) Validate(req *http.Request, errs binding.Errors) b
type NewTelegramHookForm struct {
BotToken string `binding:"Required"`
ChatID string `binding:"Required"`
ThreadID string
WebhookForm
}

Expand Down
1 change: 1 addition & 0 deletions services/webhook/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type (
TelegramMeta struct {
BotToken string `json:"bot_token"`
ChatID string `json:"chat_id"`
ThreadID string `json:"thread_id"`
}
)

Expand Down
4 changes: 4 additions & 0 deletions templates/repo/settings/webhook/telegram.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<label for="chat_id">{{.locale.Tr "repo.settings.chat_id"}}</label>
<input id="chat_id" name="chat_id" type="text" value="{{.TelegramHook.ChatID}}" required>
</div>
<div class="field {{if .Err_ThreadID}}error{{end}}">
<label for="thread_id">{{.locale.Tr "repo.settings.thread_id"}}</label>
<input id="thread_id" name="thread_id" type="text" value="{{.TelegramHook.ThreadID}}">
</div>
{{template "repo/settings/webhook/settings" .}}
</form>
{{end}}

0 comments on commit 50fc22e

Please sign in to comment.