-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslack.go
More file actions
31 lines (29 loc) · 866 Bytes
/
slack.go
File metadata and controls
31 lines (29 loc) · 866 Bytes
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
package main
import (
"fmt"
"github.com/slack-go/slack"
"github.com/worr/secstring"
"os"
)
func sendSlackMessage(message string) string {
id := os.Getenv("SLACK-CHANNEL")
token := os.Getenv("SLACK-TOKEN")
ss, _ := secstring.FromString(&token)
defer ss.Destroy()
api := slack.New(string(ss.String))
channelID, timestamp, err := api.PostMessage(id, slack.MsgOptionText(message, false))
if err != nil {
fmt.Printf("%s\n", err)
return ""
}
fmt.Printf("Message successfully sent to channel %s at %s", channelID, timestamp)
return fmt.Sprintf("%s", timestamp)
}
func editSlackMessage(tstamp string, message string) {
id := os.Getenv("SLACK-CHANNEL")
token := os.Getenv("SLACK-TOKEN")
ss, _ := secstring.FromString(&token)
defer ss.Destroy()
api := slack.New(string(ss.String))
api.UpdateMessage(id, tstamp, slack.MsgOptionText(message, false))
}