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 ¶
New creates a Slack API client with optional configuration.
Options can be used to set headers or disable TLS verification.
func NewWithToken ¶
NewWithToken returns a Slack client configured with the given bearer token.
Options can be passed to customize behavior (e.g. headers, TLS).
- token: Slack API token for authentication.
- opts: Optional functional options (e.g. WithInsecureTLS, WithHeaders).
func (*Client) Send ¶
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 Option ¶ added in v0.9.4
type Option func(*Client)
Option configures a Slack client.
func WithHeaders ¶ added in v0.9.4
WithHeaders sets additional HTTP headers for the Slack client.
func WithInsecureTLS ¶ added in v0.9.4
WithInsecureTLS sets whether to skip TLS certificate verification.
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.