Skip to content

Go library for posting messages to incoming webhooks in Slack.

License

Notifications You must be signed in to change notification settings

PromptBit/slack-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

slack-go

A (very simple) Go library for posting messages to incoming webhooks in Slack.

You will need to set up a Slack App with an incoming webhook URL; see the developer documentation for details.

Example

package main

import "github.com/PromptBit/slack-go/slack"

func main() {
	webhookURL := "<add url here>"

	err := slack.PostToWebhook(webhookURL, slack.Message{
		Text: "Error occurred with /some/endpoint",
		Blocks: []slack.Block{
			{
				Type: slack.BlockTypeHeader,
				Text: &slack.Text{
					Type:  slack.TextTypePlainText,
					Text:  ":warning: Error occurred with /some/endpoint",
					Emoji: true,
				},
			},
			{
				Type: slack.BlockTypeSection,
				Text: &slack.Text{
					Type: slack.TextTypePlainText,
					Text: "runtime error: invalid memory address or nil pointer dereference",
				},
			},
			{
				Type: slack.BlockTypeSection,
				Text: &slack.Text{
					Type: slack.TextTypeMarkdown,
					Text: "*Stacktrace*\n```stacktrace would go here...```",
				},
			},
		},
	})

	if err != nil {
		panic(err)
	}
}

That code will result in the following being posted to Slack:

Screenshot of sent message

For more formatting options, refer to the blocks reference and Block Kit Builder.

About

Go library for posting messages to incoming webhooks in Slack.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages