From 56da256853001cf3538b8d4ae99798e084935a90 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Thu, 18 Apr 2019 22:45:02 -0400 Subject: [PATCH] Telegram webhook (#4227) --- models/webhook.go | 18 + models/webhook_telegram.go | 322 ++++++++++++++++++ models/webhook_test.go | 3 + modules/auth/repo_form.go | 12 + modules/setting/webhook.go | 2 +- options/locale/locale_en-US.ini | 3 + public/img/telegram.png | Bin 0 -> 12399 bytes routers/repo/webhook.go | 91 +++++ routers/routes/routes.go | 4 + templates/org/settings/hook_new.tmpl | 3 + templates/repo/settings/webhook/list.tmpl | 3 + templates/repo/settings/webhook/new.tmpl | 3 + templates/repo/settings/webhook/telegram.tmpl | 15 + 13 files changed, 478 insertions(+), 1 deletion(-) create mode 100644 models/webhook_telegram.go create mode 100644 public/img/telegram.png create mode 100644 templates/repo/settings/webhook/telegram.tmpl diff --git a/models/webhook.go b/models/webhook.go index eb22e9597..8db281a15 100644 --- a/models/webhook.go +++ b/models/webhook.go @@ -145,6 +145,15 @@ func (w *Webhook) GetDiscordHook() *DiscordMeta { return s } +// GetTelegramHook returns telegram metadata +func (w *Webhook) GetTelegramHook() *TelegramMeta { + s := &TelegramMeta{} + if err := json.Unmarshal([]byte(w.Meta), s); err != nil { + log.Error("webhook.GetTelegramHook(%d): %v", w.ID, err) + } + return s +} + // History returns history of webhook by given conditions. func (w *Webhook) History(page int) ([]*HookTask, error) { return HookTasks(w.ID, page) @@ -456,6 +465,7 @@ const ( GITEA DISCORD DINGTALK + TELEGRAM ) var hookTaskTypes = map[string]HookTaskType{ @@ -464,6 +474,7 @@ var hookTaskTypes = map[string]HookTaskType{ "slack": SLACK, "discord": DISCORD, "dingtalk": DINGTALK, + "telegram": TELEGRAM, } // ToHookTaskType returns HookTaskType by given name. @@ -484,6 +495,8 @@ func (t HookTaskType) Name() string { return "discord" case DINGTALK: return "dingtalk" + case TELEGRAM: + return "telegram" } return "" } @@ -657,6 +670,11 @@ func prepareWebhook(e Engine, w *Webhook, repo *Repository, event HookEventType, if err != nil { return fmt.Errorf("GetDingtalkPayload: %v", err) } + case TELEGRAM: + payloader, err = GetTelegramPayload(p, event, w.Meta) + if err != nil { + return fmt.Errorf("GetTelegramPayload: %v", err) + } default: p.SetSecret(w.Secret) payloader = p diff --git a/models/webhook_telegram.go b/models/webhook_telegram.go new file mode 100644 index 000000000..5680c48b8 --- /dev/null +++ b/models/webhook_telegram.go @@ -0,0 +1,322 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package models + +import ( + "encoding/json" + "fmt" + "strings" + + "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/markup" + api "code.gitea.io/sdk/gitea" +) + +type ( + // TelegramPayload represents + TelegramPayload struct { + Message string `json:"text"` + ParseMode string `json:"parse_mode"` + } + + // TelegramMeta contains the telegram metadata + TelegramMeta struct { + BotToken string `json:"bot_token"` + ChatID string `json:"chat_id"` + } +) + +// SetSecret sets the telegram secret +func (p *TelegramPayload) SetSecret(_ string) {} + +// JSONPayload Marshals the TelegramPayload to json +func (p *TelegramPayload) JSONPayload() ([]byte, error) { + p.ParseMode = "HTML" + p.Message = markup.Sanitize(p.Message) + data, err := json.MarshalIndent(p, "", " ") + if err != nil { + return []byte{}, err + } + return data, nil +} + +func getTelegramCreatePayload(p *api.CreatePayload) (*TelegramPayload, error) { + // created tag/branch + refName := git.RefEndName(p.Ref) + title := fmt.Sprintf(`[%s] %s %s created`, p.Repo.HTMLURL, p.Repo.FullName, p.RefType, + p.Repo.HTMLURL+"/src/"+refName, refName) + + return &TelegramPayload{ + Message: title, + }, nil +} + +func getTelegramDeletePayload(p *api.DeletePayload) (*TelegramPayload, error) { + // created tag/branch + refName := git.RefEndName(p.Ref) + title := fmt.Sprintf(`[%s] %s %s deleted`, p.Repo.HTMLURL, p.Repo.FullName, p.RefType, + p.Repo.HTMLURL+"/src/"+refName, refName) + + return &TelegramPayload{ + Message: title, + }, nil +} + +func getTelegramForkPayload(p *api.ForkPayload) (*TelegramPayload, error) { + title := fmt.Sprintf(`%s is forked to %s`, p.Forkee.FullName, p.Repo.HTMLURL, p.Repo.FullName) + + return &TelegramPayload{ + Message: title, + }, nil +} + +func getTelegramPushPayload(p *api.PushPayload) (*TelegramPayload, error) { + var ( + branchName = git.RefEndName(p.Ref) + commitDesc string + ) + + var titleLink string + if len(p.Commits) == 1 { + commitDesc = "1 new commit" + titleLink = p.Commits[0].URL + } else { + commitDesc = fmt.Sprintf("%d new commits", len(p.Commits)) + titleLink = p.CompareURL + } + if titleLink == "" { + titleLink = p.Repo.HTMLURL + "/src/" + branchName + } + title := fmt.Sprintf(`[%s:%s] %s`, p.Repo.HTMLURL, p.Repo.FullName, titleLink, branchName, commitDesc) + + var text string + // for each commit, generate attachment text + for i, commit := range p.Commits { + var authorName string + if commit.Author != nil { + authorName = " - " + commit.Author.Name + } + text += fmt.Sprintf(`[%s] %s`, commit.URL, commit.ID[:7], + strings.TrimRight(commit.Message, "\r\n")) + authorName + // add linebreak to each commit but the last + if i < len(p.Commits)-1 { + text += "\n" + } + } + + return &TelegramPayload{ + Message: title + "\n" + text, + }, nil +} + +func getTelegramIssuesPayload(p *api.IssuePayload) (*TelegramPayload, error) { + var text, title string + switch p.Action { + case api.HookIssueOpened: + title = fmt.Sprintf(`[%s] Issue opened: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.Issue.URL, p.Index, p.Issue.Title) + text = p.Issue.Body + case api.HookIssueClosed: + title = fmt.Sprintf(`[%s] Issue closed: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.Issue.URL, p.Index, p.Issue.Title) + text = p.Issue.Body + case api.HookIssueReOpened: + title = fmt.Sprintf(`[%s] Issue re-opened: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.Issue.URL, p.Index, p.Issue.Title) + text = p.Issue.Body + case api.HookIssueEdited: + title = fmt.Sprintf(`[%s] Issue edited: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.Issue.URL, p.Index, p.Issue.Title) + text = p.Issue.Body + case api.HookIssueAssigned: + title = fmt.Sprintf(`[%s] Issue assigned to %s: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.Issue.Assignee.UserName, p.Issue.URL, p.Index, p.Issue.Title) + text = p.Issue.Body + case api.HookIssueUnassigned: + title = fmt.Sprintf(`[%s] Issue unassigned: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.Issue.URL, p.Index, p.Issue.Title) + text = p.Issue.Body + case api.HookIssueLabelUpdated: + title = fmt.Sprintf(`[%s] Issue labels updated: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.Issue.URL, p.Index, p.Issue.Title) + text = p.Issue.Body + case api.HookIssueLabelCleared: + title = fmt.Sprintf(`[%s] Issue labels cleared: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.Issue.URL, p.Index, p.Issue.Title) + text = p.Issue.Body + case api.HookIssueSynchronized: + title = fmt.Sprintf(`[%s] Issue synchronized: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.Issue.URL, p.Index, p.Issue.Title) + text = p.Issue.Body + case api.HookIssueMilestoned: + title = fmt.Sprintf(`[%s] Issue milestone: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.Issue.URL, p.Index, p.Issue.Title) + text = p.Issue.Body + case api.HookIssueDemilestoned: + title = fmt.Sprintf(`[%s] Issue clear milestone: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.Issue.URL, p.Index, p.Issue.Title) + text = p.Issue.Body + } + + return &TelegramPayload{ + Message: title + "\n\n" + text, + }, nil +} + +func getTelegramIssueCommentPayload(p *api.IssueCommentPayload) (*TelegramPayload, error) { + url := fmt.Sprintf("%s/issues/%d#%s", p.Repository.HTMLURL, p.Issue.Index, CommentHashTag(p.Comment.ID)) + title := fmt.Sprintf(`#%d %s`, url, p.Issue.Index, p.Issue.Title) + var text string + switch p.Action { + case api.HookIssueCommentCreated: + text = "New comment: " + title + text += p.Comment.Body + case api.HookIssueCommentEdited: + text = "Comment edited: " + title + text += p.Comment.Body + case api.HookIssueCommentDeleted: + text = "Comment deleted: " + title + text += p.Comment.Body + } + + return &TelegramPayload{ + Message: title + "\n" + text, + }, nil +} + +func getTelegramPullRequestPayload(p *api.PullRequestPayload) (*TelegramPayload, error) { + var text, title string + switch p.Action { + case api.HookIssueOpened: + title = fmt.Sprintf(`[%s] Pull request opened: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + text = p.PullRequest.Body + case api.HookIssueClosed: + if p.PullRequest.HasMerged { + title = fmt.Sprintf(`[%s] Pull request merged: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + } else { + title = fmt.Sprintf(`[%s] Pull request closed: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + } + text = p.PullRequest.Body + case api.HookIssueReOpened: + title = fmt.Sprintf(`[%s] Pull request re-opened: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + text = p.PullRequest.Body + case api.HookIssueEdited: + title = fmt.Sprintf(`[%s] Pull request edited: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + text = p.PullRequest.Body + case api.HookIssueAssigned: + list, err := MakeAssigneeList(&Issue{ID: p.PullRequest.ID}) + if err != nil { + return &TelegramPayload{}, err + } + title = fmt.Sprintf(`[%s] Pull request assigned to %s: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + list, p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + text = p.PullRequest.Body + case api.HookIssueUnassigned: + title = fmt.Sprintf(`[%s] Pull request unassigned: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + text = p.PullRequest.Body + case api.HookIssueLabelUpdated: + title = fmt.Sprintf(`[%s] Pull request labels updated: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + text = p.PullRequest.Body + case api.HookIssueLabelCleared: + title = fmt.Sprintf(`[%s] Pull request labels cleared: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + text = p.PullRequest.Body + case api.HookIssueSynchronized: + title = fmt.Sprintf(`[%s] Pull request synchronized: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + text = p.PullRequest.Body + case api.HookIssueMilestoned: + title = fmt.Sprintf(`[%s] Pull request milestone: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + text = p.PullRequest.Body + case api.HookIssueDemilestoned: + title = fmt.Sprintf(`[%s] Pull request clear milestone: #%d %s`, p.Repository.HTMLURL, p.Repository.FullName, + p.PullRequest.HTMLURL, p.Index, p.PullRequest.Title) + text = p.PullRequest.Body + } + + return &TelegramPayload{ + Message: title + "\n" + text, + }, nil +} + +func getTelegramRepositoryPayload(p *api.RepositoryPayload) (*TelegramPayload, error) { + var title string + switch p.Action { + case api.HookRepoCreated: + title = fmt.Sprintf(`[%s] Repository created`, p.Repository.HTMLURL, p.Repository.FullName) + return &TelegramPayload{ + Message: title, + }, nil + case api.HookRepoDeleted: + title = fmt.Sprintf("[%s] Repository deleted", p.Repository.FullName) + return &TelegramPayload{ + Message: title, + }, nil + } + return nil, nil +} + +func getTelegramReleasePayload(p *api.ReleasePayload) (*TelegramPayload, error) { + var title, url string + switch p.Action { + case api.HookReleasePublished: + title = fmt.Sprintf("[%s] Release created", p.Release.TagName) + url = p.Release.URL + return &TelegramPayload{ + Message: title + "\n" + url, + }, nil + case api.HookReleaseUpdated: + title = fmt.Sprintf("[%s] Release updated", p.Release.TagName) + url = p.Release.URL + return &TelegramPayload{ + Message: title + "\n" + url, + }, nil + + case api.HookReleaseDeleted: + title = fmt.Sprintf("[%s] Release deleted", p.Release.TagName) + url = p.Release.URL + return &TelegramPayload{ + Message: title + "\n" + url, + }, nil + } + + return nil, nil +} + +// GetTelegramPayload converts a telegram webhook into a TelegramPayload +func GetTelegramPayload(p api.Payloader, event HookEventType, meta string) (*TelegramPayload, error) { + s := new(TelegramPayload) + + switch event { + case HookEventCreate: + return getTelegramCreatePayload(p.(*api.CreatePayload)) + case HookEventDelete: + return getTelegramDeletePayload(p.(*api.DeletePayload)) + case HookEventFork: + return getTelegramForkPayload(p.(*api.ForkPayload)) + case HookEventIssues: + return getTelegramIssuesPayload(p.(*api.IssuePayload)) + case HookEventIssueComment: + return getTelegramIssueCommentPayload(p.(*api.IssueCommentPayload)) + case HookEventPush: + return getTelegramPushPayload(p.(*api.PushPayload)) + case HookEventPullRequest: + return getTelegramPullRequestPayload(p.(*api.PullRequestPayload)) + case HookEventRepository: + return getTelegramRepositoryPayload(p.(*api.RepositoryPayload)) + case HookEventRelease: + return getTelegramReleasePayload(p.(*api.ReleasePayload)) + } + + return s, nil +} diff --git a/models/webhook_test.go b/models/webhook_test.go index 50106a379..518be8be8 100644 --- a/models/webhook_test.go +++ b/models/webhook_test.go @@ -197,18 +197,21 @@ func TestToHookTaskType(t *testing.T) { assert.Equal(t, GOGS, ToHookTaskType("gogs")) assert.Equal(t, SLACK, ToHookTaskType("slack")) assert.Equal(t, GITEA, ToHookTaskType("gitea")) + assert.Equal(t, TELEGRAM, ToHookTaskType("telegram")) } func TestHookTaskType_Name(t *testing.T) { assert.Equal(t, "gogs", GOGS.Name()) assert.Equal(t, "slack", SLACK.Name()) assert.Equal(t, "gitea", GITEA.Name()) + assert.Equal(t, "telegram", TELEGRAM.Name()) } func TestIsValidHookTaskType(t *testing.T) { assert.True(t, IsValidHookTaskType("gogs")) assert.True(t, IsValidHookTaskType("slack")) assert.True(t, IsValidHookTaskType("gitea")) + assert.True(t, IsValidHookTaskType("telegram")) assert.False(t, IsValidHookTaskType("invalid")) } diff --git a/modules/auth/repo_form.go b/modules/auth/repo_form.go index 990a94dd6..d37a5b94d 100644 --- a/modules/auth/repo_form.go +++ b/modules/auth/repo_form.go @@ -263,6 +263,18 @@ func (f *NewDingtalkHookForm) Validate(ctx *macaron.Context, errs binding.Errors return validate(errs, ctx.Data, f, ctx.Locale) } +// NewTelegramHookForm form for creating telegram hook +type NewTelegramHookForm struct { + BotToken string `binding:"Required"` + ChatID string `binding:"Required"` + WebhookForm +} + +// Validate validates the fields +func (f *NewTelegramHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { + return validate(errs, ctx.Data, f, ctx.Locale) +} + // .___ // | | ______ ________ __ ____ // | |/ ___// ___/ | \_/ __ \ diff --git a/modules/setting/webhook.go b/modules/setting/webhook.go index 741963e54..0d91e7d9e 100644 --- a/modules/setting/webhook.go +++ b/modules/setting/webhook.go @@ -25,6 +25,6 @@ func newWebhookService() { Webhook.QueueLength = sec.Key("QUEUE_LENGTH").MustInt(1000) Webhook.DeliverTimeout = sec.Key("DELIVER_TIMEOUT").MustInt(5) Webhook.SkipTLSVerify = sec.Key("SKIP_TLS_VERIFY").MustBool() - Webhook.Types = []string{"gitea", "gogs", "slack", "discord", "dingtalk"} + Webhook.Types = []string{"gitea", "gogs", "slack", "discord", "dingtalk", "telegram"} Webhook.PagingNum = sec.Key("PAGING_NUM").MustInt(10) } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index b53a72da9..5c391cf56 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1211,6 +1211,7 @@ settings.slack_domain = Domain settings.slack_channel = Channel settings.add_discord_hook_desc = Integrate Discord into your repository. settings.add_dingtalk_hook_desc = Integrate Dingtalk into your repository. +settings.add_telegram_hook_desc = Integrate Telegram into your repository. settings.deploy_keys = Deploy Keys settings.add_deploy_key = Add Deploy Key settings.deploy_key_desc = Deploy keys have read-only pull access to the repository. @@ -1258,6 +1259,8 @@ settings.choose_branch = Choose a branch… settings.no_protected_branch = There are no protected branches. settings.edit_protected_branch = Edit settings.protected_branch_required_approvals_min = Required approvals cannot be negative. +settings.bot_token = Bot Token +settings.chat_id = Chat ID settings.archive.button = Archive Repo settings.archive.header = Archive This Repo settings.archive.text = Archiving the repo will make it entirely read-only. It is hidden from the dashboard, cannot be committed to and no issues or pull-requests can be created. diff --git a/public/img/telegram.png b/public/img/telegram.png new file mode 100644 index 0000000000000000000000000000000000000000..ee0756db5e5f4ab4742c125e3e72bf41e2c246b3 GIT binary patch literal 12399 zcmaKTWmFv9wk-sAf;$8P1b252?$&6d-82@Q;1D1{0s(@%J2cQuAXwu8LU8Ng8Z2mV z!s9#Vo_pVq`(BMvwPma|*W7#0T5Hsgiqq3kBfzD>ML|I!P=Bp#@YEjub7NyZJ^iOO z$etQ%9~CnnLk}k(f1sBmih_fOogVL(08p$w&e0)45`S|?({dxU`cs;zF`2-{+B>uq=6y$lb;PDQ0_W=g* zxO=nw2SM4<+ujT8=>zs~XZi;bXy@VUBg6c}^xsQx^ZajEckln&rl$?#3jliZ3Gnj& zv!wqRYHR=hP2Jr7+uGa5!0~_h{;$B^MuDD=d!ANL^`xGEy8kWPr@?;<-_iX^?Oso^PHxj9MM2@-R999o3P2v_;d#={ zW>r2;3#HV?@>sOE0_|x@kFzr~#ZP12^_!FIrikDH6UZ#|TqWcixG#v0#vnFmMF|OeY-ywJQ<8aJTBO$wy)K#mP(J?fI9;*( z@GF0hdTjI2YDkC%UYhm${LiEG3{r%Fz*M|_U1%4kn#Ix;@&dBwK&9rtH2<6q zODH(0?A_U2&fHhYmGO$&T8C&%ue?y#p+<%7m7+xA%Od9O*ywNf31wP=tT%gPi8^#L z;+StbN*I&&=FLassTSH&wconFCj>&Yo?{ifwlnPS;YhLh@k)`cmj+Gzw)ArYJM|FxTUS-YzP;^WA=!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~N=&XxvRiMvOl*&W1t*xcbDqH0E**h?CEvpM>t%S(h0p`m7hBreqLS$ya1^_cC(;29R|AjK-x~k>d;+OVLE-GBwfw7WDY+1Z z^EIajtIM4d1(t=rw+W-g5bR|sBy6&yk!pRa?`8HeecLy}p1wO?;$cLKm zWhm!-i)0{Rd5OQNK)j)H|D#!)cUQt9Rq*|$buKO6en>ti!%X!Aba50WKFUt^!T*JL^)8791?6#$$&_fds=Xd|< zt3=WKgS3$7H+p_+3g|*#8?@oq)$kJFG}z*&bo@kE%Iymqd=p^_#CaF9Bc<8oYIl5g zcezM4_1r#|DC*Mdjx0LFd}Yai3slkqUkHu7NZ&t_T<;dIBPQ?7DQ*q6qRFHB$$Wo> z(S(cVuvR*zEN+JtHR=m=-dFctB! z#pI(3Nt9%<7EMMr;S77H2x)SFH7!oVJ%*&tJD zV>sLeiQm_7(M^zRxRX(jGNqUZ5%HG2AqrV=y<^f>9D}#28fkz87d^~05!bFY0MtNK z!3;1T&rR9^!`*TWR(weLveBBg?u)*sNi*};LA<0rQ>X&pwTFh%L2Fur6y5+tqf-p1 z(g_rk_2?g}5k{aNSJTLOlWm6()UvwsRYZM;bD&u`1eA$}OrPdQ!7hFxW-l)(^n vEAlp}566=YG7(^#nrMG&^0ylW4TbPk|8GCu-**4}0-&y {{else if eq .HookType "dingtalk"}} + {{else if eq .HookType "telegram"}} + {{end}} @@ -28,6 +30,7 @@ {{template "repo/settings/webhook/slack" .}} {{template "repo/settings/webhook/discord" .}} {{template "repo/settings/webhook/dingtalk" .}} + {{template "repo/settings/webhook/telegram" .}} {{template "repo/settings/webhook/history" .}} diff --git a/templates/repo/settings/webhook/list.tmpl b/templates/repo/settings/webhook/list.tmpl index d2985c367..ddba0f863 100644 --- a/templates/repo/settings/webhook/list.tmpl +++ b/templates/repo/settings/webhook/list.tmpl @@ -20,6 +20,9 @@ Dingtalk + + Telegram + diff --git a/templates/repo/settings/webhook/new.tmpl b/templates/repo/settings/webhook/new.tmpl index 1b3d11457..8c8b3280e 100644 --- a/templates/repo/settings/webhook/new.tmpl +++ b/templates/repo/settings/webhook/new.tmpl @@ -17,6 +17,8 @@ {{else if eq .HookType "dingtalk"}} + {{else if eq .HookType "telegram"}} + {{end}} @@ -26,6 +28,7 @@ {{template "repo/settings/webhook/slack" .}} {{template "repo/settings/webhook/discord" .}} {{template "repo/settings/webhook/dingtalk" .}} + {{template "repo/settings/webhook/telegram" .}} {{template "repo/settings/webhook/history" .}} diff --git a/templates/repo/settings/webhook/telegram.tmpl b/templates/repo/settings/webhook/telegram.tmpl new file mode 100644 index 000000000..598ac4482 --- /dev/null +++ b/templates/repo/settings/webhook/telegram.tmpl @@ -0,0 +1,15 @@ +{{if eq .HookType "telegram"}} +

{{.i18n.Tr "repo.settings.add_telegram_hook_desc" "https://core.telegram.org/bots" | Str2html}}

+
+ {{.CsrfTokenHtml}} +
+ + +
+
+ + +
+ {{template "repo/settings/webhook/settings" .}} +
+{{end}}