loafer

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

README

Loafer

Note:

This is a quick library to help with my development work at Nike Inc, please check the supported features before you use.
Feel free to fork and add your features if needed

A Simple Slack App library to help you quickly spin up Slack Apps that are capable of app distribution and signature checking without the hassle.

  • All command, interactions, events endpoints are secured with slack signature checking.
  • App distribution is automatically enabled, howered, you need to handle the token storage by using the OnAppInstall function
  • You can enable custom routes if needed, such as for external select inputs for slack, or for your other service needs

Supported Features

  • Block Kit UI:
    • Button - Action
    • Text Section
    • Text Fields
    • Modal
    • Actions
    • Plain Text Input
    • (multi/single) Static Select Input
    • (multi/single) External Select Input
    • Multi-Conversation Select Input
    • (multi/single) User Select Input
    • Date Picker Input
    • Time Picker Input
    • Radio Input
    • Checkbox Input
    • Header
    • Context
    • Image
    • Divider
  • Slack API:
    • Open View
    • Update View
    • Find User by Email
    • Find User by Slack ID
    • Update Message
    • Post Message
    • File upload

Slack Context

All handlers are functions with the loafer.SlackContext parameter passed to it, and the format is as followed:

type SlackContext struct {
	Body      []byte              // Body of the request
	Token     string              // Token of the corresponding workspace
	Workspace string              // Workspace where event is coming from
	Req       *http.Request       // http request
	Res       http.ResponseWriter // http response
}

To Start an App

package main

// TokenCache - Implementation of the loafer.TokensCache interface, this allows you to control how you store/access your tokens
type TokenCache struct {
	tokens map[string]string
}

// Get - Getting the token for the corresponding workspace
func (t *TokenCache) Get(workspace string) string {
	return t.tokens[workspace]
}

// Set - Setting the token for the corresponding workspace
func (t *TokenCache) Set(workspace string, token string) {
	t.tokens[workspace] = token
}

// Remove - Removing the token for the corresponding workspace
func (t *TokenCache) Remove(workspace string) {
	delete(t.tokens, workspace)
}

