slack

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	Color string `json:"color"` // Color is the left border color of the attachment.
	Text  string `json:"text"`  // Text is the body content of the attachment.
	Title string `json:"title"` // Title is the heading text of the attachment.
}

Attachment represents a visual block attached to a Slack message.

type Client

type Client struct {
	HttpClient utils.HTTPDoer // HttpClient is used to send HTTP requests (mockable for testing).
}

Client sends Slack messages using the official chat.postMessage API.

func New

func New(headers map[string]string, skipTLS bool) *Client

New creates a new Slack API client with optional headers and TLS settings.

Parameters:

  • headers: Custom HTTP headers, including the Authorization bearer token.
  • skipTLS: Whether to skip TLS certificate validation.

Returns:

  • *Client: A configured Slack client implementing the Sender interface.

func NewWithToken

func NewWithToken(token string, skipTLS bool) *Client

NewWithToken returns a Slack API client using the provided bearer token.

Parameters:

  • token: Slack API token to use for authentication.
  • skipTLS: If true, disables TLS certificate verification.

Returns:

  • *Client: A configured Slack client ready to send messages.

func (*Client) Send

func (c *Client) Send(ctx context.Context, slackMessage Slack) (*Response, error)

Send posts a message to the Slack chat.postMessage endpoint.

Parameters:

  • ctx: Context to manage request lifetime.
  • slackMessage: Message payload including channel and attachments.

Returns:

  • *Response: Structured API response containing status and errors.
  • error: If sending or decoding fails, or Slack returns a failure.

type Response

type Response struct {
	Ok    bool   `json:"ok"`    // Ok is true if the request was successful.
	Error string `json:"error"` // Error is a human-readable error message, if any.
}

Response represents the structure of a Slack API response.

type Sender

type Sender interface {
	// Send posts a Slack message to the configured API endpoint.
	//
	// Parameters:
	//   - ctx: Context to control timeout or cancellation of the request.
	//   - slackMessage: The structured Slack message payload to send.
	//
	// Returns:
	//   - *Response: The Slack API response object.
	//   - error: Any error that occurred during sending or decoding.
	Send(ctx context.Context, slackMessage Slack) (*Response, error)
}

Sender defines the interface for sending Slack messages.

type Slack

type Slack struct {
	Channel     string       `json:"channel"`     // Channel is the Slack channel where the message will be posted.
	Attachments []Attachment `json:"attachments"` // Attachments is the list of structured message blocks.
}

Slack defines the payload structure for a Slack message.

Jump to

Keyboard shortcuts

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