slacker

package module
v0.0.0-...-d0953d3 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2022 License: MIT Imports: 2 Imported by: 0

README

Slacker

Simple Slack block builder

Usage

package main

import . "github.com/snpkx/slacker"

func main() {
	blocks := Blocks(
		Section(WithTextObj(Pt("Hello, world!"))),
		Section(WithFields(Pt("left"), Pt("right"))),
		OptionInput(
			Input("blockId", "actionId", WithLabel("Choose one")),
			WithOptionStrings("A", "B", "C"),
			WithOptionPlaceholder("alphabets..."),
		),
	)
}
package main

import . "github.com/snpkx/slacker"

type Metadata struct {
	Stage int
}

func main() {
	metadata := Metadata{
		Stage: 1,
	}
	request := ModalViewRequest(
		Pt("title"), nil, Pt("close"),
		Blocks(
			Section(WithTextObj(Pt("text"))),
		),
		WithJsonPrivateMetadata(metadata),
	)
}

Helper

Pt

Same as slack.NewTextBlockObject(slack.PlainTextType, text, false, false)

Mt

Same as slack.NewTextBlockObject(slack.MarkdownType, text, false, false)

DSL

Blocks

Run slack block providers and merge blocks into slack.Blocks

Blocks(
	Section(WithTextObj(Pt("text"))),
	Section(WithTextObj(Pt("text")))
)
OrBlock

Select block based on condition

// Pt("true") will return
OrBlock(true, Pt("true"), Pt("false"))
OrFuncBlock

Same as above but condition is function.

OrFuncBlock(func() {
	return random.Intn(100) & 1 == 0
}, Pt("Even"), Pt("Odd"))
ModalViewRequest

Build slack.ModalViewRequest

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Blocks

func Blocks(providers ...SlackBlockBuilderProvider) slack.Blocks

Blocks executes SlackBlockBuilderProvider and merges blocks into slack.Blocks

func ModalViewRequest

func ModalViewRequest(
	title, submit, close *slack.TextBlockObject,
	blocks slack.Blocks,
	options ...ModalOptions,
) slack.ModalViewRequest

func Mt

func Mt(text string, options ...TextBlockObjectOption) *slack.TextBlockObject

Mt is helper function for slack.MarkdownType

func Pt

func Pt(text string, options ...TextBlockObjectOption) *slack.TextBlockObject

Pt is helper function for slack.PlainTextType

Types

type BlockAction

type BlockAction struct {
	slack.BlockAction
}

func (*BlockAction) SelectedOption

func (b *BlockAction) SelectedOption() string

type InputBuilderOption

type InputBuilderOption func(*inputBuilder)

func Input

func Input(blockId, actionId string, options ...InputBuilderOption) InputBuilderOption

func WithHint

func WithHint(text string) InputBuilderOption

func WithLabel

func WithLabel(text string) InputBuilderOption

type ModalOptions

type ModalOptions = func(*slack.ModalViewRequest)

func WithJsonPrivateMetadata

func WithJsonPrivateMetadata(privateMetadata interface{}) ModalOptions

func WithPrivateMetadata

func WithPrivateMetadata(privateMetadata string) ModalOptions

type OptionInputBuilderOption

type OptionInputBuilderOption = func(*optionInputBuilder)

func WithOptionInputOptions

func WithOptionInputOptions(options []*slack.OptionBlockObject) OptionInputBuilderOption

func WithOptionPlaceholder

func WithOptionPlaceholder(placeholder string) OptionInputBuilderOption

func WithOptionStrings

func WithOptionStrings(options ...string) OptionInputBuilderOption

type PlainTextInputBuilderOption

type PlainTextInputBuilderOption = func(*plainTextInputBuilder)

func WithPlainTextPlaceholder

func WithPlainTextPlaceholder(placeholder string) PlainTextInputBuilderOption

type SectionBlockBuilderOption

type SectionBlockBuilderOption = func(*sectionBlockBuilder)

func WithAccessory

func WithAccessory(accessory *slack.Accessory) SectionBlockBuilderOption

func WithFields

func WithFields(fields ...*slack.TextBlockObject) SectionBlockBuilderOption

func WithSectionOptions

func WithSectionOptions(options ...slack.SectionBlockOption) SectionBlockBuilderOption

type SlackBlockBuilder

type SlackBlockBuilder interface {
	Build() slack.Block
}

type SlackBlockBuilderProvider

type SlackBlockBuilderProvider func() SlackBlockBuilder

func OrBlock

func OrBlock(condition bool, trueBlock, falseBlock SlackBlockBuilderProvider) SlackBlockBuilderProvider

func OrFuncBlock

func OrFuncBlock(condition func() bool, trueBlock, falseBlock SlackBlockBuilderProvider) SlackBlockBuilderProvider

type TextBlockObjectOption

type TextBlockObjectOption int
const (
	WithEmoji TextBlockObjectOption = iota
	WithVerbatim
)

type Viewer

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

func NewViewer

func NewViewer(view *slack.View) Viewer

func (*Viewer) Value

func (v *Viewer) Value(blockId, actionId string) *BlockAction

Jump to

Keyboard shortcuts

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