/
main.go
45 lines (42 loc) · 953 Bytes
/
main.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
package main
import (
"log"
"os"
"time"
"github.com/int128/slack"
)
func main() {
webhook := os.Getenv("SLACK_WEBHOOK")
if webhook == "" {
log.Fatalf("Run with environment variable SLACK_WEBHOOK=https://hooks.slack.com/services/...")
}
message := slack.Message{
Username: "mybot",
IconEmoji: ":star:",
Text: "Hello World!",
Attachments: []slack.Attachment{
{
Title: "ALERT",
Text: "Hello World!",
AuthorName: "@author",
AuthorLink: "https://www.example.com",
Footer: "Footer",
Color: "danger",
Timestamp: time.Now().Unix(),
Actions: []slack.AttachmentAction{
{
Type: "button",
Text: "Detail",
URL: "https://www.example.com",
Style: "danger",
},
},
},
},
}
err := slack.Send(webhook, &message)
if err != nil {
log.Fatalf("Could not send the message to Slack: %s", err)
}
log.Printf("Sent the message %+v", message)
}