slkm

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: MIT Imports: 6 Imported by: 1

README

slkm

slkm is github.com/slack-go/slack wrapper package for posting message.

This package converts channels and mentions of users and user groups into the correct ID notation.

  • #channel-name -> CXXXXXXXX
  • @username -> <@UXXXXXXXX>
  • @usergroup-name -> <!subteam^SXXXXXXXX>

Usage

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/k1LoW/slkm"
	"github.com/slack-go/slack"
)

const (
	notifyChannel = "#service-alerts"
)

func main() {
	ctx := context.Background()
	c, err := slkm.New()
	if err != nil {
		log.Fatal(err)
	}
	c.SetUsername("wakeup-bot")
	blocks := []slack.Block{
		slack.NewSectionBlock(slack.NewTextBlockObject("mrkdwn", "Wake up @k1low !!", false, false), nil, nil),
	}
	if err := c.PostMessage(ctx, notifyChannel, blocks...); err != nil {
		log.Fatal(err)
	}
}

Required scope of SLACK_API_TOKEN

  • channel:read
  • chat:write
  • chat:write.public
  • users:read
  • usergroups:read
  • chat:write.customize ( optional )

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New() (*Client, error)

func (*Client) CreateMentionLinkFromName added in v0.3.0

func (c *Client) CreateMentionLinkFromName(ctx context.Context, name string) (string, error)

CreateMentionLinkFromName create mention link ( `<@UXXXXXXX>` ) from mention ( `@k1low` )

func (*Client) FindChannelIDByName added in v0.3.0

func (c *Client) FindChannelIDByName(ctx context.Context, channel string) (string, error)

FindChannelIDByName find Channel ID ( `CXXXXXXX` ) by channel name ( `#general` )

func (*Client) PostMessage

func (c *Client) PostMessage(ctx context.Context, channel string, blocks ...slack.Block) error

PostMessage to Slack channel

func (c *Client) ReplaceMentionsToMentionLinks(ctx context.Context, in string) string

ReplaceMentionsToMentionLinks replace mentions ( `@k1low` ) to mention links ( `<@UXXXXXXX>` )

func (*Client) SetIconEmoji added in v0.2.0

func (c *Client) SetIconEmoji(emoji string)

func (*Client) SetIconURL added in v0.2.0

func (c *Client) SetIconURL(u string)

func (*Client) SetToken added in v0.3.0

func (c *Client) SetToken(token string)

func (*Client) SetUsername added in v0.2.0

func (c *Client) SetUsername(username string)

func (*Client) SetWebhookURL added in v0.3.0

func (c *Client) SetWebhookURL(url string)

func (*Client) SlackClient added in v0.3.0

func (c *Client) SlackClient() *slack.Client

Jump to

Keyboard shortcuts

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