-
Notifications
You must be signed in to change notification settings - Fork 0
/
slack_history.go
63 lines (50 loc) · 1.07 KB
/
slack_history.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
package slackactivity
import (
"fmt"
"github.com/slack-go/slack"
)
type SlackChannelHistoryClient interface {
GetConversationHistory(params *slack.GetConversationHistoryParameters) (*slack.GetConversationHistoryResponse, error)
}
var _ SlackChannelHistoryClient = &slack.Client{}
const (
getChannelHistoryLimit = 1000
)
func GetChannelHistory(
api SlackChannelHistoryClient,
id string,
) ([]slack.Message, error) {
params := &slack.GetConversationHistoryParameters{
ChannelID: id,
Limit: getChannelHistoryLimit,
Cursor: "",
Inclusive: false,
Latest: "",
Oldest: "",
}
result, err := api.GetConversationHistory(params)
if err != nil {
return nil, fmt.Errorf("GetConversationHistory failed: %w", err)
}
return result.Messages, nil
}
func FilterMessage(
message []slack.Message,
fn func(slack.Message) bool,
) []slack.Message {
count := 0
for _, m := range message {
if fn(m) {
count++
}
}
result := make([]slack.Message, count)
count = 0
for _, m := range message {
if fn(m) {
result[count] = m
count++
}
}
return result
}