gatewaySlack

package
v0.2.1-0...-dabd69d Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2017 License: MIT Imports: 15 Imported by: 1

README

Slack Gateway

All code that communicates between slick and slack lives here.

Constructing

slack := gatewaySlack.New("my slack token here")

Sending / Receiving Messages

Most of the code in connect.go has to do with sending / receiving messages. There's .Incoming() and .Outgoing() methods on the struct that return a reference to the raw message sending channel. For example, you can send a message like:

slack.Outgoing() <- gateway.Event{
	Direction: "outgoing",
	Type: "message_type",
	Data: map[string]interface{}{
		"foo": "bar",
	},
}

and receive a message like:

message := <-slack.Incoming()
message.Type // "message_type"
message.Direction // "incoming"
message.Data // map[string]interface{}{ "foo": "bar" }

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RawSlackMessage

type RawSlackMessage struct {
	Ts        string `json:"ts"`
	UserId    string `json:"user"`
	Text      string `json:"text"`
	Reactions []struct {
		Name  string   `json:"name"`
		Users []string `json:"users"`
	} `json:"reactions"`
	File struct {
		Id         string `json:"id"`
		Name       string `json:"name"`
		Filetype   string `json:"pretty_type"`
		User       string `json:"user"`
		PrivateUrl string `json:"url_private"`
		Permalink  string `json:"permalink"`
		Text       string `json:"plain_text"`
		Reactions  []struct {
			Name  string   `json:"name"`
			Users []string `json:"users"`
		} `json:"reactions"`
	} `json:"file,omitempty"`
	Attachments []struct {
		Title     string `json:"title"`
		TitleLink string `json:"title_link"`
		Color     string `json:"color"`
		Text      string `json:"text"`
		Fields    []struct {
			Title string `json:"title"`
			Value string `json:"value"`
			Short bool   `json:"short"`
		} `json:"fields"`
	} `json:"attachments"`
}

type SlackConnection

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

SlackConnection meets the connection interface.

func New

func New(token string) *SlackConnection

func NewWithName

func NewWithName(nickname string, token string) *SlackConnection

func (*SlackConnection) AppendMessageHistory

func (c *SlackConnection) AppendMessageHistory(message gateway.Message)

func (*SlackConnection) Channels

func (c *SlackConnection) Channels() []gateway.Channel

func (*SlackConnection) ClearMessageHistory

func (c *SlackConnection) ClearMessageHistory()

func (*SlackConnection) Connect

func (c *SlackConnection) Connect() error

Connect to the slack persistent socket.

func (*SlackConnection) DeleteMessageHistory

func (c *SlackConnection) DeleteMessageHistory(index int)

func (*SlackConnection) Disconnect

func (c *SlackConnection) Disconnect() error

func (*SlackConnection) FetchChannelMessages

func (c *SlackConnection) FetchChannelMessages(channel gateway.Channel, startTs *string) ([]gateway.Message, error)

Given a channel, return all messages within that channel.

func (*SlackConnection) FetchChannels

func (c *SlackConnection) FetchChannels() ([]gateway.Channel, error)

Fetch all channels for the given team

func (*SlackConnection) Incoming

func (c *SlackConnection) Incoming() chan gateway.Event

func (*SlackConnection) JoinChannel

func (c *SlackConnection) JoinChannel(inChannel *gateway.Channel) (*gateway.Channel, error)

Join the passed channel.

func (*SlackConnection) LeaveChannel

func (c *SlackConnection) LeaveChannel(channel *gateway.Channel) (*gateway.Channel, error)

Leave the passed channel.

func (*SlackConnection) MessageHistory

func (c *SlackConnection) MessageHistory() []gateway.Message

func (*SlackConnection) Name

func (c *SlackConnection) Name() string

Return the name of the team.

func (*SlackConnection) Outgoing

func (c *SlackConnection) Outgoing() chan gateway.Event

func (*SlackConnection) ParseMessage

func (c *SlackConnection) ParseMessage(
	preMessage map[string]interface{},
	cachedUsers map[string]*gateway.User,
) (*gateway.Message, error)

func (*SlackConnection) PostBinary

func (c *SlackConnection) PostBinary(title string, filename string, content []byte) error

func (*SlackConnection) PostText

func (c *SlackConnection) PostText(title string, content string) error

func (*SlackConnection) PrependMessageHistory

func (c *SlackConnection) PrependMessageHistory(message gateway.Message)

func (*SlackConnection) Refresh

func (c *SlackConnection) Refresh(force bool) error

Called when the connection becomes active

func (*SlackConnection) SelectedChannel

func (c *SlackConnection) SelectedChannel() *gateway.Channel

func (*SlackConnection) Self

func (c *SlackConnection) Self() *gateway.User

func (*SlackConnection) SendMessage

func (c *SlackConnection) SendMessage(message gateway.Message, channel *gateway.Channel) (*gateway.Message, error)

Send a given message to a given channel. Also, is able to process slash commands. Returns an optional pointer to a response message and an error.

func (*SlackConnection) SetChannels

func (c *SlackConnection) SetChannels(channels []gateway.Channel)

func (*SlackConnection) SetMessageHistory

func (c *SlackConnection) SetMessageHistory(messages []gateway.Message)

func (*SlackConnection) SetSelectedChannel

func (c *SlackConnection) SetSelectedChannel(channel *gateway.Channel)

func (*SlackConnection) SetSelf

func (c *SlackConnection) SetSelf(u gateway.User)

func (*SlackConnection) SetTeam

func (c *SlackConnection) SetTeam(t gateway.Team)

func (*SlackConnection) SetUserOnline

func (c *SlackConnection) SetUserOnline(user *gateway.User, status bool)

func (*SlackConnection) Status

func (*SlackConnection) Team

func (c *SlackConnection) Team() *gateway.Team

func (*SlackConnection) ToggleMessageReaction

func (c *SlackConnection) ToggleMessageReaction(message gateway.Message, reaction string) error

func (*SlackConnection) TypingUsers

func (c *SlackConnection) TypingUsers() *gateway.TypingUsers

func (*SlackConnection) UserById

func (c *SlackConnection) UserById(id string) (*gateway.User, error)

func (*SlackConnection) UserOnline

func (c *SlackConnection) UserOnline(user *gateway.User) bool

Jump to

Keyboard shortcuts

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