Created
February 27, 2018 15:55
-
-
Save danrl/a0bcde1892a0877cbd80c072a240ca7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"io/ioutil" | |
"log" | |
"os" | |
"github.com/nlopes/slack" | |
) | |
const ( | |
// fetch API key from your slack workspace | |
apiKey = "xxxx-xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx" | |
) | |
func main() { | |
channelID := flag.String("channel-id", "C85PT1ULR", | |
"ID of the channel to post too") | |
title := flag.String("title", "Message", | |
"Title for the message to post") | |
flag.Parse() | |
bytes, err := ioutil.ReadAll(os.Stdin) | |
if err != nil { | |
log.Fatalf("read stdin: %v", err) | |
} | |
if len(bytes) < 1 { | |
log.Fatalf("stdin is empty") | |
} | |
report := string(bytes) | |
params := slack.PostMessageParameters{ | |
AsUser: true, | |
Attachments: []slack.Attachment{ | |
{ | |
Color: "#FFA500", | |
Fields: []slack.AttachmentField{ | |
{ | |
Title: *title, | |
Value: report, | |
}, | |
}, | |
}, | |
}, | |
} | |
api := slack.New(apiKey) | |
_, _, err = api.PostMessage(*channelID, "", params) | |
if err != nil { | |
log.Fatalf("post report: %v", err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment