-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathbase.go
131 lines (108 loc) · 3.49 KB
/
base.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package dingtalk
import "time"
type msgTypeType string
const (
TEXT msgTypeType = "text"
LINK msgTypeType = "link"
MARKDOWN msgTypeType = "markdown"
ACTION_CARD msgTypeType = "actionCard"
FEED_CARD msgTypeType = "feedCard"
)
type initModel struct {
InitSendTimeout time.Duration
}
func (i initModel) GetSendTimeout() time.Duration {
if i.InitSendTimeout > 0 {
return i.InitSendTimeout
}
return time.Second * 2
}
type initOption interface {
applyInit(model *initModel)
}
type funcInitOption struct {
f func(model *initModel)
}
func (fdo *funcInitOption) applyInit(do *initModel) {
fdo.f(do)
}
func newFuncInitOption(f func(model *initModel)) *funcInitOption {
return &funcInitOption{f: f}
}
func WithInitSendTimeout(v time.Duration) initOption {
return newFuncInitOption(func(o *initModel) {
o.InitSendTimeout = v
})
}
type DingTalk struct {
robotToken []string
secret string
keyWord string
InitModel initModel
}
type textModel struct {
Content string `json:"content,omitempty"`
}
type atModel struct {
AtMobiles []string `json:"atMobiles,omitempty"`
AtUserIds []string `json:"atUserIds,omitempty"`
IsAtAll bool `json:"isAtAll,omitempty"`
}
type linkModel struct {
Text string `json:"text,omitempty"`
Title string `json:"title,omitempty"`
PicUrl string `json:"picUrl,omitempty"`
MessageUrl string `json:"messageUrl,omitempty"`
}
type markDownModel struct {
Title string `json:"title,omitempty"`
Text string `json:"text,omitempty"`
}
type actionCardBtnOrientationType string
const (
horizontal actionCardBtnOrientationType = "0" // 横向
vertical actionCardBtnOrientationType = "1" // 竖向
)
type actionCardModel struct {
Title string `json:"title,omitempty"`
Text string `json:"text,omitempty"`
BtnOrientation actionCardBtnOrientationType `json:"btnOrientation,omitempty"`
SingleTitle string `json:"singleTitle,omitempty"`
SingleURL string `json:"singleURL,omitempty"`
Btns []ActionCardMultiBtnModel `json:"btns,omitempty"`
}
type ActionCardMultiBtnModel struct {
Title string `json:"title,omitempty"`
ActionURL string `json:"actionURL,omitempty"`
}
type feedCardModel struct {
Links []FeedCardLinkModel `json:"links,omitempty"`
}
type FeedCardLinkModel struct {
Title string `json:"title,omitempty"`
MessageURL string `json:"messageURL,omitempty"`
PicURL string `json:"picURL,omitempty"`
}
type outGoingModel struct {
AtUsers []struct {
DingtalkID string `json:"dingtalkId"`
} `json:"atUsers"`
ChatbotUserID string `json:"chatbotUserId"`
ConversationID string `json:"conversationId"`
ConversationTitle string `json:"conversationTitle"`
ConversationType string `json:"conversationType"`
CreateAt int64 `json:"createAt"`
IsAdmin bool `json:"isAdmin"`
IsInAtList bool `json:"isInAtList"`
MsgID string `json:"msgId"`
Msgtype string `json:"msgtype"`
SceneGroupCode string `json:"sceneGroupCode"`
SenderID string `json:"senderId"`
SenderNick string `json:"senderNick"`
SessionWebhook string `json:"sessionWebhook"`
SessionWebhookExpiredTime int64 `json:"sessionWebhookExpiredTime"`
Text struct {
Content string `json:"content"`
} `json:"text"`
}
type ExecFunc func(args []string) []byte