Documentation
¶
Index ¶
Constants ¶
View Source
const ( // DefaultIdleTimeout is used when FlowConfig.IdleTimeout is zero. DefaultIdleTimeout = 24 * time.Hour // DefaultHistoryLimit is used when FlowConfig.HistoryLimit is zero. DefaultHistoryLimit = 64 // MaxRuntimeStateSize limits serialized state loaded from or written to storage. MaxRuntimeStateSize = 1 << 20 )
Variables ¶
View Source
var ( ErrNameEmpty = errors.New("flow: name cannot be empty") ErrVersionInvalid = errors.New("flow: version must be greater than zero") ErrIdleTimeoutNegative = errors.New("flow: idle timeout cannot be negative") ErrHistoryLimitNegative = errors.New("flow: history limit cannot be negative") ErrNilDefinition = errors.New("flow: nil definition") ErrNoStepsDefined = errors.New("flow: no steps defined") ErrDefinitionExists = errors.New("flow: definition already exists") ErrExpired = errors.New("flow: expired") ErrDefinitionNotRegistered = errors.New("flow: definition is not registered") ErrInvalidRuntimeState = errors.New("flow: invalid runtime state") ErrContextNoSender = errors.New("flow: context has no sender") ErrInvalidStepResult = errors.New("flow: invalid step result") ErrStorageNil = errors.New("flow: storage is nil") ErrConcurrentUpdate = errors.New("flow: state changed concurrently") ErrStateBusy = errors.New("flow: state is being processed") ErrTargetStepNotFound = errors.New("flow: target step not found") )
View Source
var ( ErrDataKeyEmpty = errors.New("flow: data key cannot be empty") ErrInvalidValue = errors.New("flow: invalid value") )
View Source
var ( ErrFlowNotBuilt = errors.New("flow: definition is not built") ErrStepNameEmpty = errors.New("flow: step name cannot be empty") ErrStepEventEmpty = errors.New("flow: step event cannot be empty") ErrStepDuplicate = errors.New("flow: duplicate step") ErrStepHandlerNil = errors.New("flow: step handler cannot be nil") ErrRuntimeStateSize = errors.New("flow: runtime state is too large") )
Functions ¶
This section is empty.
Types ¶
type BeginContextFunc ¶
BeginContextFunc is a context-aware step entry handler.
type Bus ¶
type Bus interface {
// NewFlow creates a versioned flow draft.
NewFlow(config FlowConfig) *Flow
// Start starts a flow or resumes its pending begin callback.
Start(ctx context.Context, c tele.Context, flow *Flow) error
// Handle processes an inferred Telebot event.
Handle(c tele.Context) error
// Cancel removes the active flow for the current chat and sender.
Cancel(ctx context.Context, c tele.Context) error
}
type Context ¶
type Context interface {
// SetString stores a string value under the key.
SetString(string, string) error
// SetBool stores a boolean value under the key.
SetBool(string, bool) error
// SetInt stores an int value normalized to int64.
SetInt(string, int) error
// SetInt32 stores an int32 value normalized to int64.
SetInt32(string, int32) error
// SetInt64 stores an int64 value under the key.
SetInt64(string, int64) error
// SetFloat32 stores a finite float32 value normalized to float64.
SetFloat32(string, float32) error
// SetFloat64 stores a finite float64 value under the key.
SetFloat64(string, float64) error
// SetDuration stores a time.Duration as an int64 nanosecond count.
SetDuration(string, time.Duration) error
// SetTime stores a time.Time as an RFC3339Nano string.
SetTime(string, time.Time) error
// Delete removes the value stored under the key.
Delete(string) error
// Has reports whether the key exists in the current flow data.
Has(string) bool
// GetString returns the string value stored under the key.
GetString(string) (string, bool)
// GetBool returns the boolean value stored under the key.
GetBool(string) (bool, bool)
// GetInt returns the stored integer when it fits in an int.
GetInt(string) (int, bool)
// GetInt32 returns the stored integer when it fits in an int32.
GetInt32(string) (int32, bool)
// GetInt64 returns the stored int64 value.
GetInt64(string) (int64, bool)
// GetFloat32 returns the stored floating-point value when it fits in a float32.
GetFloat32(string) (float32, bool)
// GetFloat64 returns the stored float64 value.
GetFloat64(string) (float64, bool)
// GetDuration returns the stored duration.
GetDuration(string) (time.Duration, bool)
// GetTime returns the stored time.Time value.
GetTime(string) (time.Time, bool)
// Current returns the name of the current step.
Current() string
// Depth returns the number of step entries currently present in history.
Depth() int
// CanBack reports whether the flow can move to a previous step.
CanBack() bool
// Step returns the name of the currently active step.
Step() string
// Next advances the flow to the next defined step after the handler returns.
Next() StepResult
// Back moves the flow to the previous step when history allows it.
Back() StepResult
// Go moves the flow to the named step after the handler returns.
Go(string) StepResult
// Stay keeps the flow on the current step after the handler returns.
Stay() StepResult
}
type Flow ¶
type Flow struct {
// contains filtered or unexported fields
}
Flow describes a registered flow definition and its ordered steps.
func (*Flow) Step ¶
func (f *Flow) Step( name string, event string, begin BeginFunc, handle HandleFunc, )
Step adds a named step to the flow draft.
func (*Flow) StepContext ¶
func (f *Flow) StepContext( name string, event string, begin BeginContextFunc, handle HandleContextFunc, )
StepContext adds a context-aware named step to the flow draft.
type FlowConfig ¶
type FlowConfig struct {
// Name identifies the flow and must not be empty.
Name string
// Version identifies the flow definition and must be greater than zero.
Version uint
// IdleTimeout sets when inactive state expires and uses DefaultIdleTimeout when zero.
IdleTimeout time.Duration
// HistoryLimit sets the retained step count and uses DefaultHistoryLimit when zero.
HistoryLimit int
}
FlowConfig is used to configure a flow.
type HandleContextFunc ¶
HandleContextFunc is a context-aware step event handler.
type HandleFunc ¶
type HandleFunc func(tele.Context, Context) (StepResult, error)
HandleFunc processes an event received by the current step.
type Step ¶
type Step struct {
// contains filtered or unexported fields
}
type StepResult ¶
type StepResult uint8
StepResult describes the transition requested by a step handler.
Click to show internal directories.
Click to hide internal directories.