forked from slack-go/slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manifests.go
287 lines (237 loc) · 10.4 KB
/
manifests.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
package slack
import (
"context"
"encoding/json"
"net/url"
)
// Manifest is an application manifest schema
type Manifest struct {
Metadata ManifestMetadata `json:"_metadata,omitempty" yaml:"_metadata,omitempty"`
Display Display `json:"display_information" yaml:"display_information"`
Settings Settings `json:"settings,omitempty" yaml:"settings,omitempty"`
Features Features `json:"features,omitempty" yaml:"features,omitempty"`
OAuthConfig OAuthConfig `json:"oauth_config,omitempty" yaml:"oauth_config,omitempty"`
}
// CreateManifest creates an app from an app manifest
func (api *Client) CreateManifest(manifest *Manifest, token string) (*ManifestResponse, error) {
return api.CreateManifestContext(context.Background(), manifest, token)
}
// CreateManifestContext creates an app from an app manifest with a custom context
func (api *Client) CreateManifestContext(ctx context.Context, manifest *Manifest, token string) (*ManifestResponse, error) {
if token == "" {
token = api.configToken
}
jsonBytes, err := json.Marshal(manifest)
if err != nil {
return nil, err
}
values := url.Values{
"token": {token},
"manifest": {string(jsonBytes)},
}
response := &ManifestResponse{}
err = api.postMethod(ctx, "apps.manifest.create", values, response)
if err != nil {
return nil, err
}
return response, response.Err()
}
// DeleteManifest permanently deletes an app created through app manifests
func (api *Client) DeleteManifest(token string, appId string) (*SlackResponse, error) {
return api.DeleteManifestContext(context.Background(), token, appId)
}
// DeleteManifestContext permanently deletes an app created through app manifests with a custom context
func (api *Client) DeleteManifestContext(ctx context.Context, token string, appId string) (*SlackResponse, error) {
if token == "" {
token = api.configToken
}
values := url.Values{
"token": {token},
"app_id": {appId},
}
response := &SlackResponse{}
err := api.postMethod(ctx, "apps.manifest.delete", values, response)
if err != nil {
return nil, err
}
return response, response.Err()
}
// ExportManifest exports an app manifest from an existing app
func (api *Client) ExportManifest(token string, appId string) (*Manifest, error) {
return api.ExportManifestContext(context.Background(), token, appId)
}
// ExportManifestContext exports an app manifest from an existing app with a custom context
func (api *Client) ExportManifestContext(ctx context.Context, token string, appId string) (*Manifest, error) {
if token == "" {
token = api.configToken
}
values := url.Values{
"token": {token},
"app_id": {appId},
}
response := &ExportManifestResponse{}
err := api.postMethod(ctx, "apps.manifest.export", values, response)
if err != nil {
return nil, err
}
return &response.Manifest, response.Err()
}
// UpdateManifest updates an app from an app manifest
func (api *Client) UpdateManifest(manifest *Manifest, token string, appId string) (*UpdateManifestResponse, error) {
return api.UpdateManifestContext(context.Background(), manifest, token, appId)
}
// UpdateManifestContext updates an app from an app manifest with a custom context
func (api *Client) UpdateManifestContext(ctx context.Context, manifest *Manifest, token string, appId string) (*UpdateManifestResponse, error) {
if token == "" {
token = api.configToken
}
jsonBytes, err := json.Marshal(manifest)
if err != nil {
return nil, err
}
values := url.Values{
"token": {token},
"app_id": {appId},
"manifest": {string(jsonBytes)},
}
response := &UpdateManifestResponse{}
err = api.postMethod(ctx, "apps.manifest.update", values, response)
if err != nil {
return nil, err
}
return response, response.Err()
}
// ValidateManifest sends a request to apps.manifest.validate to validate your app manifest
func (api *Client) ValidateManifest(manifest *Manifest, token string, appId string) (*ManifestResponse, error) {
return api.ValidateManifestContext(context.Background(), manifest, token, appId)
}
// ValidateManifestContext sends a request to apps.manifest.validate to validate your app manifest with a custom context
func (api *Client) ValidateManifestContext(ctx context.Context, manifest *Manifest, token string, appId string) (*ManifestResponse, error) {
if token == "" {
token = api.configToken
}
// Marshal manifest into string
jsonBytes, err := json.Marshal(manifest)
if err != nil {
return nil, err
}
values := url.Values{
"token": {token},
"manifest": {string(jsonBytes)},
}
if appId != "" {
values.Add("app_id", appId)
}
response := &ManifestResponse{}
err = api.postMethod(ctx, "apps.manifest.validate", values, response)
if err != nil {
return nil, err
}
return response, response.Err()
}
// ManifestMetadata is a group of settings that describe the manifest
type ManifestMetadata struct {
MajorVersion int `json:"major_version,omitempty" yaml:"major_version,omitempty"`
MinorVersion int `json:"minor_version,omitempty" yaml:"minor_version,omitempty"`
}
// Display is a group of settings that describe parts of an app's appearance within Slack
type Display struct {
Name string `json:"name" yaml:"name"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
LongDescription string `json:"long_description,omitempty" yaml:"long_description,omitempty"`
BackgroundColor string `json:"background_color,omitempty" yaml:"background_color,omitempty"`
}
// Settings is a group of settings corresponding to the Settings section of the app config pages.
type Settings struct {
AllowedIPAddressRanges []string `json:"allowed_ip_address_ranges,omitempty" yaml:"allowed_ip_address_ranges,omitempty"`
EventSubscriptions EventSubscriptions `json:"event_subscriptions,omitempty" yaml:"event_subscriptions,omitempty"`
Interactivity Interactivity `json:"interactivity,omitempty" yaml:"interactivity,omitempty"`
OrgDeployEnabled bool `json:"org_deploy_enabled,omitempty" yaml:"org_deploy_enabled,omitempty"`
SocketModeEnabled bool `json:"socket_mode_enabled,omitempty" yaml:"socket_mode_enabled,omitempty"`
}
// EventSubscriptions is a group of settings that describe the Events API configuration
type EventSubscriptions struct {
RequestUrl string `json:"request_url,omitempty" yaml:"request_url,omitempty"`
BotEvents []string `json:"bot_events,omitempty" yaml:"bot_events,omitempty"`
UserEvents []string `json:"user_events,omitempty" yaml:"user_events,omitempty"`
}
// Interactivity is a group of settings that describe the interactivity configuration
type Interactivity struct {
IsEnabled bool `json:"is_enabled" yaml:"is_enabled"`
RequestUrl string `json:"request_url,omitempty" yaml:"request_url,omitempty"`
MessageMenuOptionsUrl string `json:"message_menu_options_url,omitempty" yaml:"message_menu_options_url,omitempty"`
}
// Features is a group of settings corresponding to the Features section of the app config pages
type Features struct {
AppHome AppHome `json:"app_home,omitempty" yaml:"app_home,omitempty"`
BotUser BotUser `json:"bot_user,omitempty" yaml:"bot_user,omitempty"`
Shortcuts []Shortcut `json:"shortcuts,omitempty" yaml:"shortcuts,omitempty"`
SlashCommands []ManifestSlashCommand `json:"slash_commands,omitempty" yaml:"slash_commands,omitempty"`
WorkflowSteps []WorkflowStep `json:"workflow_steps,omitempty" yaml:"workflow_steps,omitempty"`
}
// AppHome is a group of settings that describe the App Home configuration
type AppHome struct {
HomeTabEnabled bool `json:"home_tab_enabled,omitempty" yaml:"home_tab_enabled,omitempty"`
MessagesTabEnabled bool `json:"messages_tab_enabled,omitempty" yaml:"messages_tab_enabled,omitempty"`
MessagesTabReadOnlyEnabled bool `json:"messages_tab_read_only_enabled,omitempty" yaml:"messages_tab_read_only_enabled,omitempty"`
}
// BotUser is a group of settings that describe bot user configuration
type BotUser struct {
DisplayName string `json:"display_name" yaml:"display_name"`
AlwaysOnline bool `json:"always_online,omitempty" yaml:"always_online,omitempty"`
}
// Shortcut is a group of settings that describes shortcut configuration
type Shortcut struct {
Name string `json:"name" yaml:"name"`
CallbackID string `json:"callback_id" yaml:"callback_id"`
Description string `json:"description" yaml:"description"`
Type ShortcutType `json:"type" yaml:"type"`
}
// ShortcutType is a new string type for the available types of shortcuts
type ShortcutType string
const (
MessageShortcut ShortcutType = "message"
GlobalShortcut ShortcutType = "global"
)
// ManifestSlashCommand is a group of settings that describes slash command configuration
type ManifestSlashCommand struct {
Command string `json:"command" yaml:"command"`
Description string `json:"description" yaml:"description"`
ShouldEscape bool `json:"should_escape,omitempty" yaml:"should_escape,omitempty"`
Url string `json:"url,omitempty" yaml:"url,omitempty"`
UsageHint string `json:"usage_hint,omitempty" yaml:"usage_hint,omitempty"`
}
// WorkflowStep is a group of settings that describes workflow steps configuration
type WorkflowStep struct {
Name string `json:"name" yaml:"name"`
CallbackID string `json:"callback_id" yaml:"callback_id"`
}
// OAuthConfig is a group of settings that describe OAuth configuration for the app
type OAuthConfig struct {
RedirectUrls []string `json:"redirect_urls,omitempty" yaml:"redirect_urls,omitempty"`
Scopes OAuthScopes `json:"scopes,omitempty" yaml:"scopes,omitempty"`
}
// OAuthScopes is a group of settings that describe permission scopes configuration
type OAuthScopes struct {
Bot []string `json:"bot,omitempty" yaml:"bot,omitempty"`
User []string `json:"user,omitempty" yaml:"user,omitempty"`
}
// ManifestResponse is the response returned by the API for apps.manifest.x endpoints
type ManifestResponse struct {
Errors []ManifestValidationError `json:"errors,omitempty"`
SlackResponse
}
// ManifestValidationError is an error message returned for invalid manifests
type ManifestValidationError struct {
Message string `json:"message"`
Pointer string `json:"pointer"`
}
type ExportManifestResponse struct {
Manifest Manifest `json:"manifest,omitempty"`
SlackResponse
}
type UpdateManifestResponse struct {
AppId string `json:"app_id,omitempty"`
PermissionsUpdated bool `json:"permissions_updated,omitempty"`
ManifestResponse
}