mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-03 17:04:35 -04:00
Telegram webhook (#4227)
This commit is contained in:
parent
6dbd261852
commit
56da256853
13 changed files with 478 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue