Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-24 02:36:10 +01:00

Add ThreadID parameter for Telegram webhooks (#25996) (#26480)

Backport #25996

Telegram has recently implemented threads (channels) for group chats.

Co-authored-by: Earl Warren <109468362+earl-warren@users.noreply.github.com>
Co-authored-by: neveraskedtoexist <matikot415@gmail.com>
(cherry picked from commit acc0fd22d8)
This commit is contained in:
Giteabot 2023-08-14 08:55:17 +08:00 committed by Earl Warren
parent f74522a352
commit d297a87f75
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
5 changed files with 9 additions and 1 deletions

View file

@ -2300,6 +2300,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.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.bot_token = Bot Token
settings.chat_id = Chat ID settings.chat_id = Chat ID
settings.thread_id = Thread ID
settings.matrix.homeserver_url = Homeserver URL settings.matrix.homeserver_url = Homeserver URL
settings.matrix.room_id = Room ID settings.matrix.room_id = Room ID
settings.matrix.message_type = Message Type settings.matrix.message_type = Message Type

View file

@ -453,12 +453,13 @@ func telegramHookParams(ctx *context.Context) webhookParams {
return webhookParams{ return webhookParams{
Type: webhook_module.TELEGRAM, 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, ContentType: webhook.ContentTypeJSON,
WebhookForm: form.WebhookForm, WebhookForm: form.WebhookForm,
Meta: &webhook_service.TelegramMeta{ Meta: &webhook_service.TelegramMeta{
BotToken: form.BotToken, BotToken: form.BotToken,
ChatID: form.ChatID, ChatID: form.ChatID,
ThreadID: form.ThreadID,
}, },
} }
} }

View file

@ -352,6 +352,7 @@ func (f *NewDingtalkHookForm) Validate(req *http.Request, errs binding.Errors) b
type NewTelegramHookForm struct { type NewTelegramHookForm struct {
BotToken string `binding:"Required"` BotToken string `binding:"Required"`
ChatID string `binding:"Required"` ChatID string `binding:"Required"`
ThreadID string
WebhookForm WebhookForm
} }

View file

@ -28,6 +28,7 @@ type (
TelegramMeta struct { TelegramMeta struct {
BotToken string `json:"bot_token"` BotToken string `json:"bot_token"`
ChatID string `json:"chat_id"` ChatID string `json:"chat_id"`
ThreadID string `json:"thread_id"`
} }
) )

View file

@ -10,6 +10,10 @@
<label for="chat_id">{{.locale.Tr "repo.settings.chat_id"}}</label> <label for="chat_id">{{.locale.Tr "repo.settings.chat_id"}}</label>
<input id="chat_id" name="chat_id" type="text" value="{{.TelegramHook.ChatID}}" required> <input id="chat_id" name="chat_id" type="text" value="{{.TelegramHook.ChatID}}" required>
</div> </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" .}} {{template "repo/settings/webhook/settings" .}}
</form> </form>
{{end}} {{end}}