Debian Codegraph @

examples/messages/messages.go

raw symbols SCIP
1 package main
2
3 import (
4 "fmt"
5
6 "github.com/slack-go/slack"
7 )
8
9 func main() {
10 api := slack.New("YOUR_TOKEN_HERE")
11 attachment := slack.Attachment{
12 Pretext: "some pretext",
13 Text: "some text",
14 // Uncomment the following part to send a field too
15 /*
16 Fields: []slack.AttachmentField{
17 slack.AttachmentField{
18 Title: "a",
19 Value: "no",
20 },
21 },
22 */
23 }
24
25 channelID, timestamp, err := api.PostMessage(
26 "CHANNEL_ID",
27 slack.MsgOptionText("Some text", false),
28 slack.MsgOptionAttachments(attachment),
29 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
30 )
31 if err != nil {
32 fmt.Printf("%s\n", err)
33 return
34 }
35 fmt.Printf("Message successfully sent to channel %s at %s", channelID, timestamp)
36 }