Categorygithub.com/tommzn/go-slack
modulepackage
1.0.0
Repository: https://github.com/tommzn/go-slack.git
Documentation: pkg.go.dev

# README

Go Reference GitHub go.mod Go version GitHub release (latest by date) Go Report Card Actions Status

Slack Client

A simple client to send messages to channels in Slack.

Example

package main

import {
    "fmt"

    slack "github.com/tommzn/go-slack"
}

func main() {

    client := slack.New()
    header := "Greeting!"
    channel := "<ChannelId>"

    // Send a message with header to a channel
    if err := client.SendToChannel("Hello Slack", channel, &header); err != nil {
        fmt.Println(err)
    }
    
    // Set default channel
    client.WithChannel(channel)
    // Send a message to default channel, including a header.
    if err := client.Send("Hello Slack", &header); err != nil {
        fmt.Println(err)
    }

    // Send a message without a header
    if err := client.Send("Hello Slack", nil); err != nil {
        fmt.Println(err)
    }
}

Auth Token

Each request to Slack Web API needs an auth token. This client expects an auth token provided by env variable SLACK_TOKEN. As an alternative you pass a SecretsManager to NewFromConfig to obtain a token from different sources.

Config

A default channel can be provided by config. See https://github.com/tommzn/go-config.

Example Config File

Following config file defines "Channel05" as default channel.


slack:
  channel: Channel05

# Functions

New will return a client to send messages to Slack.
NewFromConfig returns a client to send messages to Slack.

# Constants

SLACK_POST_MESSAGE_API
SLACK_POST_MESSAGE_API is the endpoint provides by Slack's web api to send messages.
SLACK_TOKEN is used to obtain an auth token from environment or if available by assigned secrets mananger.

# Structs

Client is used to send messages to Slack using it's web api.