stream

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2025 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Stream)

Option functions are used to configure the stream.

func OptFastSearch

func OptFastSearch() Option

func OptLatest

func OptLatest(t time.Time) Option

OptLatest sets the latest time to be fetched.

func OptOldest

func OptOldest(t time.Time) Option

OptOldest sets the oldest time to be fetched.

func OptResultFn

func OptResultFn(fn func(sr Result) error) Option

OptResultFn sets the callback function that is called for each result.

type Result

type Result struct {
	Type        ResultType
	ChannelID   string
	ThreadTS    string
	ThreadCount int
	IsLast      bool // true if this is the last message for the channel or thread
	// Count contains the count of entities in the result. Right now it's
	// populated only for search results.
	Count int
	// Err contains the error if the result is an error.
	Err error
}

Result is sent to the callback function for each channel or thread.

func (*Result) Error

func (we *Result) Error() string

func (Result) String

func (s Result) String() string

func (*Result) Unwrap

func (we *Result) Unwrap() error

type ResultType

type ResultType int8

ResultType helps to identify the type of the result, so that the callback function can handle it appropriately.

const (
	RTMain    ResultType = iota // Main function result
	RTChannel                   // Result containing channel information
	RTThread                    // Result containing thread information
	RTChannelInfo
	RTChannelUsers
	RTSearch
)

func (ResultType) String

func (i ResultType) String() string

type Slacker

type Slacker interface {
	AuthTestContext(context.Context) (response *slack.AuthTestResponse, err error)
	GetConversationHistoryContext(ctx context.Context, params *slack.GetConversationHistoryParameters) (*slack.GetConversationHistoryResponse, error)
	GetConversationRepliesContext(ctx context.Context, params *slack.GetConversationRepliesParameters) (msgs []slack.Message, hasMore bool, nextCursor string, err error)
	GetUsersPaginated(options ...slack.GetUsersOption) slack.UserPagination

	GetStarredContext(ctx context.Context, params slack.StarsParameters) ([]slack.StarredItem, *slack.Paging, error)
	ListBookmarks(channelID string) ([]slack.Bookmark, error)

	GetConversationsContext(ctx context.Context, params *slack.GetConversationsParameters) (channels []slack.Channel, nextCursor string, err error)
	GetConversationInfoContext(ctx context.Context, input *slack.GetConversationInfoInput) (*slack.Channel, error)
	GetUsersInConversationContext(ctx context.Context, params *slack.GetUsersInConversationParameters) ([]string, string, error)

	SearchMessagesContext(ctx context.Context, query string, params slack.SearchParameters) (*slack.SearchMessages, error)
	SearchFilesContext(ctx context.Context, query string, params slack.SearchParameters) (*slack.SearchFiles, error)
}

Slacker is the interface with some functions of slack.Client.

type Stream

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

Stream is used to fetch conversations from Slack. It is safe for concurrent use.

func New

func New(cl Slacker, l *network.Limits, opts ...Option) *Stream

New creates a new Stream instance that allows to stream different slack entities.

func (*Stream) Conversations

func (cs *Stream) Conversations(ctx context.Context, proc processor.Conversations, items <-chan structures.EntityItem) error

Conversations fetches the conversations from the links channel. The link sent on that channel can be a channelID, channel URL, thread URL or a link in Slackdump format. fn is called for each result (channel messages, or thread messages). The fact that fn was called for channel messages, does not mean that all threads for that channel were already processed. Each last thread result is marked with StreamResult.IsLast. The caller must track the number of threads processed for each channel, and when the thread result with IsLast is received, the caller can assume that all threads and messages for that channel have been processed. For example, see cmd/slackdump/internal/export/expproc.

func (*Stream) ConversationsCB

func (cs *Stream) ConversationsCB(ctx context.Context, proc processor.Conversations, items []structures.EntityItem, cb func(Result) error) error

func (*Stream) ListChannels

TODO: test this.

func (*Stream) Search

func (s *Stream) Search(ctx context.Context, proc processor.Searcher, query string) error

func (*Stream) SearchFiles

func (cs *Stream) SearchFiles(ctx context.Context, proc processor.FileSearcher, query string) error

SearchFiles executes the search query and calls the processor for each returned slice of files. Channels do not have the file information.

func (*Stream) SearchMessages

func (cs *Stream) SearchMessages(ctx context.Context, proc processor.MessageSearcher, query string) error

SearchMessages executes the search query and calls the processor for each message results, it will also collect information about the channels. Message search results do not have files attached, so do not expect Files method to be called.

func (*Stream) SyncConversations

func (cs *Stream) SyncConversations(ctx context.Context, proc processor.Conversations, items ...structures.EntityItem) error

SyncConversations fetches the conversations from the link which can be a channelID, channel URL, thread URL or a link in Slackdump format.

func (*Stream) Users

func (cs *Stream) Users(ctx context.Context, proc processor.Users, opt ...slack.GetUsersOption) error

Users returns all users in the workspace.

func (*Stream) WorkspaceInfo

func (cs *Stream) WorkspaceInfo(ctx context.Context, proc processor.WorkspaceInfo) error

WorkspaceInfo fetches the workspace info and passes it to the processor. Getting it might be needed when the transformer need the current User ID or Team ID. (Different teams within one workspace are not yet supported.)

Jump to

Keyboard shortcuts

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