socketmode

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// DefaultTimeout represents the time to wait for a response from slack.
	DefaultTimeout = 10 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Acknowledge

type Acknowledge struct {
	EnvelopeID string `json:"envelope_id"`
}

Acknowledge represents the payload type of the response back to Slack acknowledging. see. https://api.slack.com/apis/connections/socket-implement#acknowledge

type Client

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

Client represents a Slack client.

func New

func New(token string, opts ...Option) (*Client, error)

New creates a slack bot with an app-level token.

func (*Client) Close

func (c *Client) Close() error

Close closes the client.

func (*Client) ReceiveMessage

func (c *Client) ReceiveMessage(ctx context.Context, handler func(context.Context, *Event) error) error

ReceiveMessage receives a message and passes it to a handler for processing.

type Envelope

type Envelope struct {
	Type                   string          `json:"type"`
	EnvelopeID             string          `json:"envelope_id"`
	Payload                json.RawMessage `json:"payload"`
	AcceptsResponsePayload bool            `json:"accepts_response_payload"`
	RetryAttempt           int             `json:"retry_attempt"`
	RetryReason            string          `json:"retry_reason"`
	Reason                 string          `json:"reason"`     // disconnect type
	DebugInfo              json.RawMessage `json:"debug_info"` // disconnect type
}

Envelope represents the response of the Slack event API.

type EnvelopeType

type EnvelopeType string

EnvelopeType is the Slack event envelope type.

const (
	// EventsAPI indicates that the data is events API payload.
	EventsAPI EnvelopeType = "events_api"

	// Disconnect is the message expecting disconnects to the WebSocket connection.
	Disconnect EnvelopeType = "disconnect"

	// Interactive indicates that data is sent from a modal.
	Interactive EnvelopeType = "interactive"

	// SlashCommands indicates that data is sent from a slash command.
	SlashCommands EnvelopeType = "slash_commands"

	// Hello indicates that the client has successfully connected to the server.
	Hello EnvelopeType = "hello"
)

type Event

type Event struct {
	Type        string `json:"type"`
	Channel     string `json:"channel"`
	UserID      string `json:"user"`
	ClientMsgID string `json:"client_msg_id"`
	AppID       string `json:"app_id"`
	BotID       string `json:"bot_id"`
	TeamID      string `json:"team"`
	Text        string `json:"text"`
	TS          string `json:"ts"`
	EventTS     string `json:"event_ts"`
	ChannelType string `json:"channel_type"`

	// extended for slash_command
	Command     string `json:"command"`
	UserName    string `json:"user_name"`
	ResponseURL string `json:"response_url"`
	TriggerID   string `json:"trigger_id"`
}

Event represents the Slack event. see. https://api.slack.com/apis/connections/events-api#event_type_structure

func (Event) Is

func (e Event) Is(t EventType) bool

Is returns true, if the event type equals tne given event type.

func (Event) IsAppMention

func (e Event) IsAppMention() bool

IsAppMention returns true, if the event type is "app_mention".

func (Event) IsMessage

func (e Event) IsMessage() bool

IsMessage returns true, if the event type is "message".

func (Event) IsSlashCommand added in v1.4.0

func (e Event) IsSlashCommand() bool

IsSlashCommand returns true, if the event type is "slash_command".

type EventPayload

type EventPayload struct {
	Type               string        `json:"type"`
	EventID            string        `json:"event_id"`
	Event              Event         `json:"event"`
	EventTime          int           `json:"event_time"`
	EventContext       string        `json:"event_context"`
	APIAppID           string        `json:"api_app_id"`
	Authorizations     []interface{} `json:"authorizations"`
	IsExtSharedChannel bool          `json:"is_ext_shared_channel"`
	TeamID             string        `json:"team_id"`
	Token              string        `json:"token"`

	// for slash_commands
	Command     string `json:"command"`
	UserID      string `json:"user_id"`
	Text        string `json:"text"`
	UserName    string `json:"user_name"`
	ChannelID   string `json:"channel_id"`
	ChannelName string `json:"channel_name"`
	ResponseURL string `json:"response_url"`
	TriggerID   string `json:"trigger_id"`
}

EventPayload is a part of the Envelope.

type EventType

type EventType string

EventType is the Slack event type.

const (
	// AppMention is a Slack event type.
	// Subscribe to only the message events that mention your app or bot.
	AppMention EventType = "app_mention"

	// Message is a Slack event type.
	// A message was sent to a channel.
	Message EventType = "message"

	// SlashCommand is a slash command.
	SlashCommand = "slash_command"
)

type Option

type Option func(*Client) error

Option represents the client's option.

func Debug

func Debug() Option

Debug is the debug option.

Jump to

Keyboard shortcuts

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