Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

README.md

skackposter

Godoc Reference

Post a payload to your Slack incoming webhook.

Usage

You can send a simple message.

package main

import (
	"github.com/mnkd/slackposter"
)

func main() {
    config := slackposter.Config{
        "#channel_name or channel_id",
        ":ghost:",
        "Ghost",
        "https://hooks.slack.com/services/xxxx/xxx/xxx",
    }

    slack := slackposter.NewSlack(config)
    slack.PostMessage("Hello world!")
}

message

You can send a customized message (payload).

package main

import (
	"time"

	slack "github.com/mnkd/slackposter"
)

func main() {
	config := slack.Config{
		Channel:    "#your-channel",
		IconEmoji:  ":octocat:",
		Username:   "GitHub | Status",
		WebhookURL: "https://hooks.slack.com/services/xxx/xxx/xxx",
	}

	poster := slack.NewSlackPoster(config)

	payload := poster.NewPayload()
	payload.Mrkdwn = true

	statusField := slack.Field{
		Title: "Status",
		Value: "Good",
		Short: true,
	}

	dateString := time.Now().Format("2006-01-02 15:04")
	dateField := slack.Field{
		Title: "Date",
		Value: dateString,
		Short: true,
	}

	attachment := slack.Attachment{
		Fallback: "GitHub Status: Good - https://status.github.com",
		Text:     "<https://status.github.com/|GitHub Status> : *Good*",
		Color:    "good",
		Fields:   []slack.Field{statusField, dateField},
		MrkdwnIn: []string{"text"},
	}

	payload.Attachments = []slack.Attachment{attachment}

	poster.PostPayload(payload)
}

payload

I would recommend you read Attaching content and links to messages | Slack.

Example Apps

github-status

  • Notify GitHub Site Status to Slack incoming webhook.

github-status

prnotify

  • Notify GitHub pull requests to Slack incoming webhook.

qiiotd

  • Qiita:Team (Qiita) の n 年前の今日の記事を Slack の Incoming webhook へ post する。

qiiotd

About

Post a message to your Slack incoming webhook

Resources

License

Packages

No packages published
You can’t perform that action at this time.