v1

package
v0.0.0-release-12.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2026 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const FullValidConfigForTesting = `` /* 417-byte string literal not displayed */

FullValidConfigForTesting is a string representation of a JSON object that contains all fields supported by the notifier Config. It can be used without secrets.

View Source
const FullValidSecretsForTesting = `{
	"url": "http://localhost/url-secret",
	"token": "test-secret-token"
}`

FullValidSecretsForTesting is a string representation of JSON object that contains all fields that can be overridden from secrets

View Source
const Version = schema.V1

Variables

View Source
var APIURL = "https://slack.com/api/chat.postMessage"

APIURL of where the notification payload is sent. It is public to be overridable in integration tests.

View Source
var Schema = schema.IntegrationSchemaVersion{
	Version:   Version,
	CanCreate: true,
	Options: []schema.Field{
		{
			Label:        "Recipient",
			Element:      schema.ElementTypeInput,
			InputType:    schema.InputTypeText,
			Description:  "Specify channel, private group, or IM channel (can be an encoded ID or a name) - required unless you provide a webhook",
			PropertyName: "recipient",
			Required:     true,
			DependsOn:    "url",
		},

		{
			Label:        "Token",
			Element:      schema.ElementTypeInput,
			InputType:    schema.InputTypeText,
			Description:  "Provide a Slack API token (starts with \"xoxb\") - required unless you provide a webhook",
			PropertyName: "token",
			Secure:       true,
			Required:     true,
			DependsOn:    "url",
		},
		{
			Label:        "Username",
			Element:      schema.ElementTypeInput,
			InputType:    schema.InputTypeText,
			Description:  "Set the username for the bot's message",
			PropertyName: "username",
		},
		{
			Label:        "Icon emoji",
			Element:      schema.ElementTypeInput,
			InputType:    schema.InputTypeText,
			Description:  "Provide an emoji to use as the icon for the bot's message. Overrides the icon URL.",
			PropertyName: "icon_emoji",
		},
		{
			Label:        "Icon URL",
			Element:      schema.ElementTypeInput,
			InputType:    schema.InputTypeText,
			Description:  "Provide a URL to an image to use as the icon for the bot's message",
			PropertyName: "icon_url",
		},
		{
			Label:        "Mention Users",
			Element:      schema.ElementTypeInput,
			InputType:    schema.InputTypeText,
			Description:  "Mention one or more users (comma separated) when notifying in a channel, by ID (you can copy this from the user's Slack profile)",
			PropertyName: "mentionUsers",
		},
		{
			Label:        "Mention Groups",
			Element:      schema.ElementTypeInput,
			InputType:    schema.InputTypeText,
			Description:  "Mention one or more groups (comma separated) when notifying in a channel (you can copy this from the group's Slack profile URL)",
			PropertyName: "mentionGroups",
		},
		{
			Label:   "Mention Channel",
			Element: schema.ElementTypeSelect,
			SelectOptions: []schema.SelectOption{
				{
					Value: "",
					Label: "Disabled",
				},
				{
					Value: "here",
					Label: "Every active channel member",
				},
				{
					Value: "channel",
					Label: "Every channel member",
				},
			},
			Description:  "Mention whole channel or just active members when notifying",
			PropertyName: "mentionChannel",
		},
		{
			Label:        "Webhook URL",
			Element:      schema.ElementTypeInput,
			InputType:    schema.InputTypeText,
			Description:  "Optionally provide a Slack incoming webhook URL for sending messages, in this case the token isn't necessary",
			Placeholder:  "Slack incoming webhook URL",
			PropertyName: "url",
			Secure:       true,
			Required:     true,
			DependsOn:    "token",
			Protected:    true,
		},
		{
			Label:        "Endpoint URL",
			Element:      schema.ElementTypeInput,
			InputType:    schema.InputTypeText,
			Description:  "Optionally provide a custom Slack message API endpoint for non-webhook requests, default is https://slack.com/api/chat.postMessage",
			Placeholder:  "Slack endpoint url",
			PropertyName: "endpointUrl",
			Protected:    true,
		},
		{
			Label:        "Color",
			Element:      schema.ElementTypeInput,
			InputType:    schema.InputTypeText,
			Description:  "Templated color of the slack message",
			Placeholder:  templates.DefaultMessageColor,
			PropertyName: "color",
		},
		{
			Label:        "Title",
			Element:      schema.ElementTypeInput,
			InputType:    schema.InputTypeText,
			Description:  "Templated title of the slack message",
			PropertyName: "title",
			Placeholder:  `{{ template "slack.default.title" . }}`,
		},
		{
			Label:        "Text Body",
			Element:      schema.ElementTypeTextArea,
			Description:  "Body of the slack message",
			PropertyName: "text",
			Placeholder:  `{{ template "slack.default.text" . }}`,
		},
		{
			Label:        "Footer",
			Element:      schema.ElementTypeInput,
			InputType:    schema.InputTypeText,
			Description:  "Templated footer of the slack message",
			PropertyName: "footer",
			Placeholder:  `{{ template "slack.default.footer" . }}`,
		},
	},
}

