slackingway

package
v0.0.0-...-755c5cc Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SlackVersion  = "v0"
	TimeAllowance = 30 * time.Second
)

Variables

View Source
var (
	PingDelay = 5 * time.Second
)

Functions

func CreateEchoModal

func CreateEchoModal() slack.ModalViewRequest

func CreateMenuModal

func CreateMenuModal() slack.ModalViewRequest

func DelayedPing

func DelayedPing(s Slackingway) (slack.Msg, error)

DelayedPing sends a delayed ping response to the user

func Echo

func Echo(s *SlackingwayWrapper) error

func HomeTab

func HomeTab(s *SlackingwayWrapper) error
func Menu(s *SlackingwayWrapper) error

func Ping

func Ping() (slack.Msg, error)

Ping responds to a ping request

func ReceivedEcho

func ReceivedEcho(s *SlackingwayWrapper) (slack.Msg, error)

func ReceivedMenu

func ReceivedMenu(s *SlackingwayWrapper) ([]slack.Block, error)

func ValidateRequest

func ValidateRequest(request events.APIGatewayProxyRequest, slackSigningSecret string) error

ValidateRequest verifies the request from Slack

func ValidateRole

func ValidateRole(role, userID string) bool

ValidateRole checks if the user ID is in the role

Types

type SlackAPIClient

type SlackAPIClient interface {
	GetUserInfo(userID string) (*slack.User, error)
	PostMessage(channelID string, options ...slack.MsgOption) (string, string, error)
	OpenView(triggerID string, view slack.ModalViewRequest) (*slack.ViewResponse, error)
	UpdateView(view slack.ModalViewRequest, externalID string, hash string, viewID string) (*slack.ViewResponse, error)
	PublishView(userID string, view slack.HomeTabViewRequest, hash string) (*slack.ViewResponse, error)
}

type SlackEvent

type SlackEvent struct {
	Type    string `json:"type"`
	User    string `json:"user"`
	Channel string `json:"channel"`
	Tab     string `json:"tab"`
}

type SlackRequestBody

type SlackRequestBody struct {
	Timestamp   string     `json:"timestamp"`
	Type        string     `json:"type"`
	Challenge   string     `json:"challenge"`
	Token       string     `json:"token"`
	Command     string     `json:"command"`
	Text        string     `json:"text"`
	ResponseURL string     `json:"response_url"`
	UserID      string     `json:"user_id"`
	ChannelID   string     `json:"channel_id"`
	TeamID      string     `json:"team_id"`
	CallbackID  string     `json:"callback_id"`
	TriggerID   string     `json:"trigger_id"`
	View        slack.View `json:"view"`
	Event       SlackEvent `json:"event"`
}

Body of request data from Slack

func (*SlackRequestBody) ParsePayload

func (s *SlackRequestBody) ParsePayload(payload string) error

ParsePayload parses the payload from Slack

func (*SlackRequestBody) ParseSlashCommand

func (s *SlackRequestBody) ParseSlashCommand(requestData url.Values) error

ParseSlashCommand parses the slash command request from Slack

func (*SlackRequestBody) ParseTimestamp

func (s *SlackRequestBody) ParseTimestamp(timestamp string) error

ParseTimestamp parses the timestamp from Slack

type Slackingway

type Slackingway interface {
	NewResponse(message slack.Msg) (*http.Request, error)
	SendResponse(request *http.Request) error
	SendTextMessage(message, channelID string) error
	SendBlockMessage(blocks []slack.Block, channelID string) error
	WriteToHistory(channelID string) error
}

type SlackingwayWrapper

type SlackingwayWrapper struct {
	Debug            bool
	APIClient        SlackAPIClient
	HTTPClient       *http.Client
	SlackRequestBody *SlackRequestBody
}

func NewSlackingway

func NewSlackingway(oauthToken string, s *SlackRequestBody) *SlackingwayWrapper

NewSlackingway creates a new SlackingwayWrapper

func (*SlackingwayWrapper) NewResponse

func (s *SlackingwayWrapper) NewResponse(message slack.Msg) (*http.Request, error)

NewResponse creates a new HTTP request for a Slack response

func (*SlackingwayWrapper) SendBlockMessage

func (s *SlackingwayWrapper) SendBlockMessage(blocks []slack.Block, channelID string) error

SendBlockMessage sends a message with blocks to a Slack channel

func (*SlackingwayWrapper) SendResponse

func (s *SlackingwayWrapper) SendResponse(request *http.Request) error

SendResponse sends a response to Slack

func (*SlackingwayWrapper) SendTextMessage

func (s *SlackingwayWrapper) SendTextMessage(message, channelID string) error

SendTextMessage sends a message to a Slack channel

func (*SlackingwayWrapper) WriteToHistory

func (s *SlackingwayWrapper) WriteToHistory(channelID string) error

WriteToHistory writes a message to Slackingway's history channel

Jump to

Keyboard shortcuts

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