// main - entrypoint of program
func main {
  // Initialize an instance of the TokenCache
	myTokenCache := TokenCache{
		tokens: make(map[string]string)}
  
  // Set up the options for the slack app, clientId & client secret is not needed if you don't need app distribution
	opts := loafer.SlackAppOptions{
		Name:          "Dev Bot",
		Prefix:        "dev",
		TokensCache:   &myTokenCache,
		SigningSecret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
		ClientID:      "xxxxxxxxxxxx.xxxxxxxxxx",
		ClientSecret:  "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
    
  // Initialize your Slack App with the options
	app := loafer.InitializeSlackApp(&opts)
  
  // Add handler to command /coaching
	app.OnCommand("/coaching", handleDevCommand)
  
  // Serve the app on PORT 8080, you can use callback here if needed
	app.ServeApp(8080, nil)
}

App will now serve on the route:

http://0.0.0.0:8080/{prefix}/install - For app distribution http://0.0.0.0:8080/{prefix}/events - For event subscription http://0.0.0.0:8080/{prefix}/commands - For app commands http://0.0.0.0:8080/{prefix}/interactions - For app interactions http://0.0.0.0:8080/{prefix}/${custom_route_pattern} - For app custom routes

API Reference

App

InitializeSlackApp(opts *SlackAppOptions) SlackApp

Returns:

  • app SlackApp

Get an instance of a slack app with options:

  • Name - Name of slack app
  • Prefix - Prefix of slack app route
  • TokensCache - Token cache that implemented the TokensCache interface from loafer
  • ClientSecret - Client secret of slack app, used for app distribution
  • ClientID - Client ID of slack app, used for app distribution
  • SigningSecret - Signning secret for slack app, used for slack request verification
ServeApp(port uint16, cb func())

Serve Slack app on port and cb when server first starts

Close(ctx context.Context)

Shutdown Slack app

OnCommand(cmd string, handler func(ctx *SlackContext))

Add handler to command

RemoveCommand(cmd string)

Remove handler to command

OnAction(actionID string, handler func(ctx *SlackContext))

Add handler to action

OnShortcut(callbackID string, handler func(ctx *SlackContext))

Add handler to shortcut

OnViewSubmission(callbackID string, handler func(ctx *SlackContext))

Add handler to view submission

OnViewClose(callbackID string, handler, handler func(ctx *SlackContext))

Add handler to view close

OnEvent(eventType string, handler func(ctx *SlackContext))

Add handler to view close

OnError(handler func(res http.ResponseWriter, req *http.Request, err error))

Add handler to errors

OnAppInstall(cb func(installRes *SlackOauth2Response, res http.ResponseWriter, req *http.Request) bool

Returns:

  • avoidDefaultPage bool

handle the app distribute, once app distribution is successfull, it will call the cb function, cb function should return a boolean value.

  • true - you want to use your own html/redirection
  • false - show default installation html page
CustomRoute(pattern string, handler func(res http.ResponseWriter, req *http.Request))

Add handler to a custom pattern

Response(ctx *SlackContext, code int, message []byte, headers map[string]string)

Response back to Slack

ConvertState(state ISlackBlockKitUI, dst interface{})

Response interaction event state to your form state struct type

Slack APIs

OpenView(view SlackModal, triggerID string, token string) error

Returns:

  • err error

Open a modal within slack

UpdateView(view SlackInteractionView, viewID string, token string) error

Returns:

  • err error

Updates a modal within slack

FindUserByEmail(email string, token string) (*SlackUser, error)

Returns:

  • user SlackUser
  • err error

Find a user within the slack workspace

FindUserByID(id string, token string) (*SlackUser, error)

Returns:

  • user SlackUser
  • err error

Find a user within the slack workspace

PostMessage(channel string, blocks ISlackBlockKitUI, text string, token string) error

Returns:

  • err error

Post a message to a slack channel/user/conversation

UpdateMessage(channel string, ts string, blocks ISlackBlockKitUI, text string, token string) error

Returns:

  • err error

Update a message of a slack channel/user/conversation given a time stamp of the original message

FileUpload(channels []string, filename string, content string, filetype string, token string) error

Returns:

  • err error

Upload a file to the Slack workspace and share to the list of channels/users/conversations

Block Kit UIs

MakeSlackButton(text string, value string, actionID string) SlackBlockButton

Returns:

  • button SlackBlockButton

Make a Block Kit Button

MakeSlackTextSection(text string) SlackBlockSection

Returns:

  • section SlackBlockSection

Make a Block Kit text section

MakeSlackTextFieldsSection(texts []string) SlackBlockTextFields

Returns:

  • textField SlackBlockTextFields

Make a Block Kit text field section

MakeSlackModal(title string, callbackID string, blocks ISlackBlockKitUI, submitText string, closeText string, notifyOnClose bool) SlackModal

Returns:

  • modal SlackModal

Make a Block Kit modal

MakeSlackActions(actions ISlackBlockKitUI) SlackBlockActions

Returns:

  • actions SlackBlockActions

Make a Block Kit actions section

MakeSlackModalTextInput(label string, placeholder string, actionID string, isMultiline bool, isDispatch bool, maxLength uint16) SlackInputElement

Returns:

  • input SlackInputElement

Make a Block Kit modal plain text input

MakeSlackModalStaticSelectInput(label string, placeholder string, options []SlackInputOption, initialOption *SlackInputOption, actionID string, isMulti bool, isOptional bool) SlackModalSelect

Returns:

  • select SlackModalSelect

Make a Block Kit modal static select input

MakeSlackModalExternalStaticSelectInput(label string, placeholder string, initialOption *SlackInputOption, actionID string, isMulti bool, minQueryLength uint16, isOptional bool) SlackModalSelect

Returns:

  • externalSelect SlackModalSelect

Make a Block Kit modal external static select input

MakeSlackBlockExternalStaticSelectInput(label string, placeholder string, initialOptions []SlackInputOption, actionID string, isMulti bool, minQueryLength uint16) SlackBlockSection

Returns:

  • blockSection SlackBlockSection

Make a Block Kit block section external section

MakeSlackBlockExternalStaticSelectInput(label string, placeholder string, initialOptions []SlackInputOption, actionID string, isMulti bool) SlackBlockSection

Returns:

  • blockSection SlackBlockSection

Make a Block Kit block section static select section

MakeSlackBlockButton(label string, text string, value string, actionID string) SlackBlockSection

Returns:

  • button SlackBlockSection

Make a Block Kit block section with button

MakeSlackModalMultiConversationSelectInput(label string, placeholder string, initialConversations []string, actionID string) SlackModalSelect

Returns:

  • select SlackModalSelect

Make a Block Kit modal multi conversation select list

MakeSlackActionExternalStaticSelectInput(label string, placeholder string, initialOption *SlackInputOption, actionID string, isMulti bool, minQueryLength uint16) SlackActionSelect

Returns:

  • select SlackActionSelect

Make a Block Kit modal external select list

MakeSlackModalMultiUserSelectInput(label string, placeholder string, initialUsers []string, actionID string) SlackModalSelect

Returns:

  • select SlackModalSelect

Make a Block Kit modal multi user select list

MakeSlackModalUserSelectInput(label string, placeholder string, initialUser string, actionID string) SlackModalSelect

Returns:

  • select SlackModalSelect

Make a Block Kit modal user select list

MakeSlackModalDatePickerInput(label string, placeholder string, initialDate string, actionID string) SlackInputElement

Returns:

  • picker SlackInputElement

Make a Block Kit modal date picker

MakeSlackModalCheckboxesInput(label string, placeholder string, options []SlackInputOption, initialOptions []SlackInputOption, actionID string) SlackInputElement

Returns:

  • picker SlackInputElement

Make a Block Kit modal checkbox picker

MakeSlackModalRadioInput(label string, placeholder string, options []SlackInputOption, actionID string) SlackInputElement

Returns:

  • picker SlackInputElement

Make a Block Kit modal radio picker

MakeSlackInputOption(text string, value string) SlackInputOption

Returns:

  • option SlackInputOption

Make a Block Kit select option

MakeSlackModalTimePickerInput(label string, placeholder string, initialTime string, actionID string) SlackInputElement

Returns:

  • picker SlackInputElement

Make a Block Kit time picker

MakeSlackHeader(text string) SlackBlockSection

Returns:

  • header SlackBlockSection

Make a Block Kit header

MakeSlackDivider() SlackDivider

Returns:

  • divider SlackDivider

Make a Block Kit divider

MakeSlackContext(text string) SlackBlockActions

Returns:

  • ctx SlackBlockActions

Make a Block Kit context section

MakeSlackImage(title string, imageURL string, altText string) SlackBlockAccessory

Returns:

  • img SlackBlockAccessory

Make a Block Kit image section

Contributing

Kevin Xu

License

Apache 2.0

Documentation

Index

Constants

View Source
const (
	// INSTALLSUCCESSPAGE - Default Installation Page
	INSTALLSUCCESSPAGE = `` /* 1652-byte string literal not displayed */

)

Variables

This section is empty.

Functions

func ConvertState

func ConvertState(state ISlackBlockKitUI, dst interface{}) error

ConvertState - Convert unknown state to struct

func FileUpload

func FileUpload(channels []string, filename string, content string, filetype string, token string) error

FileUpload - Upload a file

func OpenView

func OpenView(view SlackModal, triggerID string, token string) error

OpenView - Open view in slack

func PostMessage

func PostMessage(channel string, blocks ISlackBlockKitUI, text string, token string) error

PostMessage - Post a message

func Response

func Response(ctx *SlackContext, code int, message []byte, headers map[string]string)

Response - Send response back to slack

func UpdateMessage

func UpdateMessage(channel string, ts string, blocks ISlackBlockKitUI, text string, token string) error

UpdateMessage - Update a slack message

func UpdateView

func UpdateView(view SlackInteractionView, viewID string, token string) error

UpdateView - Update a view in slack

Types

type ISlackBlockKitUI

type ISlackBlockKitUI interface{}

ISlackBlockKitUI - Slack Generic UI Kit

type SlackActionSelect

type SlackActionSelect struct {
	Type      string              `json:"type,omitempty"`
	Text      SlackBlockText      `json:"text,omitempty"`
	BlockID   string              `json:"block_id,omitempty"`
	Accessory SlackBlockAccessory `json:"accessory,omitempty"`
}

SlackActionSelect - Slack action select list

func MakeSlackActionExternalStaticSelectInput

func MakeSlackActionExternalStaticSelectInput(label string, placeholder string, initialOption *SlackInputOption, actionID string, isMulti bool, minQueryLength uint16) SlackActionSelect

MakeSlackActionExternalStaticSelectInput - Make slack external static select input field

type SlackApp

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

SlackApp - A simple slack app starter kit

func InitializeSlackApp

func InitializeSlackApp(opts *SlackAppOptions) SlackApp

InitializeSlackApp - Return an instance of SlackApp

func (*SlackApp) Close

func (a *SlackApp) Close(ctx context.Context)

Close - Shutting down the server

func (*SlackApp) CustomRoute

func (a *SlackApp) CustomRoute(pattern string, handler func(res http.ResponseWriter, req *http.Request))

CustomRoute - Add custom route

func (*SlackApp) OnAction

func (a *SlackApp) OnAction(actionID string, handler func(ctx *SlackContext))

OnAction - Add an action handler to the app base on action_id

func (*SlackApp) OnAppInstall

func (a *SlackApp) OnAppInstall(cb func(installRes *SlackOauth2Response, res http.ResponseWriter, req *http.Request) bool)

OnAppInstall - Add handler to app distribution after it's been successfully installed

func (*SlackApp) OnCommand

func (a *SlackApp) OnCommand(cmd string, handler func(ctx *SlackContext))

OnCommand - Add handler to command

func (*SlackApp) OnError

func (a *SlackApp) OnError(handler func(res http.ResponseWriter, req *http.Request, err error))

OnError - Add handler to errors

func (*SlackApp) OnEvent

func (a *SlackApp) OnEvent(eventType string, handler func(ctx *SlackContext))

OnEvent - Add handler to events

func (*SlackApp) OnShortcut

func (a *SlackApp) OnShortcut(callbackID string, handler func(ctx *SlackContext))

OnShortcut - Add an shortcut handler to the app base on callback_id

func (*SlackApp) OnViewClose

func (a *SlackApp) OnViewClose(callbackID string, handler func(ctx *SlackContext))

OnViewClose - Add handler to view close base on callback_id

func (*SlackApp) OnViewSubmission

func (a *SlackApp) OnViewSubmission(callbackID string, handler func(ctx *SlackContext))

OnViewSubmission - Add handler to view submission base on callback_id

func (*SlackApp) RemoveCommand

func (a *SlackApp) RemoveCommand(cmd string)

RemoveCommand - Remove a command to the app base on command

func (*SlackApp) ServeApp

func (a *SlackApp) ServeApp(port uint16, cb func())

ServeApp - Listen and Serve App on desired port, callback can be nil

type SlackAppOptions

type SlackAppOptions struct {
	Name          string      // Slack App name
	Prefix        string      // Prefix of routes
	TokensCache   TokensCache // List of available workspace tokens
	ClientSecret  string      // App client secret
	ClientID      string      // App client id
	SigningSecret string      // Signning secret
}

SlackAppOptions - Slack App options

type SlackBlockAccessory

type SlackBlockAccessory struct {
	Type                 string             `json:"type,omitempty"`
	Title                *SlackBlockText    `json:"title,omitempty"`
	AltText              string             `json:"alt_text,omitempty"`
	Text                 *SlackBlockText    `json:"text,omitempty"`
	Value                string             `json:"value,omitempty"`
	IsMultiline          bool               `json:"multiline,omitempty"`
	MaxLength            uint16             `json:"max_length,omitempty"`
	MinQueryLength       uint16             `json:"min_query_length,omitempty"`
	Placeholder          *SlackBlockText    `json:"placeholder,omitempty"`
	ImageURL             string             `json:"image_url,omitempty"`
	ActionID             string             `json:"action_id,omitempty"`
	Options              []SlackInputOption `json:"options,omitempty"`
	InitialDate          string             `json:"initial_date,omitempty"`
	InitialTime          string             `json:"initial_time,omitempty"`
	InitialOption        *SlackInputOption  `json:"initial_option,omitempty"`
	InitialOptions       []SlackInputOption `json:"initial_options,omitempty"`
	InitialConversations []string           `json:"initial_conversations,omitempty"`
	InitialUser          string             `json:"initial_user,omitempty"`
	InitialUsers         []string           `json:"initial_users,omitempty"`
}

SlackBlockAccessory - Slack Accessory

func MakeSlackImage

func MakeSlackImage(title string, imageURL string, altText string) SlackBlockAccessory

MakeSlackImage - Make a slack image section

type SlackBlockActions

type SlackBlockActions struct {
	Type     string           `json:"type,omitempty"`
	Elements ISlackBlockKitUI `json:"elements,omitempty"`
}

SlackBlockActions - Slack Actions

func MakeSlackActions

func MakeSlackActions(actions ISlackBlockKitUI) SlackBlockActions

MakeSlackActions - Make slack actions

func MakeSlackContext

func MakeSlackContext(text string) SlackBlockActions

MakeSlackContext - Make a slack context

type SlackBlockButton

type SlackBlockButton struct {
	Type     string          `json:"type,omitempty"`
	Text     *SlackBlockText `json:"text,omitempty"`
	Value    string          `json:"value,omitempty"`
	ActionID string          `json:"action_id,omitempty"`
}

SlackBlockButton - Slack Button action

func MakeSlackButton

func MakeSlackButton(text string, value string, actionID string) SlackBlockButton

MakeSlackButton - Make a slack button

type SlackBlockSection

type SlackBlockSection struct {
	Type      string               `json:"type,omitempty"`
	Text      *SlackBlockText      `json:"text,omitempty"`
	Accessory *SlackBlockAccessory `json:"accessory,omitempty"`
}

SlackBlockSection - Slack message section

func MakeSlackBlockButton

func MakeSlackBlockButton(label string, text string, value string, actionID string) SlackBlockSection

MakeSlackBlockButton - Make a slack button

func MakeSlackBlockExternalStaticSelectInput

func MakeSlackBlockExternalStaticSelectInput(label string, placeholder string, initialOptions []SlackInputOption, actionID string, isMulti bool, minQueryLength uint16) SlackBlockSection

MakeSlackBlockExternalStaticSelectInput - Make slack external static select input field

func MakeSlackBlockStaticSelectInput

func MakeSlackBlockStaticSelectInput(label string, placeholder string, options []SlackInputOption, initialOptions []SlackInputOption, actionID string, isMulti bool) SlackBlockSection

MakeSlackBlockStaticSelectInput - Make slack static select input field

func MakeSlackHeader

func MakeSlackHeader(text string) SlackBlockSection

MakeSlackHeader - Make a slack header section

func MakeSlackTextSection

func MakeSlackTextSection(text string) SlackBlockSection

MakeSlackTextSection - Make a text section (markdown)

type SlackBlockText

type SlackBlockText struct {
	Type  string `json:"type,omitempty"`
	Text  string `json:"text,omitempty"`
	Emoji *bool  `json:"emoji,omitempty"`
}

SlackBlockText - Slack Text

type SlackBlockTextFields

type SlackBlockTextFields struct {
	Type   string           `json:"type,omitempty"`
	Fields []SlackBlockText `json:"fields,omitempty"`
}

SlackBlockTextFields - Slack Text fields

func MakeSlackTextFieldsSection

func MakeSlackTextFieldsSection(texts []string) SlackBlockTextFields

MakeSlackTextFieldsSection - Make a text section (markdown)

type SlackContext

type SlackContext struct {
	Body      []byte
	Token     string
	Workspace string
	Req       *http.Request
	Res       http.ResponseWriter
}

SlackContext - Slack request context

type SlackDivider

type SlackDivider struct {
	Type string `json:"type"`
}

SlackDivider - Slack divider

func MakeSlackDivider

func MakeSlackDivider() SlackDivider

MakeSlackDivider -Make a slack divider

type SlackInputElement

type SlackInputElement struct {
	Type             string               `json:"type,omitempty"`
	BlockID          string               `json:"block_id,omitempty"`
	IsDispatchAction bool                 `json:"dispatch_action,omitempty"`
	Element          *SlackBlockAccessory `json:"element,omitempty"`
	Label            *SlackBlockText      `json:"label,omitempty"`
}

SlackInputElement - Slack Modal Plain text input

func MakeSlackModalCheckboxesInput

func MakeSlackModalCheckboxesInput(label string, placeholder string, options []SlackInputOption, initialOptions []SlackInputOption, actionID string) SlackInputElement

MakeSlackModalCheckboxesInput - Make slack modal checkboxes input field

func MakeSlackModalDatePickerInput

func MakeSlackModalDatePickerInput(label string, placeholder string, initialDate string, actionID string) SlackInputElement

MakeSlackModalDatePickerInput - Make slack modal datepicker input field

func MakeSlackModalRadioInput

func MakeSlackModalRadioInput(label string, placeholder string, options []SlackInputOption, actionID string) SlackInputElement

MakeSlackModalRadioInput - Make slack modal Radio input field

func MakeSlackModalTextInput

func MakeSlackModalTextInput(label string, placeholder string, actionID string, isMultiline bool, isDispatch bool, maxLength uint16) SlackInputElement

MakeSlackModalTextInput - Make slack modal input field

func MakeSlackModalTimePickerInput

func MakeSlackModalTimePickerInput(label string, placeholder string, initialTime string, actionID string) SlackInputElement

MakeSlackModalTimePickerInput - Make slack modal time picker input field

type SlackInputOption

type SlackInputOption struct {
	Text  *SlackBlockText `json:"text,omitempty"`
	Value string          `json:"value,omitempty"`
}

SlackInputOption - Slack Select option

func MakeSlackInputOption

func MakeSlackInputOption(text string, value string) SlackInputOption

MakeSlackInputOption - Make Slack input option

type SlackInteractionAction

type SlackInteractionAction struct {
	ActionID string          `json:"action_id,omitempty"`
	BlockID  string          `json:"block_id,omitempty"`
	Text     *SlackBlockText `json:"text,omitempty"`
	Value    string          `json:"value,omitempty"`
	Type     string          `json:"type,omitempty"`
	ActionTS string          `json:"action_ts,omitempty"`
}

SlackInteractionAction - Slack Interaction Action

type SlackInteractionContainer

type SlackInteractionContainer struct {
	Type        string `json:"type,omitempty"`
	MessageTS   string `json:"message_ts,omitempty"`
	ChannelID   string `json:"channel_id,omitempty"`
	IsEphemeral string `json:"is_ephemeral,omitempty"`
}

SlackInteractionContainer - Slack Interaction Container

type SlackInteractionEvent

type SlackInteractionEvent struct {
	Type        string                      `json:"type,omitempty"`
	User        *SlackInteractionUser       `json:"user,omitempty"`
	APIAppID    string                      `json:"api_app_id,omitempty"`
	Token       string                      `json:"token,omitempty"`
	Container   *SlackInteractionContainer  `json:"blocks,omitempty"`
	TriggerID   string                      `json:"trigger_id,omitempty"`
	Team        *SlackInteractionTeam       `json:"team,omitempty"`
	Channel     *SlackOauth2Team            `json:"channel,omitempty"`
	ResponseURL string                      `json:"response_url,omitempty"`
	Actions     []SlackInteractionAction    `json:"actions,omitempty"`
	Value       string                      `json:"value,omitempty"`
	State       map[string]ISlackBlockKitUI `json:"state,omitempty"`
	View        *SlackInteractionView       `json:"view,omitempty"`
	CallbackID  string                      `json:"callback_id,omitempty"`
	ActionID    string                      `json:"action_id,omitempty"`
	BlockID     string                      `json:"block_id,omitempty"`
	ActionTS    string                      `json:"action_ts,omitempty"`
}

SlackInteractionEvent - Slack Interaction Event

type SlackInteractionTeam

type SlackInteractionTeam struct {
	ID     string `json:"id,omitempty"`
	Domain string `json:"domain,omitempty"`
}

SlackInteractionTeam - Slack Interaction Team

type SlackInteractionUser

type SlackInteractionUser struct {
	ID       string `json:"id,omitempty"`
	Username string `json:"username,omitempty"`
	Name     string `json:"name,omitempty"`
	TeamID   string `json:"team_id,omitempty"`
}

SlackInteractionUser - Slack Interaction User

type SlackInteractionView

type SlackInteractionView struct {
	ID                 string                      `json:"id,omitempty"`
	TeamID             string                      `json:"team_id,omitempty"`
	Type               string                      `json:"type,omitempty"`
	Blocks             ISlackBlockKitUI            `json:"blocks,omitempty"`
	PrivateMetadata    string                      `json:"private_metadata,omitempty"`
	CallbackID         string                      `json:"callback_id,omitempty"`
	State              map[string]ISlackBlockKitUI `json:"state,omitempty"`
	Hash               string                      `json:"hash,omitempty"`
	Title              *SlackBlockText             `json:"title,omitempty"`
	Close              *SlackBlockText             `json:"close,omitempty"`
	Submit             *SlackBlockText             `json:"submit,omitempty"`
	ClearOnClose       bool                        `json:"clear_on_close,omitempty"`
	NotifyOnClose      bool                        `json:"notify_on_close,omitempty"`
	PreviousViewID     string                      `json:"previous_view_id,omitempty"`
	RootViewID         string                      `json:"root_view_id,omitempty"`
	AppID              string                      `json:"app_id,omitempty"`
	ExternalID         string                      `json:"external_id,omitempty"`
	AppInstalledTeamID string                      `json:"app_installed_team_id,omitempty"`
	BotID              string                      `json:"bot_id,omitempty"`
}

SlackInteractionView - Slack Interaction View

type SlackModal

type SlackModal struct {
	Type            string           `json:"type,omitempty"`
	Title           *SlackBlockText  `json:"title,omitempty"`
	Submit          *SlackBlockText  `json:"submit,omitempty"`
	Close           *SlackBlockText  `json:"close,omitempty"`
	Blocks          ISlackBlockKitUI `json:"blocks,omitempty"`
	CallbackID      string           `json:"callback_id,omitempty"`
	NotifyOnClose   bool             `json:"notify_on_close,omitempty"`
	PrivateMetadata string           `json:"private_metadata,omitempty"`
}

SlackModal - Slack Modal

func MakeSlackModal

func MakeSlackModal(title string, callbackID string, blocks ISlackBlockKitUI, submitText string, closeText string, notifyOnClose bool) SlackModal

MakeSlackModal - Make a slack button

type SlackModalSelect

type SlackModalSelect struct {
	Type     string               `json:"type,omitempty"`
	Optional bool                 `json:"optional,omitempty"`
	BlockID  string               `json:"block_id,omitempty"`
	Element  *SlackBlockAccessory `json:"element,omitempty"`
	Label    *SlackBlockText      `json:"label,omitempty"`
}

SlackModalSelect - Slack modal select

func MakeSlackModalExternalStaticSelectInput

func MakeSlackModalExternalStaticSelectInput(label string, placeholder string, initialOption *SlackInputOption, actionID string, isMulti bool, minQueryLength uint16, isOptional bool) SlackModalSelect

MakeSlackModalExternalStaticSelectInput - Make slack external static select input field

func MakeSlackModalMultiConversationSelectInput

func MakeSlackModalMultiConversationSelectInput(label string, placeholder string, initialConversations []string, isOptional bool, actionID string) SlackModalSelect

MakeSlackModalMultiConversationSelectInput - Make slack multi convo select input field

func MakeSlackModalMultiUserSelectInput

func MakeSlackModalMultiUserSelectInput(label string, placeholder string, initialUsers []string, actionID string) SlackModalSelect

MakeSlackModalMultiUserSelectInput - Make slack multi user select input field

func MakeSlackModalStaticSelectInput

func MakeSlackModalStaticSelectInput(label string, placeholder string, options []SlackInputOption, initialOption *SlackInputOption, actionID string, isMulti bool, isOptional bool) SlackModalSelect

MakeSlackModalStaticSelectInput - Make slack static select input field

func MakeSlackModalUserSelectInput

func MakeSlackModalUserSelectInput(label string, placeholder string, initialUser string, actionID string) SlackModalSelect

MakeSlackModalUserSelectInput - Make slack user select input field

type SlackOauth2Response

type SlackOauth2Response struct {
	Ok          bool            `json:"ok"`
	AccessToken string          `json:"access_token"`
	TokenType   string          `json:"token_type"`
	Scope       string          `json:"scope"`
	BotUserID   string          `json:"bot_user_id"`
	AppID       string          `json:"app_id"`
	Team        SlackOauth2Team `json:"team"`
	Enterprise  SlackOauth2Team `json:"enterprise"`
	AuthedUser  SlackOauth2User `json:"authed_user"`
}

SlackOauth2Response - Slack App Access Response

type SlackOauth2Team

type SlackOauth2Team struct {
	Name string `json:"name,omitempty"`
	ID   string `json:"id,omitempty"`
}

SlackOauth2Team - Slack App Access Response Team

type SlackOauth2User

type SlackOauth2User struct {
	ID          string `json:"id"`
	Scope       string `json:"scope"`
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
}

SlackOauth2User - Slack App Access Response User

type SlackSubscriptionEvent

type SlackSubscriptionEvent struct {
	Type    string `json:"type"`
	EventTS string `json:"event_ts"`
}

SlackSubscriptionEvent - Slack Subscription event

type SlackSubscriptionEventRequest

type SlackSubscriptionEventRequest struct {
	Token     string                 `json:"token"`
	TeamID    string                 `json:"team_id"`
	APIAppID  string                 `json:"api_app_id"`
	Event     SlackSubscriptionEvent `json:"event"`
	Type      string                 `json:"type"`
	EventID   string                 `json:"event_id"`
	EventTime uint32                 `json:"event_time"`
}

SlackSubscriptionEventRequest - Slack subscription event

type SlackUI

type SlackUI struct {
	Blocks ISlackBlockKitUI `json:"blocks,omitempty"`
}

SlackUI - Slack UI

type SlackUser

type SlackUser struct {
	ID       string `json:"id"`
	TeamID   string `json:"team_id"`
	Name     string `json:"name"`
	Deleted  bool   `json:"deleted"`
	Color    string `json:"color"`
	RealName string `json:"real_name"`
	TZ       string `json:"tz"`
	TZLabel  string `json:"tz_label"`
	TZOffset int32  `json:"tz_offset"`
	Profile  struct {
		AvatarHash            string `json:"avatar_hash"`
		StatusText            string `json:"status_text"`
		StatusEmoji           string `json:"status_emoji"`
		RealName              string `json:"real_name"`
		DisplayName           string `json:"display_name"`
		RealNameNormalized    string `json:"real_name_normalized"`
		DisplayNameNormalized string `json:"display_name_normalized"`
		Email                 string `json:"email"`
		Image24               string `json:"image_24"`
		Image32               string `json:"image_32"`
		Image48               string `json:"image_48"`
		Image72               string `json:"image_72"`
		Image192              string `json:"image_192"`
		Image512              string `json:"image_512"`
		Team                  string `json:"team"`
	} `json:"profile"`
	IsAdmin           bool   `json:"is_admin"`
	IsOwner           bool   `json:"is_owner"`
	IsPrimaryOwner    bool   `json:"is_primary_owner"`
	IsRestricted      bool   `json:"is_restricted"`
	IsUltraRestricted bool   `json:"is_ultra_restricted"`
	IsBot             bool   `json:"is_bot"`
	Updated           uint32 `json:"updated"`
	IsAppUser         bool   `json:"is_app_user"`
	Has2FA            bool   `json:"has_2fa"`
}

SlackUser - Slack User

func FindUserByEmail

func FindUserByEmail(email string, token string) (*SlackUser, error)

FindUserByEmail - Finding slack user by email

func FindUserByID

func FindUserByID(id string, token string) (*SlackUser, error)

FindUserByID - Finding slack user by id

type SlackUsersQuery

type SlackUsersQuery struct {
	Ok    bool      `json:"ok"`
	User  SlackUser `json:"user"`
	Error string    `json:"error"`
}

SlackUsersQuery - Slack User query

type TokensCache

type TokensCache interface {
	Get(workspace string) string
	Set(workspace string, token string)
	Remove(workspace string)
}

TokensCache - Token cache interface type

Jump to

Keyboard shortcuts

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