webapi

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: 13 Imported by: 0

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 Attachment

type Attachment struct {
	Text     string `json:"text,omitempty"`
	ID       int    `json:"id,omitempty"`
	Fallback string `json:"fallback,omitempty"`
}

Attachment is a part of the Message.

type Client

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

Client represents a Slack client for Web API.

func New

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

New creates a client with a bot token.

func (*Client) PostMessage

func (c *Client) PostMessage(ctx context.Context, channelID string, msg string) (*MessageResponse, error)

PostMessage sends a message to the Slack channel. see. https://api.slack.com/methods/chat.postMessage

func (*Client) RefreshUsersCache

func (c *Client) RefreshUsersCache(ctx context.Context) error

RefreshUsersCache updates the client's cached user map.

func (*Client) RespondToCommand added in v1.4.0

func (c *Client) RespondToCommand(ctx context.Context, responseURL string, msg string, visible bool) error

RespondToCommand responds to the Slack command.

func (*Client) UploadImage

func (c *Client) UploadImage(ctx context.Context, channels []string, title, fileName, fileType, comment string, img io.Reader) error

UploadImage uploads an image by files.upload API. see. https://api.slack.com/methods/files.upload

func (*Client) User

func (c *Client) User(id string) (User, bool)

User returns the user corresponding to user ID from the client's user cache.

func (*Client) UserID

func (c *Client) UserID(name string) string

UserID returns the userID corresponding to the username from the client's user cache.

func (*Client) Users

func (c *Client) Users(ctx context.Context) (map[string]User, error)

Users lists all users in a Slack team and returns it's userID map.

func (*Client) UsersList

func (c *Client) UsersList(ctx context.Context) ([]User, error)

UsersList lists all users in a Slack team. see. https://api.slack.com/methods/users.list

type Message

type Message struct {
	Text        string       `json:"text,omitempty"`
	Username    string       `json:"username,omitempty"`
	BotID       string       `json:"bot_id,omitempty"`
	Attachments []Attachment `json:"attachments,omitempty"`
	Type        string       `json:"type,omitempty"`
	SubType     string       `json:"sub_type,omitempty"`
	TS          string       `json:"ts,omitempty"`
}

Message represents the Slack message.

type MessageResponse

type MessageResponse struct {
	OK       bool    `json:"ok,omitempty"`
	Error    string  `json:"error,omitempty"`
	Needed   string  `json:"needed,omitempty"`
	Provided string  `json:"provided,omitempty"`
	Channel  string  `json:"channel,omitempty"`
	TS       string  `json:"ts,omitempty"`
	Message  Message `json:"message,omitempty"`
}

MessageResponse represents the response of the chat.postMessage API.

type Option

type Option func(*Client) error

Option represents the client's option.

func CacheUsers

func CacheUsers() Option

CacheUsers lists all users in a Slack team and caches it. required scopes: `users:read`

func Debug

func Debug() Option

Debug is the debug option.

type User

type User struct {
	ID        string `json:"id,omitempty"`
	TeamID    string `json:"team_id,omitempty"`
	Name      string `json:"name,omitempty"`
	RealName  string `json:"real_name,omitempty"`
	IsBot     bool   `json:"is_bot,omitempty"`
	Deleted   bool   `json:"deleted,omitempty"`
	IsAppUser bool   `json:"is_app_user"`
}

User represents the Slack user.

type UsersListResponse

type UsersListResponse struct {
	OK       bool   `json:"ok"`
	Error    string `json:"error"`
	Needed   string `json:"needed"`
	Provided string `json:"provided"`
	Members  []User `json:"members"`
}

UsersListResponse is the response of the users.list API.

Jump to

Keyboard shortcuts

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