Functions

This section is empty.

Types

type CommonAPIResponse

type CommonAPIResponse struct {
	OK    bool   `json:"ok"`
	Error string `json:"error,omitempty"`
}

generic api response from slack

type CompleteFileUploadRequest

type CompleteFileUploadRequest struct {
	Files []struct {
		ID string `json:"id"`
	} `json:"files"`
	ChannelID      string `json:"channel_id"`
	ThreadTs       string `json:"thread_ts"`
	InitialComment string `json:"initial_comment"`
}

type Config

type Config struct {
	EndpointURL    string                          `json:"endpointUrl,omitempty" yaml:"endpointUrl,omitempty"`
	URL            string                          `json:"url,omitempty" yaml:"url,omitempty"`
	Token          string                          `json:"token,omitempty" yaml:"token,omitempty"`
	Recipient      string                          `json:"recipient,omitempty" yaml:"recipient,omitempty"`
	Text           string                          `json:"text,omitempty" yaml:"text,omitempty"`
	Title          string                          `json:"title,omitempty" yaml:"title,omitempty"`
	Username       string                          `json:"username,omitempty" yaml:"username,omitempty"`
	IconEmoji      string                          `json:"icon_emoji,omitempty" yaml:"icon_emoji,omitempty"`
	IconURL        string                          `json:"icon_url,omitempty" yaml:"icon_url,omitempty"`
	MentionChannel string                          `json:"mentionChannel,omitempty" yaml:"mentionChannel,omitempty"`
	MentionUsers   receivers.CommaSeparatedStrings `json:"mentionUsers,omitempty" yaml:"mentionUsers,omitempty"`
	MentionGroups  receivers.CommaSeparatedStrings `json:"mentionGroups,omitempty" yaml:"mentionGroups,omitempty"`
	Color          string                          `json:"color,omitempty" yaml:"color,omitempty"`
	Footer         string                          `json:"footer,omitempty" yaml:"footer,omitempty"`
}

func NewConfig

func NewConfig(jsonData json.RawMessage, decryptFn receivers.DecryptFunc) (Config, error)

type FileUploadURLResponse

type FileUploadURLResponse struct {
	UploadURL string `json:"upload_url"`
	FileID    string `json:"file_id"`
}

the response to get the URL to upload a file to (files.getUploadURLExternal)

type Notifier

type Notifier struct {
	*receivers.Base
	// contains filtered or unexported fields
}

Notifier is responsible for sending alert notification to Slack.

func New

func New(cfg Config, meta receivers.Metadata, template *templates.Template, sender receivers.WebhookSender, images images.Provider, logger log.Logger, appVersion string) *Notifier

func (*Notifier) Notify

func (sn *Notifier) Notify(ctx context.Context, alerts ...*types.Alert) (bool, error)

Notify sends an alert notification to Slack.

func (*Notifier) SendResolved

func (sn *Notifier) SendResolved() bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL