slack

package module
v0.0.0-...-0356e1e Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2015 License: MIT Imports: 13 Imported by: 0

README

Slack GoDoc

Golang client for the Slack API. Include the example code using each slack api.

Currently supports:

Method Description Example
channels.history Fetches history of messages and events from a channel. #link
channels.join Joins a channel, creating it if needed. #link
channels.list Lists all channels in a Slack team. #link
chat.postMessage Sends a message to a channel. #link
files.upload Upload an image/file #link
groups.invite Invites a user to a private group. #link
groups.create Creates a private group. #link
groups.list Lists private groups that the calling user has access to. #link
users.info Gets information about a channel. #link
users.list Lists all users in a Slack team. #link

Example

package main

import (
  "github.com/bluele/slack"
)

const (
  token       = "your-api-token"
  channelName = "general"
)

func main() {
  api := slack.New(token)
  channel, err := api.FindChannelByName(channelName)
  if err != nil {
    panic(err)
  }
  err = api.ChatPostMessage(channel.Id, "Hello, world!", nil)
  if err != nil {
    panic(err)
  }
}

Author

Jun Kimura

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseAPIResponse

type BaseAPIResponse struct {
	Ok    bool   `json:"ok"`
	Error string `json:"error"`
}

type Channel

type Channel struct {
	Id         string          `json:"id"`
	Name       string          `json:"name"`
	IsChannel  bool            `json:"is_channel"`
	Created    int             `json:"created"`
	Creator    string          `json:"creator"`
	IsArchived bool            `json:"is_archived"`
	IsGeneral  bool            `json:"is_general"`
	IsMember   bool            `json:"is_member"`
	Members    []string        `json:"members"`
	RawTopic   json.RawMessage `json:"topic"`
	RawPurpose json.RawMessage `json:"purpose"`
	NumMembers int             `json:"num_members"`
}

slack channel type

func (*Channel) Purpose

func (ch *Channel) Purpose() (*Purpose, error)

func (*Channel) Topic

func (ch *Channel) Topic() (*Topic, error)

type ChannelsHistoryOpt

type ChannelsHistoryOpt struct {
	Channel   string  `json:"channel"`
	Latest    float64 `json:"latest"`
	Oldest    float64 `json:"oldest"`
	Inclusive int     `json:"inclusive"`
	Count     int     `json:"count"`
}

option type for `channels.history` api

func (*ChannelsHistoryOpt) Bind

func (opt *ChannelsHistoryOpt) Bind(uv *url.Values) error

type ChannelsHistoryResponse

type ChannelsHistoryResponse struct {
	BaseAPIResponse
	Latest   float64    `json:"latest"`
	Messages []*Message `json:"messages"`
	HasMore  bool       `json:"has_more"`
}

response type for `channels.history` api

type ChannelsListAPIResponse

type ChannelsListAPIResponse struct {
	BaseAPIResponse
	RawChannels json.RawMessage `json:"channels"`
}

response type for `channels.list` api

func (*ChannelsListAPIResponse) Channels

func (res *ChannelsListAPIResponse) Channels() ([]*Channel, error)

Channels returns a slice of channel object from a response of `channels.list` api.

type ChatPostMessageAPIResponse

type ChatPostMessageAPIResponse struct {
	BaseAPIResponse
	Channel string `json:"channel"`
	Ts      string `json:"ts"`
}

response type for `chat.postMessage` api

type ChatPostMessageOpt

type ChatPostMessageOpt struct {
	AsUser      bool
	Parse       string
	LinkNames   string
	AttachMents string
	UnfurlLinks string
	UnfurlMedia string
	IconUrl     string
	IconEmoji   string
}

option type for `chat.postMessage` api

type FilesUploadAPIResponse

type FilesUploadAPIResponse struct {
	Ok    bool   `json:"ok"`
	Error string `json:"error"`
}

response of `files.upload` api

type FilesUploadOpt

type FilesUploadOpt struct {
	Content        string
	Filepath       string
	Filetype       string
	Filename       string
	Title          string
	InitialComment string
	Channels       []string
}

option type for `files.upload` api

type Group

type Group struct {
	Id         string          `json:"id"`
	Name       string          `json:"name"`
	Created    int             `json:"created"`
	Creator    string          `json:"creator"`
	IsArchived bool            `json:"is_archived"`
	Members    []string        `json:"members"`
	RawTopic   json.RawMessage `json:"topic"`
	RawPurpose json.RawMessage `json:"purpose"`
}

slack group type

type GroupsCreateAPIResponse

type GroupsCreateAPIResponse struct {
	BaseAPIResponse
	RawGroup json.RawMessage `json:"group"`
}

response type for `groups.create` api

func (*GroupsCreateAPIResponse) Group

func (res *GroupsCreateAPIResponse) Group() (*Group, error)

type GroupsListAPIResponse

