forked from slack-go/slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
external.go
59 lines (54 loc) · 1.42 KB
/
external.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
package slack
import (
"encoding/json"
"errors"
"github.com/artemlive/slack/slackevents"
)
type ExternalRequest struct {
Name string `json:"name"`
Value string `json:"value"`
CallbackID string `json:"callback_id"`
Type string `json:"type"`
Team struct {
ID string `json:"id"`
Domain string `json:"domain"`
} `json:"team"`
Channel struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"channel"`
User struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"user"`
ActionTs string `json:"action_ts"`
MessageTs string `json:"message_ts"`
AttachmentID string `json:"attachment_id"`
Token string `json:"token"`
}
//select structure
type ExternalSelectResponse struct {
ExSelectOptions []ExternalSelectOption `json:"options"`
}
type ExternalSelectOption struct {
Label string `json:"text"`
Value string `json:"value"`
}
func ParseExternalContent(body string, opts ...slackevents.Option) (ExternalRequest, error) {
byteString := []byte(body)
action := ExternalRequest{}
err := json.Unmarshal(byteString, &action)
if err != nil {
return ExternalRequest{}, errors.New("ExternalRequest unmarshalling failed")
}
cfg := &slackevents.Config{}
cfg.VerificationToken = action.Token
for _, opt := range opts {
opt(cfg)
}
if !cfg.TokenVerified {
return ExternalRequest{}, errors.New("invalid verification token")
} else {
return action, nil
}
}