Skip to content

mnkd/slackposter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  • Notify GitHub Site Status to Slack incoming webhook.

github-status

  • Notify GitHub pull requests to Slack incoming webhook.
  • Qiita:Team (Qiita) の n 年前の今日の記事を Slack の Incoming webhook へ post する。

qiiotd

About

Post a message to your Slack incoming webhook

Resources

License

Stars

Watchers

Forks

Packages

No packages published