feat(webhook): support Telegram Bot API 10.1 Rich Messages (#38298)

Upgrades Gitea's Telegram webhook integration to support Telegram Bot
API 10.1 (June 2026 release). This enables Gitea webhooks to take
advantage of rich formatted messages (tables, nested blocks, collapsible
details, etc.) by routing them through the /sendRichMessage endpoint
with the new rich_message payload structure.

Old `/sendMessage` webhook URLs are written to `/sendRichMessage`
at runtime to prevent the need for database migrations

Fixes https://github.com/go-gitea/gitea/issues/38118

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Shudhanshu Singh
2026-07-02 20:44:48 +05:30
committed by GitHub
parent c6184ed184
commit b09920a537
3 changed files with 41 additions and 29 deletions
+18 -6
View File
@@ -8,6 +8,7 @@ import (
"fmt"
"html"
"net/http"
"net/url"
"strings"
webhook_model "gitea.dev/models/webhook"
@@ -23,9 +24,12 @@ import (
type (
// TelegramPayload represents
TelegramPayload struct {
Message string `json:"text"`
ParseMode string `json:"parse_mode"`
DisableWebPreview bool `json:"disable_web_page_preview"`
RichMessage InputRichMessage `json:"rich_message"`
}
// InputRichMessage represents input rich message
InputRichMessage struct {
HTML string `json:"html"`
}
// TelegramMeta contains the telegram metadata
@@ -195,13 +199,21 @@ func (telegramConvertor) WorkflowJob(p *api.WorkflowJobPayload) (TelegramPayload
func createTelegramPayloadHTML(msgHTML string) TelegramPayload {
// https://core.telegram.org/bots/api#formatting-options
return TelegramPayload{
Message: strings.TrimSpace(string(markup.Sanitize(msgHTML))),
ParseMode: "HTML",
DisableWebPreview: true,
RichMessage: InputRichMessage{
HTML: strings.TrimSpace(string(markup.Sanitize(msgHTML))),
},
}
}
func newTelegramRequest(_ context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) {
u, err := url.Parse(w.URL)
if err != nil {
return nil, nil, err
}
if urlPrefix, ok := strings.CutSuffix(u.Path, "/sendMessage"); ok {
u.Path = urlPrefix + "/sendRichMessage"
w.URL = u.String()
}
var pc payloadConvertor[TelegramPayload] = telegramConvertor{}
return newJSONRequest(pc, w, t, true)
}