Documentation
¶
Index ¶
- Variables
- type Addr
- type Chunk
- type ChunkType
- type DirOption
- type Directory
- func (d *Directory) Channels() ([]slack.Channel, error)
- func (d *Directory) Close() error
- func (d *Directory) Create(fileID FileID) (io.WriteCloser, error)
- func (d *Directory) File(id string, name string) (fs.File, error)
- func (d *Directory) Name() string
- func (d *Directory) Open(id FileID) (*File, error)
- func (d *Directory) OpenRAW(filename string) (io.ReadSeekCloser, error)
- func (d *Directory) RemoveAll() error
- func (d *Directory) Stat(id FileID) (fs.FileInfo, error)
- func (d *Directory) Users() ([]slack.User, error)
- func (d *Directory) WorkspaceInfo() (*slack.AuthTestResponse, error)
- type Encoder
- type File
- func (p *File) AllChannelIDs() []string
- func (f *File) AllChannelInfoWithMembers() ([]slack.Channel, error)
- func (f *File) AllChannelInfos() ([]slack.Channel, error)
- func (p *File) AllChannels() ([]slack.Channel, error)
- func (f *File) AllMessages(channelID string) ([]slack.Message, error)
- func (f *File) AllThreadMessages(channelID, threadTS string) ([]slack.Message, error)
- func (p *File) AllUsers() ([]slack.User, error)
- func (f *File) ChannelInfo(channelID string) (*slack.Channel, error)
- func (f *File) ChannelUsers(channelID string) ([]string, error)
- func (f *File) Close() error
- func (f *File) ForEach(fn func(ev *Chunk) error) error
- func (f *File) HasChannels() bool
- func (f *File) HasChunks(id GroupID) bool
- func (f *File) HasUsers() bool
- func (f *File) Offsets(id GroupID) ([]int64, bool)
- func (f *File) Sorted(ctx context.Context, desc bool, fn func(ts time.Time, m *slack.Message) error) error
- func (f *File) State() (*state.State, error)
- func (f *File) ThreadParent(channelID, threadTS string) (*slack.Message, error)
- func (f *File) WorkspaceInfo() (*slack.AuthTestResponse, error)
- type FileID
- type GroupID
- type Option
- type Player
- func (p *Player) ChannelInfo(id string) (*slack.Channel, error)
- func (p *Player) ChannelUsers(channelID string) ([]string, error)
- func (p *Player) Channels() ([]slack.Channel, error)
- func (p *Player) Close() error
- func (p *Player) HasChannels() bool
- func (p *Player) HasMoreChannelUsers(channelID string) bool
- func (p *Player) HasMoreChannels() bool
- func (p *Player) HasMoreMessages(channelID string) bool
- func (p *Player) HasMoreThreads(channelID string, threadTS string) bool
- func (p *Player) HasUsers() bool
- func (p *Player) Messages(channelID string) ([]slack.Message, error)
- func (p *Player) Offset() int64
- func (p *Player) Reset() error
- func (p *Player) SetState(ptrs map[GroupID]int)
- func (p *Player) State() map[GroupID]int
- func (p *Player) Thread(channelID string, threadTS string) ([]slack.Message, error)
- func (p *Player) ThreadChannelInfo(id string) (*slack.Channel, error)
- func (p *Player) Users() ([]slack.User, error)
- func (p *Player) WorkspaceInfo() (*slack.AuthTestResponse, error)
- type Recorder
- func (rec *Recorder) ChannelInfo(ctx context.Context, channel *slack.Channel, threadTS string) error
- func (rec *Recorder) ChannelUsers(ctx context.Context, channelID string, threadTS string, users []string) error
- func (rec *Recorder) Channels(ctx context.Context, channels []slack.Channel) error
- func (rec *Recorder) Close() error
- func (rec *Recorder) Files(ctx context.Context, channel *slack.Channel, parent slack.Message, ...) error
- func (rec *Recorder) Messages(ctx context.Context, channelID string, numThreads int, isLast bool, ...) error
- func (rec *Recorder) SearchFiles(ctx context.Context, query string, sf []slack.File) error
- func (rec *Recorder) SearchMessages(ctx context.Context, query string, sm []slack.SearchMessage) error
- func (rec *Recorder) State() (*state.State, error)
- func (rec *Recorder) ThreadMessages(ctx context.Context, channelID string, parent slack.Message, ...) error
- func (rec *Recorder) Users(ctx context.Context, users []slack.User) error
- func (rec *Recorder) WorkspaceInfo(ctx context.Context, atr *slack.AuthTestResponse) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("not found") ErrDataMisaligned = errors.New("internal error: index and file data misaligned") )
var ErrUnsupChunkType = fmt.Errorf("unsupported chunk type")
Functions ¶
This section is empty.
Types ¶
type Addr ¶
type Addr struct { Offset int64 // offset within the chunk file Index int16 // index of the message within the messages slice in the chunk }
Addr is the address of a particular message within a chunk file.
type Chunk ¶
type Chunk struct { // header // Type is the type of the Chunk Type ChunkType `json:"t"` // Timestamp when the chunk was recorded. Timestamp int64 `json:"ts"` // ChannelID that this chunk relates to. ChannelID string `json:"id,omitempty"` // Count is the count of elements in the chunk, i.e. messages or files. Count int `json:"n,omitempty"` // ThreadTS is populated if the chunk contains thread related data. It // is Slack's thread_ts. ThreadTS string `json:"r,omitempty"` // IsLast is set to true if this is the last chunk for the channel or // thread. IsLast bool `json:"l,omitempty"` // NumThreads is the number of threads in the message chunk. NumThreads int `json:"nt,omitempty"` // Channel contains the channel information. Within the chunk file, it // may not be immediately followed by messages from the channel due to // concurrent nature of the calls. // // Populated by ChannelInfo and Files methods. Channel *slack.Channel `json:"ci,omitempty"` // ChannelUsers contains the user IDs of the users in the channel. ChannelUsers []string `json:"cu,omitempty"` // Populated by ChannelUsers // Parent is populated in case the chunk is a thread, or a file. Populated // by ThreadMessages and Files methods. Parent *slack.Message `json:"p,omitempty"` // Messages contains a chunk of messages as returned by the API. Populated // by Messages and ThreadMessages methods. Messages []slack.Message `json:"m,omitempty"` // Files contains a chunk of files as returned by the API. Populated by // Files method. Files []slack.File `json:"f,omitempty"` // Users contains a chunk of users as returned by the API. Populated by // Users method. Users []slack.User `json:"u,omitempty"` // Channels contains a chunk of channels as returned by the API. Populated // by Channels method. Channels []slack.Channel `json:"ch,omitempty"` // WorkspaceInfo contains the workspace information as returned by the // API. Populated by WorkspaceInfo. WorkspaceInfo *slack.AuthTestResponse `json:"w,omitempty"` // StarredItems contains the starred items. StarredItems []slack.StarredItem `json:"st,omitempty"` // Populated by StarredItems // Bookmarks contains the bookmarks. Bookmarks []slack.Bookmark `json:"b,omitempty"` // Populated by Bookmarks // SearchQuery contains the search query. SearchQuery string `json:"sq,omitempty"` // Populated by SearchMessages and SearchFiles. // SearchMessages contains the search results. SearchMessages []slack.SearchMessage `json:"sm,omitempty"` // Populated by SearchMessages // SearchFiles contains the search results. SearchFiles []slack.File `json:"sf,omitempty"` // Populated by SearchFiles }
Chunk is a representation of a single chunk of data retrieved from the API. A single API call always produces a single Chunk.
func (*Chunk) Timestamps ¶
Timestamps returns the timestamps of the messages in the chunk. For files and other types of chunks, it returns ErrUnsupChunkType.
type Directory ¶
type Directory struct {
// contains filtered or unexported fields
}
Directory is an abstraction over the directory with chunk files. It provides a way to write chunk files and read channels, users and messages across many the chunk files. All functions that require a name, except functions with suffix RAW, will append an extension to the name automatically (".json.gz"). *RAW functions expect the full name of the file with the extension. All files created by this package will be compressed with GZIP, unless stated otherwise.
func CreateDir ¶
CreateDir creates and opens a directory. It will create all parent directories if they don't exist.
func OpenDir ¶
OpenDir "opens" an existing directory for read and write operations. It expects the directory to exist and to be a directory, otherwise it will return an error.
func (*Directory) Channels ¶
Channels collects all channels from the chunk directory. First, it attempts to find the channel.json.gz file, if it's not present, it will go through all conversation files and try to get "ChannelInfo" chunk from the each file.
func (*Directory) Create ¶
func (d *Directory) Create(fileID FileID) (io.WriteCloser, error)
Create creates the chunk file with the given name. Extension is appended automatically.
Example:
cd, _ := chunk.OpenDirectory("chunks") f, _ := cd.Create("channels") // creates channels.json.gz
It will NOT overwrite an existing file and will return an error if the file exists.
func (*Directory) Open ¶
Open opens a chunk file with the given name. Extension is appended automatically.
func (*Directory) OpenRAW ¶
func (d *Directory) OpenRAW(filename string) (io.ReadSeekCloser, error)
OpenRAW opens a compressed chunk file with filename within the directory, and returns a ReadSeekCloser. filename is the full name of the file with extension.
func (*Directory) RemoveAll ¶
RemoveAll deletes the directory and all its contents. Make sure all files are closed.
func (*Directory) WorkspaceInfo ¶
func (d *Directory) WorkspaceInfo() (*slack.AuthTestResponse, error)
WorkspaceInfo returns the workspace info from the directory.
type Encoder ¶
type Encoder interface {
Encode(chunk interface{}) error
}
Encoder is the interface that wraps the Encode method.
type File ¶
type File struct {
// contains filtered or unexported fields
}
File is the catalog of chunks in a file.
func FromReader ¶
func FromReader(rs io.ReadSeeker) (*File, error)
FromReader creates a new chunk File from the io.ReadSeeker.
func (*File) AllChannelIDs ¶
AllChannelIDs returns all the channels in the chunkfile.
func (*File) AllChannelInfoWithMembers ¶
AllChannelInfoWithMembers returns all channels with Members populated.
func (*File) AllChannelInfos ¶
AllChannelInfos returns all the channel information collected by the channel info API.
func (*File) AllChannels ¶
AllChannels returns all channels collected by listing channels in the dump file.
func (*File) AllMessages ¶
AllMessages returns all the messages for the given channel posted to it (no thread). The messages are in the order as they appear in the file.
func (*File) AllThreadMessages ¶
AllThreadMessages returns all the messages for the given thread. It does not return the parent message in the result, use File.ThreadParent for that. The messages are in the order as they appear in the file.
func (*File) ChannelInfo ¶
ChannelInfo returns the information for the given channel.
func (*File) ForEach ¶
ForEach iterates over the chunks in the reader and calls the function for each chunk. It will lock the file until it finishes.
func (*File) HasChannels ¶
HasChannels returns true if there is at least one channel chunk in the file.
func (*File) Sorted ¶
func (f *File) Sorted(ctx context.Context, desc bool, fn func(ts time.Time, m *slack.Message) error) error
Sorted iterates over all the messages in the chunkfile in chronological order. If desc is true, the slice will be iterated in reverse order.
func (*File) State ¶
State generates and returns the state of the file. It does not include the path to the downloaded files.
func (*File) ThreadParent ¶
ThreadParent returns the thread parent message for the given thread. It returns ErrNotFound if the thread is not found.
func (*File) WorkspaceInfo ¶
func (f *File) WorkspaceInfo() (*slack.AuthTestResponse, error)
WorkspaceInfo returns the workspace info from the chunkfile.
type FileID ¶
type FileID string
FileID is the ID of the file within the Directory (it's basically the file name without an extension).
const ( FChannels FileID = "channels" FUsers FileID = "users" FWorkspace FileID = "workspace" FSearch FileID = "search" )
common filenames
func LinkToFileID ¶
func LinkToFileID(sl structures.SlackLink, includeThread bool) FileID
LinkToFileID converts the SlackLink to file ID. If includeThread is true and the thread timestamp is not empty, the thread timestamp will be appended to the channel ID. Otherwise, only the channel ID will be returned.
func ToFileID ¶
ToFileID returns the file ID for the given channel and thread timestamp. If includeThread is true and threadTS is not empty, the thread timestamp will be appended to the channel ID. Otherwise, only the channel ID will be returned.
func (FileID) SlackLink ¶
func (id FileID) SlackLink() structures.SlackLink
SlackLink returns the SlackLink for the file ID. If the file ID doesn't contain the thread timestamp, the thread timestamp will be empty.
type GroupID ¶
type GroupID string
GroupID is a unique ID for a chunk group. It is used to group chunks of the same type together for indexing purposes. It may or may not be equal to the Slack ID of the entity.
type Option ¶
type Option func(r *Recorder)
Option is a function that configures the Recorder.
func WithEncoder ¶
WithEncoder allows you to specify a custom encoder to use for the chunks. By default json.Encoder is used.
type Player ¶
type Player struct {
// contains filtered or unexported fields
}
Player replays the chunks from a file, it is able to emulate the API responses, if used in conjunction with the [proctest.Server]. Zero value is not usable.
func NewPlayerFromFile ¶
func (*Player) ChannelInfo ¶
ChannelInfo returns the channel information for the given channel. It returns an error if the channel is not found within the chunkfile.
func (*Player) HasChannels ¶
func (*Player) HasMoreChannelUsers ¶
func (*Player) HasMoreChannels ¶
func (*Player) HasMoreMessages ¶
HasMoreMessages returns true if there are more messages to be read for the channel.
func (*Player) HasMoreThreads ¶
func (*Player) ThreadChannelInfo ¶
func (*Player) WorkspaceInfo ¶
func (p *Player) WorkspaceInfo() (*slack.AuthTestResponse, error)
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder records all the data it receives into a writer.
func NewRecorder ¶
NewRecorder creates a new recorder.
func (*Recorder) ChannelInfo ¶
func (rec *Recorder) ChannelInfo(ctx context.Context, channel *slack.Channel, threadTS string) error
ChannelInfo records a channel information. threadTS should be set to threadTS, if ChannelInfo is called while streaming a thread (user requested a thread).
func (*Recorder) ChannelUsers ¶
func (rec *Recorder) ChannelUsers(ctx context.Context, channelID string, threadTS string, users []string) error
ChannelUsers records the channel users
func (*Recorder) Files ¶
func (rec *Recorder) Files(ctx context.Context, channel *slack.Channel, parent slack.Message, f []slack.File) error
Files is called for each file chunk that is retrieved. The parent message is passed in as well.
func (*Recorder) Messages ¶
func (rec *Recorder) Messages(ctx context.Context, channelID string, numThreads int, isLast bool, m []slack.Message) error
Messages is called for each message chunk that is retrieved.
func (*Recorder) SearchFiles ¶
SearchMessages records the result of a file search.
func (*Recorder) SearchMessages ¶
func (rec *Recorder) SearchMessages(ctx context.Context, query string, sm []slack.SearchMessage) error
SearchMessages records the result of a message search.
func (*Recorder) ThreadMessages ¶
func (rec *Recorder) ThreadMessages(ctx context.Context, channelID string, parent slack.Message, threadOnly, isLast bool, tm []slack.Message) error
ThreadMessages is called for each of the thread messages that are retrieved. The parent message is passed in as well.
func (*Recorder) WorkspaceInfo ¶
WorkspaceInfo is called when workspace info is retrieved.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package chunktest provides a test server for testing the chunk package.
|
Package chunktest provides a test server for testing the chunk package. |
Package control holds the implementation of the Slack Stream controller.
|
Package control holds the implementation of the Slack Stream controller. |
Package dirproc is a processor that writes the data into gzipped files in a directory.
|
Package dirproc is a processor that writes the data into gzipped files in a directory. |
Package obfuscate obfuscates a slackdump chunk recording.
|
Package obfuscate obfuscates a slackdump chunk recording. |
fileproc
Package fileproc is the file processor that can be used in conjunction with the transformer.
|
Package fileproc is the file processor that can be used in conjunction with the transformer. |