Documentation
¶
Overview ¶
Package module provides the module handler interface and base types.
Index ¶
- Constants
- func Behavior(uid types.Uid, flag string, number int)
- func Bootstrap() error
- func FormMsg(ctx types.Context, id string) types.MsgPayload
- func Help(rules []any) (map[string][]string, error)
- func Init(jsonconf json.RawMessage) error
- func List() map[string]Handler
- func Register(name string, module Handler)
- func RunCommand(commandRules []command.Rule, ctx types.Context, content any) (types.MsgPayload, error)
- func RunForm(formRules []form.Rule, ctx types.Context, values types.KV) (types.MsgPayload, error)
- func ServiceURL(ctx types.Context, group, path string, param types.KV) string
- func SetModuleDataStore(s ModuleDataStore)
- func SettingGet(ctx types.Context, id, key string) (types.KV, error)
- func SettingMsg(ctx types.Context, id string) types.MsgPayload
- func Shortcut(title, link string) (string, error)
- func StoreForm(ctx types.Context, payload types.MsgPayload) types.MsgPayload
- func StoreParameter(params types.KV, expiredAt time.Time) (string, error)
- func Unregister(name string)
- func Webservice(app *fiber.App, name string, ruleset webservice.Ruleset)
- type Base
- func (Base) Bootstrap() error
- func (Base) Command(_ types.Context, _ any) (types.MsgPayload, error)
- func (Base) Form(_ types.Context, _ types.KV) (types.MsgPayload, error)
- func (b Base) Help() (map[string][]string, error)
- func (Base) Input(_ types.Context, _ types.KV, _ any) (types.MsgPayload, error)
- func (Base) Rules() []any
- func (Base) Webservice(_ *fiber.App)
- type BehaviorRecord
- type FormRecord
- type Handler
- type ModuleDataStore
Constants ¶
View Source
const ( MessageBotIncomingBehavior = "message_bot_incoming" MessageGroupIncomingBehavior = "message_group_incoming" )
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init(jsonconf json.RawMessage) error
func RunCommand ¶
func SetModuleDataStore ¶ added in v0.99.0
func SetModuleDataStore(s ModuleDataStore)
SetModuleDataStore wires the persistence backend used by module helpers.
func SettingMsg ¶
func SettingMsg(ctx types.Context, id string) types.MsgPayload
func StoreForm ¶
func StoreForm(ctx types.Context, payload types.MsgPayload) types.MsgPayload
func Unregister ¶
func Unregister(name string)
Unregister removes a previously registered module handler. It is a no-op if the name is not found. Intended primarily for test teardown.
func Webservice ¶
func Webservice(app *fiber.App, name string, ruleset webservice.Ruleset)
Types ¶
type BehaviorRecord ¶ added in v0.99.0
BehaviorRecord is the module-layer view of a persisted behavior counter.
type FormRecord ¶ added in v0.99.0
type FormRecord struct {
ID int64
FormID string
UID string
Topic string
Schema types.KV
Values types.KV
Extra types.KV
State int
}
FormRecord is the module-layer view of a persisted form without ORM types.
type Handler ¶
type Handler interface {
// Init initializes the module.
Init(jsonconf json.RawMessage) error
// IsReady checks if the module is initialized.
IsReady() bool
// Bootstrap Lifecycle hook
Bootstrap() error
// Help return module help
Help() (map[string][]string, error)
// Rules return module ruleset
Rules() []any
// Input return input result
Input(ctx types.Context, head types.KV, content any) (types.MsgPayload, error)
// Command return module result
Command(ctx types.Context, content any) (types.MsgPayload, error)
// Form return module form result
Form(ctx types.Context, values types.KV) (types.MsgPayload, error)
// Webservice return webservice routes
Webservice(app *fiber.App)
}
type ModuleDataStore ¶ added in v0.99.0
type ModuleDataStore interface {
FormGet(ctx context.Context, formID string) (FormRecord, error)
FormSet(ctx context.Context, formID string, form FormRecord) error
ParameterSet(ctx context.Context, flag string, params types.KV, expiredAt time.Time) error
ConfigGet(ctx context.Context, uid types.Uid, topic, key string) (types.KV, error)
BehaviorGet(ctx context.Context, uid types.Uid, flag string) (BehaviorRecord, error)
BehaviorIncrease(ctx context.Context, uid types.Uid, flag string, number int) error
BehaviorSet(ctx context.Context, behavior BehaviorRecord) error
}
ModuleDataStore persists module form, parameter, config, and behavior data.
Click to show internal directories.
Click to hide internal directories.