Help us shape the future of Go! Take the 2026 Go Developer Survey

chat

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package chat is the notify adapters for chat platforms that take an incoming webhook: Slack, Microsoft Teams and Discord (R-374, issue #50).

Each posts to one channel, named by a webhook URL an administrator creates in the platform, so each is a channel adapter: it ignores recipients, and only event subscriptions send to it (R-373). A message meant for one person never lands in a room.

The webhook URL is the credential. Whoever holds it can post to the channel, so it is stored sealed like any adapter credential and never shown again (R-190).

Index

Constants

This section is empty.

Variables

View Source
var Discord = Platform{
	Kind:        "discord",
	Name:        "Discord",
	Description: "Posts the events a subscription chooses to a Discord channel, through a channel webhook.",
	IDPrefix:    "ntf_",
	Placeholder: "https://discord.com/api/webhooks/…",
	Help:        "The webhook URL from the server's Integrations settings.",
	Hosts:       []string{"discord.com", "discordapp.com"},
	Steps:       discordSteps(),
	Format:      discordMessage,
}

Discord posts to a Discord channel webhook.

View Source
var Slack = Platform{
	Kind:        "slack",
	Name:        "Slack",
	Description: "Posts the events a subscription chooses to a Slack channel, through an incoming webhook.",
	IDPrefix:    "ntf_",
	Placeholder: "https://hooks.slack.com/services/…",
	Help:        "The incoming webhook URL Slack gives you for the channel.",
	Hosts:       []string{"hooks.slack.com", "hooks.slack-gov.com"},
	Steps:       slackSteps(),
	Format:      func(n api.Notification) any { return SlackMessage(n) },
}

Slack posts to a Slack incoming webhook.

View Source
var Teams = Platform{
	Kind:        "teams",
	Name:        "Microsoft Teams",
	Description: "Posts the events a subscription chooses to a Microsoft Teams channel, as an adaptive card, through a Workflows webhook.",
	IDPrefix:    "ntf_",
	Placeholder: "https://….environment.api.powerplatform.com/powerautomate/automations/direct/workflows/…",
	Help:        "The webhook URL of a Send webhook alerts to a channel workflow.",
	Steps:       teamsSteps(),

	Hosts: []string{
		"api.powerplatform.com",
		"api.gov.powerplatform.microsoft.us",
		"api.high.powerplatform.microsoft.us",
		"api.appsplatform.us",
		"api.powerplatform.partner.microsoftonline.cn",
		"logic.azure.us",
		"logic.azure.cn",
	},

	Retired: map[string]string{
		"webhook.office.com": "Microsoft retired Office 365 connector webhooks in Teams on May 22, 2026. Create a workflow from the Send webhook alerts to a channel template and copy its URL.",
		"logic.azure.com":    "Microsoft retired Teams workflow URLs on logic.azure.com on November 30, 2025. Open the workflow in Power Automate and copy the new URL from its trigger.",
	},
	Format: teamsMessage,
}

Teams posts to a Microsoft Teams channel through a Workflows webhook.

Functions

func SlackMessage added in v0.11.0

func SlackMessage(n api.Notification) map[string]any

SlackMessage lays a notification out as a Slack message: text for the phone notification, blocks for the message itself. Used by the Slack adapter too.

Types

type Adapter

type Adapter struct {
	notifykit.Unconnected
	// contains filtered or unexported fields
}

Adapter posts to one channel.

func New

func New(p Platform) *Adapter

New returns an unconfigured adapter for platform.

func (*Adapter) Capabilities

func (a *Adapter) Capabilities() api.NotifyCapabilities

Capabilities: a channel, not people.

func (*Adapter) Category

func (a *Adapter) Category() api.Category

func (*Adapter) Configure

func (a *Adapter) Configure(_ context.Context, raw json.RawMessage) error

Configure reads the configuration core assembled, credentials included.

func (*Adapter) HealthCheck

func (a *Adapter) HealthCheck(context.Context) error

HealthCheck succeeds once configured. It does not post: a health check that sends a message to a channel every five minutes would be the outage.

func (*Adapter) Kind

func (a *Adapter) Kind() string

func (*Adapter) Notify

func (a *Adapter) Notify(ctx context.Context, n api.Notification) error

Notify posts one message.

type Config

type Config struct {
	Credentials    Credentials `json:"credentials,omitzero"`
	TimeoutSeconds int         `json:"timeout_seconds,omitempty"`
}

Config is the adapter's configuration.

type Credentials

type Credentials struct {
	WebhookURL secret.Value `json:"webhook_url,omitzero"`
}

Credentials is what this adapter keeps secret.

type Platform

type Platform struct {
	Kind        string
	Name        string
	Description string
	IDPrefix    string
	Placeholder string
	Help        string

	// Hosts are the hosts a webhook URL for the platform is on. A URL on
	// another host is refused at configuration, because a webhook URL pasted
	// into the wrong platform's form fails at the first event otherwise.
	// Empty accepts any host.
	Hosts []string

	// Retired are hosts the platform once issued webhook URLs on and no
	// longer serves, each with what to do instead. A URL on one is refused
	// with that remedy rather than the generic wrong-platform message.
	Retired map[string]string
	// Steps walk someone through making the webhook (api.KindInfo.Steps).
	Steps []api.Step

	Format func(n api.Notification) any
}

Platform is what differs between the three: a name, and how a notification is laid out.

func (Platform) Info

func (p Platform) Info() api.KindInfo

Info describes the platform's adapter for the forms that configure one.

Jump to

Keyboard shortcuts

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