Categorygithub.com/tommzn/go-slack
repositorypackage
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