Package list golang-github-nlopes-slack / 60601b6
Add GetChannelReplies to channels megane42 4 years ago
3 changed file(s) with 84 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
258258 }
259259 return response.Topic, nil
260260 }
261
262 // GetChannelReplies gets an entire thread (a message plus all the messages in reply to it).
263 func (api *Client) GetChannelReplies(channel, thread_ts string) ([]Message, error) {
264 values := url.Values{
265 "token": {api.config.token},
266 "channel": {channel},
267 "thread_ts": {thread_ts},
268 }
269 response, err := channelRequest("channels.replies", values, api.debug)
270 if err != nil {
271 return nil, err
272 }
273 return response.History.Messages, nil
274 }
5757 // channel_archive, group_archive
5858 Members []string `json:"members,omitempty"`
5959
60 // channels.replies, groups.replies, im.replies, mpim.replies
61 ReplyCount int `json:"reply_count,omitempty"`
62 Replies []Reply `json:"replies,omitempty"`
63 ParentUserId string `json:"parent_user_id,omitempty"`
64
6065 // file_share, file_comment, file_mention
6166 File *File `json:"file,omitempty"`
6267
8590
8691 // Edited indicates that a message has been edited.
8792 type Edited struct {
93 User string `json:"user,omitempty"`
94 Timestamp string `json:"ts,omitempty"`
95 }
96
97 // Reply contains information about a reply for a thread
98 type Reply struct {
8899 User string `json:"user,omitempty"`
89100 Timestamp string `json:"ts,omitempty"`
90101 }
525525 assert.Equal(t, "U1234", message.User)
526526 }
527527
528 var channelRepliesParentMessage = `{
529 "type": "message",
530 "user": "U1234",
531 "text": "test",
532 "thread_ts": "1493305433.915644",
533 "reply_count": 2,
534 "replies": [
535 {
536 "user": "U5678",
537 "ts": "1493305444.920992"
538 },
539 {
540 "user": "U9012",
541 "ts": "1493305894.133936"
542 }
543 ],
544 "subscribed": true,
545 "last_read": "1493305894.133936",
546 "unread_count": 0,
547 "ts": "1493305433.915644"
548 }`
549
550 func TestChannelRepliesParentMessage(t *testing.T) {
551 message, err := unmarshalMessage(channelRepliesParentMessage)
552 assert.Nil(t, err)
553 assert.NotNil(t, message)
554 assert.Equal(t, "message", message.Type)
555 assert.Equal(t, "U1234", message.User)
556 assert.Equal(t, "test", message.Text)
557 assert.Equal(t, "1493305433.915644", message.ThreadTimestamp)
558 assert.Equal(t, 2, message.ReplyCount)
559 assert.Equal(t, "U5678", message.Replies[0].User)
560 assert.Equal(t, "1493305444.920992", message.Replies[0].Timestamp)
561 assert.Equal(t, "U9012", message.Replies[1].User)
562 assert.Equal(t, "1493305894.133936", message.Replies[1].Timestamp)
563 assert.Equal(t, "1493305433.915644", message.Timestamp)
564 }
565
566 var channelRepliesChildMessage = `{
567 "type": "message",
568 "user": "U5678",
569 "text": "foo",
570 "thread_ts": "1493305433.915644",
571 "parent_user_id": "U1234",
572 "ts": "1493305444.920992"
573 }`
574
575 func TestChannelRepliesChildMessage(t *testing.T) {
576 message, err := unmarshalMessage(channelRepliesChildMessage)
577 assert.Nil(t, err)
578 assert.NotNil(t, message)
579 assert.Equal(t, "message", message.Type)
580 assert.Equal(t, "U5678", message.User)
581 assert.Equal(t, "foo", message.Text)
582 assert.Equal(t, "1493305433.915644", message.ThreadTimestamp)
583 assert.Equal(t, "U1234", message.ParentUserId)
584 assert.Equal(t, "1493305444.920992", message.Timestamp)
585 }
586
528587 var groupJoinMessage = `{
529588 "type": "message",
530589 "subtype": "group_join",