type GroupsListAPIResponse struct {
	BaseAPIResponse
	RawGroups json.RawMessage `json:"groups"`
}

response type for `groups.list` api

func (*GroupsListAPIResponse) Groups

func (res *GroupsListAPIResponse) Groups() ([]*Group, error)

Groups returns a slice of group object from `groups.list` api.

type Message

type Message struct {
	Type   string `json:"type"`
	Ts     string `json:"ts"`
	UserId string `json:"user"`
	Text   string `json:"text"`
}

func (*Message) Timestamp

func (msg *Message) Timestamp() *time.Time

type ProfileInfo

type ProfileInfo struct {
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	RealName  string `json:"real_name"`
	Email     string `json:"email"`
	Skype     string `json:"skype"`
	Phone     string `json:"phone"`
	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"`
}

slack user profile type

type Purpose

type Purpose struct {
	Value   string `json:"value"`
	Creator string `json:"creator"`
	LastSet int    `json:"last_set"`
}

type Slack

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

func New

func New(token string) *Slack

Create a slack client with an API token.

func (*Slack) ChannelsHistory

func (sl *Slack) ChannelsHistory(opt *ChannelsHistoryOpt) ([]*Message, error)

API channels.history: Fetches history of messages and events from a channel.

func (*Slack) ChannelsList

func (sl *Slack) ChannelsList() ([]*Channel, error)

API channels.list: Lists all channels in a Slack team.

func (*Slack) ChatPostMessage

func (sl *Slack) ChatPostMessage(channelId string, text string, opt *ChatPostMessageOpt) error

API chat.postMessage: Sends a message to a channel.

func (*Slack) CreateGroup

func (sl *Slack) CreateGroup(name string) error

API groups.create: Creates a private group.

func (*Slack) DoRequest

func (sl *Slack) DoRequest(req *http.Request) ([]byte, error)

func (*Slack) FilesUpload

func (sl *Slack) FilesUpload(opt *FilesUploadOpt) error

API files.upload: Uploads or creates a file.

func (*Slack) FindChannel

func (sl *Slack) FindChannel(cb func(*Channel) bool) (*Channel, error)

FindChannel returns a channel object that satisfy conditions specified.

func (*Slack) FindChannelByName

func (sl *Slack) FindChannelByName(name string) (*Channel, error)

FindChannelByName returns a channel object that matches name specified.

func (*Slack) FindGroup

func (sl *Slack) FindGroup(cb func(*Group) bool) (*Group, error)

FindGroup returns a group object that satisfy conditions specified.

func (*Slack) FindGroupByName

func (sl *Slack) FindGroupByName(name string) (*Group, error)

FindGroupByName returns a group object that matches name specified.

func (*Slack) FindUser

func (sl *Slack) FindUser(cb func(*User) bool) (*User, error)

FindUser returns a user object that satisfy conditions specified.

func (*Slack) GetRequest

func (sl *Slack) GetRequest(endpoint string, uv *url.Values) ([]byte, error)

func (*Slack) GroupsList

func (sl *Slack) GroupsList() ([]*Group, error)

API groups.list: Lists private groups that the calling user has access to.

func (*Slack) InviteGroup

func (sl *Slack) InviteGroup(channelId, userId string) error

API groups.invite: Invites a user to a private group.

func (*Slack) JoinChannel

func (sl *Slack) JoinChannel(name string) error

API channels.join: Joins a channel, creating it if needed.

func (*Slack) PostRequest

func (sl *Slack) PostRequest(endpoint string, uv *url.Values, body *bytes.Buffer) ([]byte, error)

func (*Slack) UsersInfo

func (sl *Slack) UsersInfo(userId string) (*User, error)

API users.info: Gets information about a user.

func (*Slack) UsersList

func (sl *Slack) UsersList() ([]*User, error)

API users.list: Lists all users in a Slack team.

type Topic

type Topic struct {
	Value   string `json:"value"`
	Creator string `json:"creator"`
	LastSet int    `json:"last_set"`
}

type User

type User struct {
	Id       string `json:"id"`
	Name     string `json:"name"`
	Deleted  bool   `json:"deleted"`
	Color    string `json:"color"`
	Profile  *ProfileInfo
	IsAdmin  bool `json:"is_admin"`
	IsOwner  bool `json:"is_owner"`
	Has2fa   bool `json:"has_2fa"`
	HasFiles bool `json:"has_files"`
}

slack user type

type UsersInfoAPIResponse

type UsersInfoAPIResponse struct {
	BaseAPIResponse
	User *User `json:"user"`
}

response type of `users.info` api

type UsersListAPIResponse

type UsersListAPIResponse struct {
	BaseAPIResponse
	RawMembers json.RawMessage `json:"members"`
}

response type of `users.list` api

func (*UsersListAPIResponse) Members

func (res *UsersListAPIResponse) Members() ([]*User, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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