Skip to content

Instantly share code, notes, and snippets.

@danrl
Created February 27, 2018 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danrl/a0bcde1892a0877cbd80c072a240ca7c to your computer and use it in GitHub Desktop.
Save danrl/a0bcde1892a0877cbd80c072a240ca7c to your computer and use it in GitHub Desktop.
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