forked from slack-go/slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages.go
36 lines (32 loc) · 825 Bytes
/
messages.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
package main
import (
"fmt"
"github.com/slack-go/slack"
)
func main() {
api := slack.New("YOUR_TOKEN_HERE")
attachment := slack.Attachment{
Pretext: "some pretext",
Text: "some text",
// Uncomment the following part to send a field too
/*
Fields: []slack.AttachmentField{
slack.AttachmentField{
Title: "a",
Value: "no",
},
},
*/
}
channelID, timestamp, err := api.PostMessage(
"CHANNEL_ID",
slack.MsgOptionText("Some text", false),
slack.MsgOptionAttachments(attachment),
slack.MsgOptionAsUser(true), // Add this if you want that the bot would post message as a user, otherwise it will send response using the default slackbot
)
if err != nil {
fmt.Printf("%s\n", err)
return
}
fmt.Printf("Message successfully sent to channel %s at %s", channelID, timestamp)
}