Documentation ¶
Index ¶
- Constants
- func SprintLines(width int, lines [][]PrintableMessagePart) string
- type Attachment
- type AttachmentField
- type Channel
- type ChannelType
- type Connection
- type ConnectionStatus
- type Event
- type File
- type Message
- type PrintableMessage
- type PrintableMessagePart
- type PrintableMessagePartType
- type Reaction
- type Team
- type TypingUsers
- type User
Constants ¶
const TYPING_PERSIST_SECONDS = 5
How many seconds after getting a user typing event does the user no longer show as typing?
Variables ¶
This section is empty.
Functions ¶
func SprintLines ¶
func SprintLines(width int, lines [][]PrintableMessagePart) string
Types ¶
type Attachment ¶
type Attachment struct { Title string TitleLink string Body string Color string Fields []AttachmentField }
type AttachmentField ¶
type Channel ¶
type Channel struct { Id string `json:"id"` Name string `json:"name"` Creator *User `json:"creator"` Created int `json:"created"` IsMember bool `json:"is_member"` IsArchived bool `json:"is_archived"` SubType ChannelType `json:"subtype"` }
A Channel is a independent stream of messages sent by users.
type ChannelType ¶
type ChannelType int
const ( TYPE_CHANNEL ChannelType = iota // A channel is a open conversation between a large number of people TYPE_DIRECT_MESSAGE // A DM is a message connection between two people TYPE_GROUP_DIRECT_MESSAGE // A Group DM is a DM between greater than two people )
type Connection ¶
type Connection interface { // Each connection has a name. Name() string Status() ConnectionStatus Connect() error Disconnect() error // Called to "refetch" any persistent resources, such as channels. Refresh(bool) error // Get incoming and outgoing message buffers Incoming() chan Event Outgoing() chan Event MessageHistory() []Message SetMessageHistory([]Message) AppendMessageHistory(message Message) PrependMessageHistory(message Message) DeleteMessageHistory(index int) ClearMessageHistory() SendMessage(Message, *Channel) (*Message, error) ParseMessage(map[string]interface{}, map[string]*User) (*Message, error) ToggleMessageReaction(Message, string) error // Fetch a slice of all channels that are available on this connection Channels() []Channel SetChannels([]Channel) FetchChannels() ([]Channel, error) SelectedChannel() *Channel SetSelectedChannel(*Channel) JoinChannel(*Channel) (*Channel, error) LeaveChannel(*Channel) (*Channel, error) // Fetch the team associated with this connection. Team() *Team SetTeam(Team) // Fetch user that is authenticated Self() *User SetSelf(User) // Given a channel, fetch the message history for that channel. Optionally, provide a timestamp // to fetch all messages after. FetchChannelMessages(Channel, *string) ([]Message, error) UserById(string) (*User, error) UserOnline(user *User) bool SetUserOnline(user *User, status bool) // Post a large block of text in a given channel PostText(title string, body string) error // Upload a file into a given channel PostBinary(title string, filename string, content []byte) error // Manage which users are typing. TypingUsers() *TypingUsers }
A Connection is used to represent a message source.
type ConnectionStatus ¶
type ConnectionStatus int
const ( DISCONNECTED ConnectionStatus = iota CONNECTING CONNECTED FAILED // When the gateway errors, then move to this state. )
type Event ¶
type Event struct { Direction string // "incoming" or "outgoing" Type string `json:"type"` Data map[string]interface{} // Properties that an event may be associated with. Channel Channel User User }
Events are emitted when data comes in from a connection and sent when data is to be sent to a connection. ie, when another user sends a message, an event would come in:
Event{ Direction: "incoming", Type: "message", Data: map[string]interface{ "text": "Hello World!", ... }, }
type File ¶
type File struct { Id string `json:"id"` Name string `json:"name"` Filetype string `json:"type"` User *User `json:"user"` PrivateUrl string `json:"url_private"` Permalink string `json:"permalink"` }
A File is an optional key on a message.
type Message ¶
type Message struct { Sender *User `json:"sender"` Text string `json:"text"` Reactions []Reaction `json:"reactions"` Hash string `json:"hash"` Timestamp int `json:"timestamp"` // This value is in seconds! File *File `json:"file,omitempty"` Attachments *[]Attachment `json:"attachments,omitempty"` // Has a message been confirmed as existing from the server, or is it preemptive? Confirmed bool `json:"confirmed"` // Cache message tokens on the message. Tokens *[][]PrintableMessagePart `json:"tokens"` }
A Message is a blob of text or media sent by a User within a Channel.
type PrintableMessage ¶
type PrintableMessage struct {
// contains filtered or unexported fields
}
func NewPrintableMessage ¶
func NewPrintableMessage(parts []PrintableMessagePart) PrintableMessage
func (*PrintableMessage) Length ¶
func (p *PrintableMessage) Length() int
Return the length of the printable message
func (*PrintableMessage) Lines ¶
func (p *PrintableMessage) Lines(width int) [][]PrintableMessagePart
func (*PrintableMessage) Parts ¶
func (p *PrintableMessage) Parts() []PrintableMessagePart
func (*PrintableMessage) Plain ¶
func (p *PrintableMessage) Plain() string
Return the printable message converted to plain text string.
func (*PrintableMessage) SetParts ¶
func (p *PrintableMessage) SetParts(parts []PrintableMessagePart)
type PrintableMessagePart ¶
type PrintableMessagePart struct { Type PrintableMessagePartType Content string Metadata map[string]interface{} }
type PrintableMessagePartType ¶
type PrintableMessagePartType int
const ( PRINTABLE_MESSAGE_PLAIN_TEXT PrintableMessagePartType = iota PRINTABLE_MESSAGE_FORMATTING_BOLD PRINTABLE_MESSAGE_FORMATTING_ITALIC PRINTABLE_MESSAGE_AT_MENTION_USER // (like @foo, @bar, etc) PRINTABLE_MESSAGE_AT_MENTION_GROUP // (like @channel, @here, etc) PRINTABLE_MESSAGE_CHANNEL // (like #general) PRINTABLE_MESSAGE_CONNECTION // (like "my custom slack team") PRINTABLE_MESSAGE_LINK // (like http://example.com) PRINTABLE_MESSAGE_NEWLINE PRINTABLE_MESSAGE_FORMATTING_CODE PRINTABLE_MESSAGE_FORMATTING_PREFORMATTED )
type TypingUsers ¶
type TypingUsers struct {
// contains filtered or unexported fields
}
func NewTypingUsers ¶
func NewTypingUsers() *TypingUsers
func (*TypingUsers) Add ¶
func (t *TypingUsers) Add(username string, time time.Time)
Given a user and a timestamp, store their last typing timestamp.
func (*TypingUsers) Remove ¶
func (t *TypingUsers) Remove(username string)
Given a user, if they're typing, stop their typing.
func (*TypingUsers) Users ¶
func (t *TypingUsers) Users() []string
Return a slice of users that are typing at any given point in time.
type User ¶
type User struct { Id string `json:"id"` Name string `json:"name"` Color string `json:"color"` Avatar string `json:"avatar"` Status string `json:"status"` RealName string `json:"real_name"` Email string `json:"email"` Skype string `json:"skype"` Phone string `json:"phone"` }
A user is a human or bot that sends messages on within channel.