-
Notifications
You must be signed in to change notification settings - Fork 13
/
slack_go.go
42 lines (32 loc) · 951 Bytes
/
slack_go.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
package slack
import (
"fmt"
"github.com/slack-go/slack"
)
type APIClient struct {
clients map[string]*slack.Client
errorChannel string
devPanelURL string
}
func NewSlackGo(botTokens map[string]string, errorChannel, devPanelURL string) *APIClient {
clients := make(map[string]*slack.Client)
for name, token := range botTokens {
clients[name] = slack.New(token)
}
return &APIClient{clients: clients, errorChannel: errorChannel, devPanelURL: devPanelURL}
}
func (s *APIClient) GetDevPanelURL() string {
return s.devPanelURL
}
func (s *APIClient) GetErrorChannel() string {
return s.errorChannel
}
func (s *APIClient) SendToChannel(botName, channelName, message string, opt ...slack.MsgOption) error {
client, ok := s.clients[botName]
if !ok {
return fmt.Errorf(`bot "%s" not defined`, botName)
}
opt = append(opt, slack.MsgOptionText(message, true))
_, _, err := client.PostMessage(channelName, opt...)
return err
}