Package list golang-github-nlopes-slack / 74f694f
:art: Hygiene, Mostly Related To ID Joe Fitzgerald 6 years ago
26 changed file(s) with 264 addition(s) and 263 deletion(s). Raw diff Collapse all Expand all
2828 return
2929 }
3030 for _, group := range groups {
31 fmt.Printf("Id: %s, Name: %s\n", group.Id, group.Name)
31 fmt.Printf("ID: %s, Name: %s\n", group.ID, group.Name)
3232 }
3333 }
3434
4747 fmt.Printf("%s\n", err)
4848 return
4949 }
50 fmt.Printf("Id: %s, Fullname: %s, Email: %s\n", user.Id, user.Profile.RealName, user.Profile.Email)
50 fmt.Printf("ID: %s, Fullname: %s, Email: %s\n", user.ID, user.Profile.RealName, user.Profile.Email)
5151 }
5252
5353 ## Why?
6060 Anyone is welcome to contribute. Either open a PR or create an issue.
6161
6262 ## License
63 BSD 2 Clause license
63 BSD 2 Clause license
2424 return adminResponse, nil
2525 }
2626
27 // InviteGuest invites a user to Slack as a single-channel guest
2728 func (api *Slack) InviteGuest(
2829 teamName string,
29 channelID string,
30 channel string,
3031 firstName string,
3132 lastName string,
3233 emailAddress string,
3334 ) error {
3435 values := url.Values{
3536 "email": {emailAddress},
36 "channels": {channelID},
37 "channels": {channel},
3738 "first_name": {firstName},
3839 "last_name": {lastName},
3940 "ultra_restricted": {"1"},
5051 return nil
5152 }
5253
54 // InviteRestricted invites a user to Slack as a restricted account
5355 func (api *Slack) InviteRestricted(
5456 teamName string,
55 channelID string,
57 channel string,
5658 firstName string,
5759 lastName string,
5860 emailAddress string,
5961 ) error {
6062 values := url.Values{
6163 "email": {emailAddress},
62 "channels": {channelID},
64 "channels": {channel},
6365 "first_name": {firstName},
6466 "last_name": {lastName},
6567 "restricted": {"1"},
0 package slack
1
2 // AttachmentField contains information for an attachment field
3 // An Attachment can contain multiple of these
4 type AttachmentField struct {
5 Title string `json:"title"`
6 Value string `json:"value"`
7 Short bool `json:"short"`
8 }
9
10 // Attachment contains all the information for an attachment
11 type Attachment struct {
12 Color string `json:"color,omitempty"`
13 Fallback string `json:"fallback"`
14
15 AuthorName string `json:"author_name,omitempty"`
16 AuthorSubname string `json:"author_subname,omitempty"`
17 AuthorLink string `json:"author_link,omitempty"`
18 AuthorIcon string `json:"author_icon,omitempty"`
19
20 Title string `json:"title,omitempty"`
21 TitleLink string `json:"title_link,omitempty"`
22 Pretext string `json:"pretext,omitempty"`
23 Text string `json:"text"`
24
25 ImageURL string `json:"image_url,omitempty"`
26 ThumbURL string `json:"thumb_url,omitempty"`
27
28 Fields []AttachmentField `json:"fields,omitempty"`
29 MarkdownIn []string `json:"mrkdwn_in,omitempty"`
30 }
2929 LastSet JSONTime `json:"last_set"`
3030 }
3131
32 type BaseChannel struct {
33 Id string `json:"id"`
34 Created JSONTime `json:"created"`
35 IsOpen bool `json:"is_open"`
36 LastRead string `json:"last_read,omitempty"`
37 Latest Message `json:"latest,omitempty"`
38 UnreadCount int `json:"unread_count,omitempty"`
39 UnreadCountDisplay int `json:"unread_count_display,omitempty"`
32 type baseChannel struct {
33 ID string `json:"id"`
34 Created JSONTime `json:"created"`
35 IsOpen bool `json:"is_open"`
36 LastRead string `json:"last_read,omitempty"`
37 Latest Message `json:"latest,omitempty"`
38 UnreadCount int `json:"unread_count,omitempty"`
39 UnreadCountDisplay int `json:"unread_count_display,omitempty"`
4040 }
4141
4242 // Channel contains information about the channel
4343 type Channel struct {
44 BaseChannel
45 Name string `json:"name"`
46 IsChannel bool `json:"is_channel"`
47 Creator string `json:"creator"`
48 IsArchived bool `json:"is_archived"`
49 IsGeneral bool `json:"is_general"`
50 Members []string `json:"members"`
51 Topic ChannelTopic `json:"topic"`
52 Purpose ChannelPurpose `json:"purpose"`
53 IsMember bool `json:"is_member"`
54 LastRead string `json:"last_read,omitempty"`
55 Latest *Message `json:"latest,omitempty"`
56 UnreadCount int `json:"unread_count,omitempty"`
57 NumMembers int `json:"num_members,omitempty"`
44 baseChannel
45 Name string `json:"name"`
46 IsChannel bool `json:"is_channel"`
47 Creator string `json:"creator"`
48 IsArchived bool `json:"is_archived"`
49 IsGeneral bool `json:"is_general"`
50 Members []string `json:"members"`
51 Topic ChannelTopic `json:"topic"`
52 Purpose ChannelPurpose `json:"purpose"`
53 IsMember bool `json:"is_member"`
54 LastRead string `json:"last_read,omitempty"`
55 Latest *Message `json:"latest,omitempty"`
56 UnreadCount int `json:"unread_count,omitempty"`
57 NumMembers int `json:"num_members,omitempty"`
5858 }
5959
6060 func channelRequest(path string, values url.Values, debug bool) (*channelResponseFull, error) {
7070 }
7171
7272 // ArchiveChannel archives the given channel
73 func (api *Slack) ArchiveChannel(channelId string) error {
74 values := url.Values{
75 "token": {api.config.token},
76 "channel": {channelId},
73 func (api *Slack) ArchiveChannel(channel string) error {
74 values := url.Values{
75 "token": {api.config.token},
76 "channel": {channel},
7777 }
7878 _, err := channelRequest("channels.archive", values, api.debug)
7979 if err != nil {
8383 }
8484
8585 // UnarchiveChannel unarchives the given channel
86 func (api *Slack) UnarchiveChannel(channelId string) error {
87 values := url.Values{
88 "token": {api.config.token},
89 "channel": {channelId},
86 func (api *Slack) UnarchiveChannel(channel string) error {
87 values := url.Values{
88 "token": {api.config.token},
89 "channel": {channel},
9090 }
9191 _, err := channelRequest("channels.unarchive", values, api.debug)
9292 if err != nil {
109109 }
110110
111111 // GetChannelHistory retrieves the channel history
112 func (api *Slack) GetChannelHistory(channelId string, params HistoryParameters) (*History, error) {
113 values := url.Values{
114 "token": {api.config.token},
115 "channel": {channelId},
112 func (api *Slack) GetChannelHistory(channel string, params HistoryParameters) (*History, error) {
113 values := url.Values{
114 "token": {api.config.token},
115 "channel": {channel},
116116 }
117117 if params.Latest != DEFAULT_HISTORY_LATEST {
118118 values.Add("latest", params.Latest)
138138 }
139139
140140 // GetChannelInfo retrieves the given channel
141 func (api *Slack) GetChannelInfo(channelId string) (*Channel, error) {
142 values := url.Values{
143 "token": {api.config.token},
144 "channel": {channelId},
141 func (api *Slack) GetChannelInfo(channel string) (*Channel, error) {
142 values := url.Values{
143 "token": {api.config.token},
144 "channel": {channel},
145145 }
146146 response, err := channelRequest("channels.info", values, api.debug)
147147 if err != nil {
151151 }
152152
153153 // InviteUserToChannel invites a user to a given channel and returns a *Channel
154 func (api *Slack) InviteUserToChannel(channelId, userId string) (*Channel, error) {
155 values := url.Values{
156 "token": {api.config.token},
157 "channel": {channelId},
158 "user": {userId},
154 func (api *Slack) InviteUserToChannel(channel, user string) (*Channel, error) {
155 values := url.Values{
156 "token": {api.config.token},
157 "channel": {channel},
158 "user": {user},
159159 }
160160 response, err := channelRequest("channels.invite", values, api.debug)
161161 if err != nil {
178178 }
179179
180180 // LeaveChannel makes the authenticated user leave the given channel
181 func (api *Slack) LeaveChannel(channelId string) (bool, error) {
182 values := url.Values{
183 "token": {api.config.token},
184 "channel": {channelId},
181 func (api *Slack) LeaveChannel(channel string) (bool, error) {
182 values := url.Values{
183 "token": {api.config.token},
184 "channel": {channel},
185185 }
186186 response, err := channelRequest("channels.leave", values, api.debug)
187187 if err != nil {
194194 }
195195
196196 // KickUserFromChannel kicks a user from a given channel
197 func (api *Slack) KickUserFromChannel(channelId, userId string) error {
198 values := url.Values{
199 "token": {api.config.token},
200 "channel": {channelId},
201 "user": {userId},
197 func (api *Slack) KickUserFromChannel(channel, user string) error {
198 values := url.Values{
199 "token": {api.config.token},
200 "channel": {channel},
201 "user": {user},
202202 }
203203 _, err := channelRequest("channels.kick", values, api.debug)
204204 if err != nil {
227227 // timer before making the call. In this way, any further updates needed during the timeout will not generate extra calls
228228 // (just one per channel). This is useful for when reading scroll-back history, or following a busy live channel. A
229229 // timeout of 5 seconds is a good starting point. Be sure to flush these calls on shutdown/logout.
230 func (api *Slack) SetChannelReadMark(channelId, ts string) error {
231 values := url.Values{
232 "token": {api.config.token},
233 "channel": {channelId},
230 func (api *Slack) SetChannelReadMark(channel, ts string) error {
231 values := url.Values{
232 "token": {api.config.token},
233 "channel": {channel},
234234 "ts": {ts},
235235 }
236236 _, err := channelRequest("channels.mark", values, api.debug)
241241 }
242242
243243 // RenameChannel renames a given channel
244 func (api *Slack) RenameChannel(channelId, name string) (*Channel, error) {
245 values := url.Values{
246 "token": {api.config.token},
247 "channel": {channelId},
244 func (api *Slack) RenameChannel(channel, name string) (*Channel, error) {
245 values := url.Values{
246 "token": {api.config.token},
247 "channel": {channel},
248248 "name": {name},
249249 }
250250 // XXX: the created entry in this call returns a string instead of a number
259259
260260 // SetChannelPurpose sets the channel purpose and returns the purpose that was
261261 // successfully set
262 func (api *Slack) SetChannelPurpose(channelId, purpose string) (string, error) {
263 values := url.Values{
264 "token": {api.config.token},
265 "channel": {channelId},
262 func (api *Slack) SetChannelPurpose(channel, purpose string) (string, error) {
263 values := url.Values{
264 "token": {api.config.token},
265 "channel": {channel},
266266 "purpose": {purpose},
267267 }
268268 response, err := channelRequest("channels.setPurpose", values, api.debug)
273273 }
274274
275275 // SetChannelTopic sets the channel topic and returns the topic that was successfully set
276 func (api *Slack) SetChannelTopic(channelId, topic string) (string, error) {
277 values := url.Values{
278 "token": {api.config.token},
279 "channel": {channelId},
276 func (api *Slack) SetChannelTopic(channel, topic string) (string, error) {
277 values := url.Values{
278 "token": {api.config.token},
279 "channel": {channel},
280280 "topic": {topic},
281281 }
282282 response, err := channelRequest("channels.setTopic", values, api.debug)
2020 )
2121
2222 type chatResponseFull struct {
23 ChannelId string `json:"channel"`
23 Channel string `json:"channel"`
2424 Timestamp string `json:"ts"`
2525 Text string `json:"text"`
2626 SlackResponse
27 }
28
29 // AttachmentField contains information for an attachment field
30 // An Attachment can contain multiple of these
31 type AttachmentField struct {
32 Title string `json:"title"`
33 Value string `json:"value"`
34 Short bool `json:"short"`
35 }
36
37 // Attachment contains all the information for an attachment
38 type Attachment struct {
39 Fallback string `json:"fallback"`
40
41 Color string `json:"color,omitempty"`
42
43 Pretext string `json:"pretext,omitempty"`
44
45 AuthorName string `json:"author_name,omitempty"`
46 AuthorLink string `json:"author_link,omitempty"`
47 AuthorIcon string `json:"author_icon,omitempty"`
48
49 Title string `json:"title,omitempty"`
50 TitleLink string `json:"title_link,omitempty"`
51
52 Text string `json:"text"`
53
54 ImageURL string `json:"image_url,omitempty"`
55 ThumbURL string `json:"thumb_url,omitempty"`
56
57 Fields []AttachmentField `json:"fields,omitempty"`
58
59 MarkdownIn []string `json:"mrkdwn_in,omitempty"`
6027 }
6128
6229 // PostMessageParameters contains all the parameters necessary (including the optional ones) for a PostMessage() request
10572 }
10673
10774 // DeleteMessage deletes a message in a channel
108 func (api *Slack) DeleteMessage(channelId, messageTimestamp string) (string, string, error) {
75 func (api *Slack) DeleteMessage(channel, messageTimestamp string) (string, string, error) {
10976 values := url.Values{
11077 "token": {api.config.token},
111 "channel": {channelId},
78 "channel": {channel},
11279 "ts": {messageTimestamp},
11380 }
11481 response, err := chatRequest("chat.delete", values, api.debug)
11582 if err != nil {
11683 return "", "", err
11784 }
118 return response.ChannelId, response.Timestamp, nil
85 return response.Channel, response.Timestamp, nil
11986 }
12087
12188 func escapeMessage(message string) string {
13097
13198 // PostMessage sends a message to a channel
13299 // Message is escaped by default according to https://api.slack.com/docs/formatting
133 func (api *Slack) PostMessage(channelId string, text string, params PostMessageParameters) (channel string, timestamp string, err error) {
100 func (api *Slack) PostMessage(channel string, text string, params PostMessageParameters) (string, string, error) {
134101 if params.EscapeText {
135102 text = escapeMessage(text)
136103 }
137104 values := url.Values{
138105 "token": {api.config.token},
139 "channel": {channelId},
106 "channel": {channel},
140107 "text": {text},
141108 }
142109 if params.Username != DEFAULT_MESSAGE_USERNAME {
178145 if err != nil {
179146 return "", "", err
180147 }
181 return response.ChannelId, response.Timestamp, nil
148 return response.Channel, response.Timestamp, nil
182149 }
183150
184151 // UpdateMessage updates a message in a channel
185 func (api *Slack) UpdateMessage(channelId, timestamp, text string) (string, string, string, error) {
152 func (api *Slack) UpdateMessage(channel, timestamp, text string) (string, string, string, error) {
186153 values := url.Values{
187154 "token": {api.config.token},
188 "channel": {channelId},
155 "channel": {channel},
189156 "text": {escapeMessage(text)},
190157 "ts": {timestamp},
191158 }
193160 if err != nil {
194161 return "", "", "", err
195162 }
196 return response.ChannelId, response.Timestamp, response.Text, nil
163 return response.Channel, response.Timestamp, response.Text, nil
197164 }
0 package slack
1
2 // Comment contains all the information relative to a comment
3 type Comment struct {
4 ID string `json:"id,omitempty"`
5 Created JSONTime `json:"created,omitempty"`
6 Timestamp JSONTime `json:"timestamp,omitempty"`
7 User string `json:"user,omitempty"`
8 Comment string `json:"comment,omitempty"`
9 }
+15
-15
dm.go less more
66 )
77
88 type imChannel struct {
9 Id string `json:"id"`
9 ID string `json:"id"`
1010 }
1111
1212 type imResponseFull struct {
2121
2222 // IM contains information related to the Direct Message channel
2323 type IM struct {
24 BaseChannel
25 IsIM bool `json:"is_im"`
26 UserId string `json:"user"`
27 IsUserDeleted bool `json:"is_user_deleted"`
24 baseChannel
25 IsIM bool `json:"is_im"`
26 User string `json:"user"`
27 IsUserDeleted bool `json:"is_user_deleted"`
2828 }
2929
3030 func imRequest(path string, values url.Values, debug bool) (*imResponseFull, error) {
4040 }
4141
4242 // CloseIMChannel closes the direct message channel
43 func (api *Slack) CloseIMChannel(channelId string) (bool, bool, error) {
43 func (api *Slack) CloseIMChannel(channel string) (bool, bool, error) {
4444 values := url.Values{
4545 "token": {api.config.token},
46 "channel": {channelId},
46 "channel": {channel},
4747 }
4848 response, err := imRequest("im.close", values, api.debug)
4949 if err != nil {
5353 }
5454
5555 // OpenIMChannel opens a direct message channel to the user provided as argument
56 // Returns some status and the channelId
57 func (api *Slack) OpenIMChannel(userId string) (bool, bool, string, error) {
56 // Returns some status and the channel
57 func (api *Slack) OpenIMChannel(user string) (bool, bool, string, error) {
5858 values := url.Values{
5959 "token": {api.config.token},
60 "user": {userId},
60 "user": {user},
6161 }
6262 response, err := imRequest("im.open", values, api.debug)
6363 if err != nil {
6464 return false, false, "", err
6565 }
66 return response.NoOp, response.AlreadyOpen, response.Channel.Id, nil
66 return response.NoOp, response.AlreadyOpen, response.Channel.ID, nil
6767 }
6868
6969 // MarkIMChannel sets the read mark of a direct message channel to a specific point
70 func (api *Slack) MarkIMChannel(channelId, ts string) (err error) {
70 func (api *Slack) MarkIMChannel(channel, ts string) (err error) {
7171 values := url.Values{
7272 "token": {api.config.token},
73 "channel": {channelId},
73 "channel": {channel},
7474 "ts": {ts},
7575 }
7676 _, err = imRequest("im.mark", values, api.debug)
8181 }
8282
8383 // GetIMHistory retrieves the direct message channel history
84 func (api *Slack) GetIMHistory(channelId string, params HistoryParameters) (*History, error) {
84 func (api *Slack) GetIMHistory(channel string, params HistoryParameters) (*History, error) {
8585 values := url.Values{
8686 "token": {api.config.token},
87 "channel": {channelId},
87 "channel": {channel},
8888 }
8989 if params.Latest != DEFAULT_HISTORY_LATEST {
9090 values.Add("latest", params.Latest)
2020 }
2121 fmt.Printf("Name: %s, Url: %s\n", file.Name, file.URL)
2222
23 err = api.DeleteFile(file.Id)
23 err = api.DeleteFile(file.ID)
2424 if err != nil {
2525 fmt.Printf("%s\n", err)
2626 return
1616 return
1717 }
1818 for _, group := range groups {
19 fmt.Printf("Id: %s, Name: %s\n", group.Id, group.Name)
19 fmt.Printf("ID: %s, Name: %s\n", group.ID, group.Name)
2020 }
2121 }
2222 */
2323 }
2424 params.Attachments = []slack.Attachment{attachment}
25 channelId, timestamp, err := api.PostMessage("CHANNEL_ID", "Some text", params)
25 channelID, timestamp, err := api.PostMessage("CHANNEL_ID", "Some text", params)
2626 if err != nil {
2727 fmt.Printf("%s\n", err)
2828 return
2929 }
30 fmt.Printf("Message successfully sent to channel %s at %s", channelId, timestamp)
30 fmt.Printf("Message successfully sent to channel %s at %s", channelID, timestamp)
3131 }
1212 fmt.Printf("%s\n", err)
1313 return
1414 }
15 fmt.Printf("Id: %s, Fullname: %s, Email: %s\n", user.Id, user.Profile.RealName, user.Profile.Email)
15 fmt.Printf("ID: %s, Fullname: %s, Email: %s\n", user.ID, user.Profile.RealName, user.Profile.Email)
1616 }
88
99 const (
1010 // Add here the defaults in the siten
11 DEFAULT_FILES_USERID = ""
11 DEFAULT_FILES_USER = ""
1212 DEFAULT_FILES_TS_FROM = 0
1313 DEFAULT_FILES_TS_TO = -1
1414 DEFAULT_FILES_TYPES = "all"
1616 DEFAULT_FILES_PAGE = 1
1717 )
1818
19 // Comment contains all the information relative to a comment
20 type Comment struct {
21 Id string `json:"id"`
22 Timestamp JSONTime `json:"timestamp"`
23 UserId string `json:"user"`
24 Comment string `json:"comment"`
25 Created JSONTime `json:"created,omitempty"`
26 }
27
2819 // File contains all the information for a file
2920 type File struct {
30 Id string `json:"id"`
21 ID string `json:"id"`
3122 Created JSONTime `json:"created"`
3223 Timestamp JSONTime `json:"timestamp"`
3324
3627 Mimetype string `json:"mimetype"`
3728 Filetype string `json:"filetype"`
3829 PrettyType string `json:"pretty_type"`
39 UserId string `json:"user"`
30 User string `json:"user"`
4031
4132 Mode string `json:"mode"`
4233 Editable bool `json:"editable"`
8677
8778 // GetFilesParameters contains all the parameters necessary (including the optional ones) for a GetFiles() request
8879 type GetFilesParameters struct {
89 UserId string
80 User string
9081 TimestampFrom JSONTime
9182 TimestampTo JSONTime
9283 Types string
10697 // NewGetFilesParameters provides an instance of GetFilesParameters with all the sane default values set
10798 func NewGetFilesParameters() GetFilesParameters {
10899 return GetFilesParameters{
109 UserId: DEFAULT_FILES_USERID,
100 User: DEFAULT_FILES_USER,
110101 TimestampFrom: DEFAULT_FILES_TS_FROM,
111102 TimestampTo: DEFAULT_FILES_TS_TO,
112103 Types: DEFAULT_FILES_TYPES,
128119 }
129120
130121 // GetFileInfo retrieves a file and related comments
131 func (api *Slack) GetFileInfo(fileId string, count, page int) (*File, []Comment, *Paging, error) {
132 values := url.Values{
133 "token": {api.config.token},
134 "file": {fileId},
122 func (api *Slack) GetFileInfo(fileID string, count, page int) (*File, []Comment, *Paging, error) {
123 values := url.Values{
124 "token": {api.config.token},
125 "file": {fileID},
135126 "count": {strconv.Itoa(count)},
136127 "page": {strconv.Itoa(page)},
137128 }
147138 values := url.Values{
148139 "token": {api.config.token},
149140 }
150 if params.UserId != DEFAULT_FILES_USERID {
151 values.Add("user", params.UserId)
141 if params.User != DEFAULT_FILES_USER {
142 values.Add("user", params.User)
152143 }
153144 // XXX: this is broken. fix it with a proper unix timestamp
154145 if params.TimestampFrom != DEFAULT_FILES_TS_FROM {
216207 }
217208
218209 // DeleteFile deletes a file
219 func (api *Slack) DeleteFile(fileId string) error {
220 values := url.Values{
221 "token": {api.config.token},
222 "file": {fileId},
210 func (api *Slack) DeleteFile(fileID string) error {
211 values := url.Values{
212 "token": {api.config.token},
213 "file": {fileID},
223214 }
224215 _, err := fileRequest("files.delete", values, api.debug)
225216 if err != nil {
77
88 // Group contains all the information for a group
99 type Group struct {
10 BaseChannel
10 baseChannel
1111 Name string `json:"name"`
1212 IsGroup bool `json:"is_group"`
1313 Creator string `json:"creator"`
5151 }
5252
5353 // ArchiveGroup archives a private group
54 func (api *Slack) ArchiveGroup(groupId string) error {
55 values := url.Values{
56 "token": {api.config.token},
57 "channel": {groupId},
54 func (api *Slack) ArchiveGroup(group string) error {
55 values := url.Values{
56 "token": {api.config.token},
57 "channel": {group},
5858 }
5959 _, err := groupRequest("groups.archive", values, api.debug)
6060 if err != nil {
6464 }
6565
6666 // UnarchiveGroup unarchives a private group
67 func (api *Slack) UnarchiveGroup(groupId string) error {
68 values := url.Values{
69 "token": {api.config.token},
70 "channel": {groupId},
67 func (api *Slack) UnarchiveGroup(group string) error {
68 values := url.Values{
69 "token": {api.config.token},
70 "channel": {group},
7171 }
7272 _, err := groupRequest("groups.unarchive", values, api.debug)
7373 if err != nil {
9595 // 2. Archives the existing group.
9696 // 3. Creates a new group with the name of the existing group.
9797 // 4. Adds all members of the existing group to the new group.
98 func (api *Slack) CreateChildGroup(groupId string) (*Group, error) {
99 values := url.Values{
100 "token": {api.config.token},
101 "channel": {groupId},
98 func (api *Slack) CreateChildGroup(group string) (*Group, error) {
99 values := url.Values{
100 "token": {api.config.token},
101 "channel": {group},
102102 }
103103 response, err := groupRequest("groups.createChild", values, api.debug)
104104 if err != nil {
108108 }
109109
110110 // CloseGroup closes a private group
111 func (api *Slack) CloseGroup(groupId string) (bool, bool, error) {
112 values := url.Values{
113 "token": {api.config.token},
114 "channel": {groupId},
111 func (api *Slack) CloseGroup(group string) (bool, bool, error) {
112 values := url.Values{
113 "token": {api.config.token},
114 "channel": {group},
115115 }
116116 response, err := imRequest("groups.close", values, api.debug)
117117 if err != nil {
121121 }
122122
123123 // GetGroupHistory retrieves message history for a give group
124 func (api *Slack) GetGroupHistory(groupId string, params HistoryParameters) (*History, error) {
125 values := url.Values{
126 "token": {api.config.token},
127 "channel": {groupId},
124 func (api *Slack) GetGroupHistory(group string, params HistoryParameters) (*History, error) {
125 values := url.Values{
126 "token": {api.config.token},
127 "channel": {group},
128128 }
129129 if params.Latest != DEFAULT_HISTORY_LATEST {
130130 values.Add("latest", params.Latest)
150150 }
151151
152152 // InviteUserToGroup invites a user to a group
153 func (api *Slack) InviteUserToGroup(groupId, userId string) (*Group, bool, error) {
154 values := url.Values{
155 "token": {api.config.token},
156 "channel": {groupId},
157 "user": {userId},
153 func (api *Slack) InviteUserToGroup(group, user string) (*Group, bool, error) {
154 values := url.Values{
155 "token": {api.config.token},
156 "channel": {group},
157 "user": {user},
158158 }
159159 response, err := groupRequest("groups.invite", values, api.debug)
160160 if err != nil {
164164 }
165165
166166 // LeaveGroup makes authenticated user leave the group
167 func (api *Slack) LeaveGroup(groupId string) error {
168 values := url.Values{
169 "token": {api.config.token},
170 "channel": {groupId},
167 func (api *Slack) LeaveGroup(group string) error {
168 values := url.Values{
169 "token": {api.config.token},
170 "channel": {group},
171171 }
172172 _, err := groupRequest("groups.leave", values, api.debug)
173173 if err != nil {
177177 }
178178
179179 // KickUserFromGroup kicks a user from a group
180 func (api *Slack) KickUserFromGroup(groupId, userId string) error {
181 values := url.Values{
182 "token": {api.config.token},
183 "channel": {groupId},
184 "user": {userId},
180 func (api *Slack) KickUserFromGroup(group, user string) error {
181 values := url.Values{
182 "token": {api.config.token},
183 "channel": {group},
184 "user": {user},
185185 }
186186 _, err := groupRequest("groups.kick", values, api.debug)
187187 if err != nil {
206206 }
207207
208208 // GetGroupInfo retrieves the given group
209 func (api *Slack) GetGroupInfo(groupId string) (*Group, error) {
210 values := url.Values{
211 "token": {api.config.token},
212 "channel": {groupId},
209 func (api *Slack) GetGroupInfo(group string) (*Group, error) {
210 values := url.Values{
211 "token": {api.config.token},
212 "channel": {group},
213213 }
214214 response, err := groupRequest("groups.info", values, api.debug)
215215 if err != nil {
223223 // timer before making the call. In this way, any further updates needed during the timeout will not generate extra
224224 // calls (just one per channel). This is useful for when reading scroll-back history, or following a busy live
225225 // channel. A timeout of 5 seconds is a good starting point. Be sure to flush these calls on shutdown/logout.
226 func (api *Slack) SetGroupReadMark(groupId, ts string) error {
227 values := url.Values{
228 "token": {api.config.token},
229 "channel": {groupId},
226 func (api *Slack) SetGroupReadMark(group, ts string) error {
227 values := url.Values{
228 "token": {api.config.token},
229 "channel": {group},
230230 "ts": {ts},
231231 }
232232 _, err := groupRequest("groups.mark", values, api.debug)
237237 }
238238
239239 // OpenGroup opens a private group
240 func (api *Slack) OpenGroup(groupId string) (bool, bool, error) {
240 func (api *Slack) OpenGroup(group string) (bool, bool, error) {
241241 values := url.Values{
242242 "token": {api.config.token},
243 "user": {groupId},
243 "user": {group},
244244 }
245245 response, err := groupRequest("groups.open", values, api.debug)
246246 if err != nil {
252252 // RenameGroup renames a group
253253 // XXX: They return a channel, not a group. What is this crap? :(
254254 // Inconsistent api it seems.
255 func (api *Slack) RenameGroup(groupId, name string) (*Channel, error) {
256 values := url.Values{
257 "token": {api.config.token},
258 "channel": {groupId},
255 func (api *Slack) RenameGroup(group, name string) (*Channel, error) {
256 values := url.Values{
257 "token": {api.config.token},
258 "channel": {group},
259259 "name": {name},
260260 }
261261 // XXX: the created entry in this call returns a string instead of a number
269269 }
270270
271271 // SetGroupPurpose sets the group purpose
272 func (api *Slack) SetGroupPurpose(groupId, purpose string) (string, error) {
273 values := url.Values{
274 "token": {api.config.token},
275 "channel": {groupId},
272 func (api *Slack) SetGroupPurpose(group, purpose string) (string, error) {
273 values := url.Values{
274 "token": {api.config.token},
275 "channel": {group},
276276 "purpose": {purpose},
277277 }
278278 response, err := groupRequest("groups.setPurpose", values, api.debug)
283283 }
284284
285285 // SetGroupTopic sets the group topic
286 func (api *Slack) SetGroupTopic(groupId, topic string) (string, error) {
287 values := url.Values{
288 "token": {api.config.token},
289 "channel": {groupId},
286 func (api *Slack) SetGroupTopic(group, topic string) (string, error) {
287 values := url.Values{
288 "token": {api.config.token},
289 "channel": {group},
290290 "topic": {topic},
291291 }
292292 response, err := groupRequest("groups.setTopic", values, api.debug)
105105
106106 // UserDetails contains user details coming in the initial response from StartRTM
107107 type UserDetails struct {
108 Id string `json:"id"`
108 ID string `json:"id"`
109109 Name string `json:"name"`
110110 Created JSONTime `json:"created"`
111111 ManualPresence string `json:"manual_presence"`
123123
124124 // Team contains details about a team
125125 type Team struct {
126 Id string `json:"id"`
126 ID string `json:"id"`
127127 Name string `json:"name"`
128128 Domain string `json:"name"`
129129 }
135135
136136 // Bot contains information about a bot
137137 type Bot struct {
138 Id string `json:"id"`
138 ID string `json:"id"`
139139 Name string `json:"name"`
140140 Deleted bool `json:"deleted"`
141141 Icons Icons `json:"icons"`
159159 SlackWSResponse
160160 }
161161
162 // GetBotById returns a bot given a bot id
163 func (info Info) GetBotById(botId string) *Bot {
162 // GetBotByID returns a bot given a bot id
163 func (info Info) GetBotByID(botID string) *Bot {
164164 for _, bot := range info.Bots {
165 if bot.Id == botId {
165 if bot.ID == botID {
166166 return &bot
167167 }
168168 }
169169 return nil
170170 }
171171
172 // GetUserById returns a user given a user id
173 func (info Info) GetUserById(userId string) *User {
172 // GetUserByID returns a user given a user id
173 func (info Info) GetUserByID(userID string) *User {
174174 for _, user := range info.Users {
175 if user.Id == userId {
175 if user.ID == userID {
176176 return &user
177177 }
178178 }
179179 return nil
180180 }
181181
182 // GetChannelById returns a channel given a channel id
183 func (info Info) GetChannelById(channelId string) *Channel {
182 // GetChannelByID returns a channel given a channel id
183 func (info Info) GetChannelByID(channelID string) *Channel {
184184 for _, channel := range info.Channels {
185 if channel.Id == channelId {
185 if channel.ID == channelID {
186186 return &channel
187187 }
188188 }
1111 }
1212
1313 // GetOAuthToken retrieves an AccessToken
14 func GetOAuthToken(clientId, clientSecret, code, redirectURI string, debug bool) (accessToken string, scope string, err error) {
14 func GetOAuthToken(clientID, clientSecret, code, redirectURI string, debug bool) (accessToken string, scope string, err error) {
1515 values := url.Values{
16 "client_id": {clientId},
16 "client_id": {clientID},
1717 "client_secret": {clientSecret},
1818 "code": {code},
1919 "redirect_uri": {redirectURI},
2222 }
2323
2424 type CtxChannel struct {
25 Id string `json:"id"`
25 ID string `json:"id"`
2626 Name string `json:"name"`
2727 }
2828
2929 type CtxMessage struct {
30 UserId string `json:"user"`
30 User string `json:"user"`
3131 Username string `json:"username"`
3232 Text string `json:"text"`
3333 Timestamp string `json:"ts"`
3737 type SearchMessage struct {
3838 Type string `json:"type"`
3939 Channel CtxChannel `json:"channel"`
40 UserId string `json:"user"`
40 User string `json:"user"`
4141 Username string `json:"username"`
4242 Timestamp string `json:"ts"`
4343 Text string `json:"text"`
1919 Url string `json:"url"`
2020 Team string `json:"team"`
2121 User string `json:"user"`
22 TeamId string `json:"team_id"`
23 UserId string `json:"user_id"`
22 TeamID string `json:"team_id"`
23 UserID string `json:"user_id"`
2424 }
2525
2626 type authTestResponseFull struct {
66 )
77
88 const (
9 DEFAULT_STARS_USERID = ""
10 DEFAULT_STARS_COUNT = 100
11 DEFAULT_STARS_PAGE = 1
9 DEFAULT_STARS_USER = ""
10 DEFAULT_STARS_COUNT = 100
11 DEFAULT_STARS_PAGE = 1
1212 )
1313
1414 type StarsParameters struct {
3030
3131 func NewStarsParameters() StarsParameters {
3232 return StarsParameters{
33 User: DEFAULT_STARS_USERID,
33 User: DEFAULT_STARS_USER,
3434 Count: DEFAULT_STARS_COUNT,
3535 Page: DEFAULT_STARS_PAGE,
3636 }
5050 values := url.Values{
5151 "token": {api.config.token},
5252 }
53 if params.User != DEFAULT_STARS_USERID {
53 if params.User != DEFAULT_STARS_USER {
5454 values.Add("user", params.User)
5555 }
5656 if params.Count != DEFAULT_STARS_COUNT {
2424
2525 // User contains all the information of a user
2626 type User struct {
27 Id string `json:"id"`
27 ID string `json:"id"`
2828 Name string `json:"name"`
2929 Deleted bool `json:"deleted"`
3030 Color string `json:"color"`
7474 }
7575
7676 // GetUserPresence will retrieve the current presence status of given user.
77 func (api *Slack) GetUserPresence(userId string) (*UserPresence, error) {
77 func (api *Slack) GetUserPresence(user string) (*UserPresence, error) {
7878 values := url.Values{
7979 "token": {api.config.token},
80 "user": {userId},
80 "user": {user},
8181 }
8282 response, err := userRequest("users.getPresence", values, api.debug)
8383 if err != nil {
8787 }
8888
8989 // GetUserInfo will retrive the complete user information
90 func (api *Slack) GetUserInfo(userId string) (*User, error) {
90 func (api *Slack) GetUserInfo(user string) (*User, error) {
9191 values := url.Values{
9292 "token": {api.config.token},
93 "user": {userId},
93 "user": {user},
9494 }
9595 response, err := userRequest("users.info", values, api.debug)
9696 if err != nil {
112112 api.mutex.Lock()
113113 defer api.mutex.Unlock()
114114 api.messageId++
115 msg := &Ping{Id: api.messageId, Type: "ping"}
115 msg := &Ping{ID: api.messageId, Type: "ping"}
116116 if err := websocket.JSON.Send(api.conn, msg); err != nil {
117117 return err
118118 }
66 }
77
88 type ChannelCreatedInfo struct {
9 Id string `json:"id"`
9 ID string `json:"id"`
1010 IsChannel bool `json:"is_channel"`
1111 Name string `json:"name"`
1212 Created JSONTimeString `json:"created"`
2424 // channel_archive
2525 // channel_unarchive
2626 Type string `json:"type"`
27 ChannelId string `json:"channel"`
28 UserId string `json:"user,omitempty"`
27 Channel string `json:"channel"`
28 User string `json:"user,omitempty"`
2929 Timestamp *JSONTimeString `json:"ts,omitempty"`
3030 }
3131
3535 }
3636
3737 type ChannelRenameInfo struct {
38 Id string `json:"id"`
38 ID string `json:"id"`
3939 Name string `json:"name"`
4040 Created JSONTimeString `json:"created"`
4141 }
11
22 type IMCreatedEvent struct {
33 Type string `json:"type"`
4 UserId string `json:"user"`
4 User string `json:"user"`
55 Channel ChannelCreatedInfo `json:"channel"`
66 }
77
33 Type string `json:"type"`
44 EventTimestamp JSONTimeString `json:"event_ts"`
55 File File `json:"file"`
6 // FileId is used for FileDeletedEvent
7 FileId string `json:"file_id,omitempty"`
6 // FileID is used for FileDeletedEvent
7 FileID string `json:"file_id,omitempty"`
88 }
99
1010 type FileCreatedEvent fileActionEvent
2727
2828 type FileCommentDeletedEvent struct {
2929 fileActionEvent
30 CommentId string `json:"comment"`
30 Comment string `json:"comment"`
3131 }
11
22 type GroupCreatedEvent struct {
33 Type string `json:"type"`
4 UserId string `json:"user"`
4 User string `json:"user"`
55 Channel ChannelCreatedInfo `json:"channel"`
66 }
77
1111 type PresenceChangeEvent struct {
1212 Type string `json:"type"`
1313 Presence string `json:"presence"`
14 UserId string `json:"user"`
14 User string `json:"user"`
1515 }
1616
1717 type UserTypingEvent struct {
18 Type string `json:"type"`
19 UserId string `json:"user"`
20 ChannelId string `json:"channel"`
18 Type string `json:"type"`
19 User string `json:"user"`
20 Channel string `json:"channel"`
2121 }
2222
2323 type LatencyReport struct {
11
22 type starEvent struct {
33 Type string `json:"type"`
4 UserId string `json:"user"`
4 User string `json:"user"`
55 Item StarredItem `json:"item"`
66 EventTimestamp JSONTimeString `json:"event_ts"`
77 }