This repository has been archived by the owner on Sep 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
hook.go
50 lines (42 loc) · 1.45 KB
/
hook.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package tat
import (
"fmt"
)
var HookTat2XMPPHeaderKey = "Tat2xmppkey"
// HookMessageJSON represents a json sent to an external system, for a event about a message
type HookMessageJSON struct {
Action string `json:"action"`
MessageJSONOut *MessageJSONOut `json:"message"`
}
// HookJSON represents a json sent to an external system
type HookJSON struct {
Hook Hook `json:"hook"`
HookMessage *HookMessageJSON `json:"hookMessage"`
Username string `json:"username"`
}
var HooksType = []string{HookTypeWebHook, HookTypeKafka, HookTypeXMPP, HookTypeXMPPOut, HookTypeXMPPIn}
var (
HookTypeWebHook = "tathook-webhook"
HookTypeKafka = "tathook-kafka"
HookTypeXMPP = "tathook-xmpp"
HookTypeXMPPOut = "tathook-xmpp-out"
HookTypeXMPPIn = "tathook-xmpp-in"
)
type Hook struct {
ID string `bson:"_id" json:"_id"`
Type string `bson:"type" json:"type"` // in HooksType
Destination string `bson:"destination" json:"destination"`
Errors int `bson:"errors" json:"errors"`
Enabled bool `bson:"enabled" json:"enabled"`
Item string `json:"item"` // only "message" for now
Action string `json:"action"` // MessageActionVoteup, MessageActionCreate, etc...
}
func checkHook(h Hook) error {
if !ArrayContains(HooksType, h.Type) {
return fmt.Errorf("Invalid Hook type: %s", h.Type)
}
if h.Destination == "" {
return fmt.Errorf("Invalid hook, destination is empty")
}
return nil
}