wizard

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InvalidFieldValueErrorTr     = "wizard.errors.field.invalid.value"
	InvalidFieldValueTypeErrorTr = "wizard.errors.field.invalid.type"
	MissingStateErrorTr          = "wizard.errors.state.missing"
)
View Source
const (
	CallbackDataFieldPrefix = "field" + callbackDataSep
)
View Source
const ValidErrNotInListTr = "errors.validation.option.not.in.list"

Variables

This section is empty.

Functions

func CallbackQueryHandler added in v0.2.0

func CallbackQueryHandler(reqenv *base.RequestEnv, query *tgbotapi.CallbackQuery, stateStorage StateStorage)

func PopulateWizardDescriptors

func PopulateWizardDescriptors(handlers []base.MessageHandler) bool

Types

type Field

type Field struct {
	Name         string      `json:"name"`
	Data         interface{} `json:"data,omitempty"`
	WasRequested bool        `json:"wasRequested"`
	Type         FieldType   `json:"type"`

	Form *Form `json:"-"`
	// contains filtered or unexported fields
}

type FieldDescriptor

type FieldDescriptor struct {
	Validator                 FieldValidator
	SkipIf                    SkipCondition
	ReplyKeyboardBuilder      ReplyKeyboardBuilder
	InlineKeyboardAnswers     []string
	DisableKeyboardValidation bool
	// contains filtered or unexported fields
}

func (*FieldDescriptor) InlineButtonCustomizer added in v0.2.2

func (descriptor *FieldDescriptor) InlineButtonCustomizer(option string, customizer InlineButtonCustomizer) bool

type FieldExtractor

type FieldExtractor func(msg *tgbotapi.Message) interface{}

type FieldType

type FieldType string
const (
	Auto      FieldType = "<auto>"
	Text      FieldType = "text"
	Sticker   FieldType = "sticker"
	Image     FieldType = "image"
	Voice     FieldType = "voice"
	Audio     FieldType = "audio"
	Video     FieldType = "video"
	VideoNote FieldType = "video_note"
	Gif       FieldType = "gif"
	Document  FieldType = "document"
)

type FieldValidator

type FieldValidator func(msg *tgbotapi.Message, lc *loc.Context) error

type Fields

type Fields []*Field

func (Fields) FindField

func (fs Fields) FindField(name string) *Field

type File

type File struct {
	ID       string
	UniqueID string
}

type Form

type Form struct {
	Fields     Fields `json:"fields"`
	Index      int    `json:"index"`
	WizardType string `json:"wizardType"`
	// contains filtered or unexported fields
}

func (*Form) AddEmptyField

func (form *Form) AddEmptyField(name string, fieldType FieldType)

func (*Form) AddPrefilledField

func (form *Form) AddPrefilledField(name string, value interface{})

func (*Form) DoAction

func (form *Form) DoAction(reqenv *base.RequestEnv, msg *tgbotapi.Message)

func (*Form) PopulateRestored

func (form *Form) PopulateRestored(msg *tgbotapi.Message, storage StateStorage)

func (*Form) ProcessNextField

func (form *Form) ProcessNextField(reqenv *base.RequestEnv, msg *tgbotapi.Message)

type FormAction

type FormAction func(reqenv *base.RequestEnv, msg *tgbotapi.Message, fields Fields)

type FormDescriptor

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

func NewWizardDescriptor

func NewWizardDescriptor(action FormAction) *FormDescriptor

func (*FormDescriptor) AddField

func (descriptor *FormDescriptor) AddField(name, promptDescriptionOrTrKey string) *FieldDescriptor

type InlineButtonCustomizer added in v0.2.2

type InlineButtonCustomizer func(btn *tgbotapi.InlineKeyboardButton, f *Field)

type RedisStateStorage

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

func ConnectToRedis

func ConnectToRedis(ctx context.Context, ttl time.Duration, options *redis.Options) RedisStateStorage

func (RedisStateStorage) Close

func (rss RedisStateStorage) Close() error

func (RedisStateStorage) DeleteState

func (rss RedisStateStorage) DeleteState(uid int64) error

func (RedisStateStorage) GetCurrentState

func (rss RedisStateStorage) GetCurrentState(uid int64, dest Wizard) error

func (RedisStateStorage) SaveState

func (rss RedisStateStorage) SaveState(uid int64, wizard Wizard) error

type ReplyKeyboardBuilder added in v0.2.2

type ReplyKeyboardBuilder func(reqenv *base.RequestEnv, msg *tgbotapi.Message) []string

type SkipCondition

type SkipCondition interface {
	ShouldBeSkipped(form *Form) bool
}

type SkipOnFieldValue

type SkipOnFieldValue struct {
	Name  string
	Value string
}

func (SkipOnFieldValue) ShouldBeSkipped

func (s SkipOnFieldValue) ShouldBeSkipped(form *Form) bool

type StateStorage

type StateStorage interface {
	GetCurrentState(uid int64, dest Wizard) error
	SaveState(uid int64, wizard Wizard) error
	DeleteState(uid int64) error
	Close() error
}

type Wizard

type Wizard interface {
	AddEmptyField(name string, fieldType FieldType)
	AddPrefilledField(name string, value interface{})
	ProcessNextField(reqenv *base.RequestEnv, msg *tgbotapi.Message)
	DoAction(reqenv *base.RequestEnv, msg *tgbotapi.Message)
	PopulateRestored(msg *tgbotapi.Message, storage StateStorage)
}

func NewWizard

func NewWizard(handler WizardMessageHandler, fields int) Wizard

type WizardMessageHandler

type WizardMessageHandler interface {
	base.MessageHandler

	GetWizardName() string
	GetWizardStateStorage() StateStorage
	GetWizardDescriptor() *FormDescriptor
}

Jump to

Keyboard shortcuts

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