botsfwmodels

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: MIT Imports: 6 Imported by: 22

Documentation

Index

Constants

View Source
const (
	// AwaitingReplyToPathSeparator separates parts of the command state
	AwaitingReplyToPathSeparator = "/"

	// AwaitingReplyToPath2QuerySeparator separates path and query parts of state
	AwaitingReplyToPath2QuerySeparator = "?"

	// AwaitingReplyToParamsSeparator separates params of command state
	AwaitingReplyToParamsSeparator = "&"
)

Variables

This section is empty.

Functions

func AwaitingReplyToPath

func AwaitingReplyToPath(awaitingReplyTo string) string

AwaitingReplyToPath returns just path part of command state

func AwaitingReplyToQuery

func AwaitingReplyToQuery(awaitingReplyTo string) string

AwaitingReplyToQuery returns just query part of command state

func NewChatID

func NewChatID(botID, botChatID string) string

NewChatID create a new bot chat ID, returns string

Types

type AppUserAdapter added in v0.4.0

type AppUserAdapter interface {
	// SetBotUserID associates bot user ID with an app user record
	SetBotUserID(platform, botID, botUserID string)

	// UserNamesHolder is an interface to set and get user's names.
	UserNamesHolder

	// PreferredLocaleHolder is an interface to set and get preferred locale
	PreferredLocaleHolder
}

type AppUserData added in v0.0.5

type AppUserData interface {

	// BotsFwAdapter returns to bots framework an adapter to app user data record.
	// Using an adapter ensures there is no clashes between bots framework interfaces and app user struct.
	BotsFwAdapter() AppUserAdapter
}

AppUserData is a record where information about app user is stored. Bots can use it to store information about a user like names, preferred locale.

type BotBaseData

type BotBaseData struct {
	//user.OwnedByUserWithID
	AppUserID string // intentionally indexed & do NOT omitempty (so we can find records with empty AppUserID)

	DtCreated time.Time `json:",omitempty" datastore:",omitempty" firestore:",omitempty"`
	DtUpdated time.Time `json:",omitempty" datastore:",omitempty" firestore:",omitempty"`

	// AccessGranted indicates if access to the bot has been granted
	AccessGranted bool
}

BotBaseData holds properties common to all bot entities

func (*BotBaseData) GetAppUserID added in v0.0.5

func (e *BotBaseData) GetAppUserID() string

GetAppUserID returns app user ID

func (*BotBaseData) IsAccessGranted

func (e *BotBaseData) IsAccessGranted() bool

IsAccessGranted indicates if access to the bot has been granted

func (*BotBaseData) SetAccessGranted

func (e *BotBaseData) SetAccessGranted(value bool) bool

SetAccessGranted mark that access has been granted

func (*BotBaseData) SetAppUserID added in v0.0.5

func (e *BotBaseData) SetAppUserID(s string)

SetAppUserID sets app user ID

func (*BotBaseData) SetUpdatedTime added in v0.0.5

func (e *BotBaseData) SetUpdatedTime(v time.Time)

SetUpdatedTime sets updated time

func (*BotBaseData) Validate added in v0.0.5

func (e *BotBaseData) Validate() error

Validate returns error if data is invalid

type BotChatData added in v0.1.0

type BotChatData interface {
	// Base returns a base struct that should be included in all structs that implement BotChatData.
	Base() *ChatBaseData // TODO: Document why this is needed or remove

	// IsChanged returns true if data has been changed
	IsChanged() bool

	// GetBotID returns bot ID
	GetBotID() (botID string)

	// GetChatID returns chat ID
	GetChatID() (chatID string)

	// Key returns chat key
	Key() ChatKey

	// GetAppUserID returns app user ID
	GetAppUserID() (appUserID string)

	// SetAppUserID sets app user ID
	SetAppUserID(appUserID string)

	// AddClientLanguage adds client language
	AddClientLanguage(languageCode string) (changed bool)

	// SetBotUserID sets bot user ID
	SetBotUserID(id interface{})

	// SetIsGroupChat marks current chat as a group chat
	SetIsGroupChat(bool)

	// IsAccessGranted returns true if access is granted
	IsAccessGranted() bool

	// IsGroupChat returns true if current chat is a group chat
	IsGroupChat() bool

	// SetAccessGranted sets access granted flag
	SetAccessGranted(value bool) bool

	// GetPreferredLanguage returns preferred language for the chat
	GetPreferredLanguage() string

	// SetPreferredLanguage sets preferred language for the chat
	SetPreferredLanguage(value string)

	// SetUpdatedTime sets updated time
	SetUpdatedTime(time.Time) // github.com/strongo/user.UpdatedTimeSetter

	// SetDtLastInteraction sets last interaction time
	SetDtLastInteraction(time time.Time)

	// GetAwaitingReplyTo returns path of the step that is awaiting reply to
	GetAwaitingReplyTo() string

	// SetAwaitingReplyTo sets path of the step that is awaiting reply to
	SetAwaitingReplyTo(path string)

	// IsAwaitingReplyTo returns true if awaiting reply to specific step
	IsAwaitingReplyTo(code string) bool

	// AddWizardParam adds a parameter to wizard with a given key & value
	AddWizardParam(key, value string)

	// GetWizardParam returns a parameter from wizard for a given key
	GetWizardParam(key string) string

	// PopStepsFromAwaitingReplyUpToSpecificParent pops steps from awaiting reply up to specific parent
	PopStepsFromAwaitingReplyUpToSpecificParent(code string)

	// PushStepToAwaitingReplyTo pushes step to awaiting reply to
	PushStepToAwaitingReplyTo(code string)
}

BotChatData provides data about bot chat

type BotRecordsMaker added in v0.0.4

type BotRecordsMaker interface {
	Platform() string

	// MakeAppUserDto makes app user DTO for a given request sender
	MakeAppUserDto(botID string) (AppUserData, error)

	// MakeBotUserDto makes bot user DTO for a given request sender
	MakeBotUserDto(botID string) (BotUserData, error)

	// MakeBotChatDto makes bot chat DTO for a given request
	MakeBotChatDto(botID string) (BotChatData, error)
}

BotRecordsMaker is an interface for making bot records This should be implemented by platform adapters (for example by https://github.com/bots-go-framework/bots-fw-telegram)

func NewBotRecordsMaker added in v0.0.4

func NewBotRecordsMaker(
	platform string,
	makeAppUserDto func(botID string) (appUser AppUserData, err error),
	makeBotUserDto func(botID string) (botUser BotUserData, err error),
	makeBotChatDto func(botID string) (botChat BotChatData, err error),
) BotRecordsMaker

type BotUserBaseData added in v0.0.4

type BotUserBaseData struct {
	BotBaseData

	// FirstName is first name of a user
	FirstName string `json:",omitempty" dalgo:",omitempty,noindex"`

	// LastName is last name of a user
	LastName string `json:",omitempty" dalgo:",omitempty,noindex"`

	// UserName is login ID of a user
	UserName string `json:",omitempty" dalgo:",omitempty,noindex"`
}

BotUserBaseData hold common properties for bot user entities

func (*BotUserBaseData) BaseData added in v0.0.4

func (v *BotUserBaseData) BaseData() *BotUserBaseData

BaseData returns base data of a user that should be included in all structs that implement BotUserData

type BotUserData

type BotUserData interface {
	// BaseData returns base data that should be implemented by all bot user structs
	BaseData() *BotUserBaseData

	// GetAppUserID returns app user ID if available
	GetAppUserID() string

	// SetAppUserID sets app user ID to associate bot user record with app user
	SetAppUserID(appUserID string)

	WithAccessGrantedFlag

	// SetUpdatedTime sets last updated time // TODO: document intended usage
	SetUpdatedTime(time.Time) //to satisfy github.com/strongo/app/user.UpdatedTimeSetter
}

BotUserData interface provides information about bot user This should be implemented by bot user record struct.

type ChatBaseData added in v0.0.5

type ChatBaseData struct {
	ChatKey // BotID & ChatID

	// BotUserID is and ID of a bot user who owns this chat
	BotUserID string // We want it to be indexed and not to omit empty, so we can find chats without bot user assigned.

	// BotUserIDs keeps ids of bot users who are members of a group chat
	BotUserIDs []string `dalgo:",omitempty" datastore:",omitempty" firestore:",omitempty"`

	BotBaseData

	// AppUserIntIDs is kept for legacy reasons
	// Deprecated: replace with `AppUserIDs []string`
	AppUserIntIDs []int64 `dalgo:",omitempty" datastore:",omitempty" firestore:",omitempty"`

	// IsGroup indicates if bot is added/used in a group chat
	IsGroup bool `dalgo:",noindex,omitempty" datastore:",noindex,omitempty" firestore:",omitempty"`

	// Type - TODO: document what is it
	Type string `dalgo:",noindex,omitempty" datastore:",noindex,omitempty" firestore:",omitempty"`

	// Title stores a title of a chat if bot platforms supports named chats
	Title string `dalgo:",noindex,omitempty" datastore:",noindex,omitempty" firestore:",omitempty"`

	// GAClientID is Google Analytics client ID
	// Deprecated: use GAClientIDs AnalyticsClientIDs
	GaClientID []byte `dalgo:",noindex,omitempty" datastore:",noindex,omitempty" firestore:",omitempty"`

	// AnalyticsClientIDs stores IDs of analytics clients. For example {"GA": "1234567890.1234567890"}
	AnalyticsClientIDs map[string]string `dalgo:",noindex,omitempty" datastore:",noindex,omitempty" firestore:",omitempty"`

	// DtLastInteraction must be set through SetDtLastInteraction() as it also increments InteractionsCount
	DtLastInteraction time.Time `dalgo:",omitempty" datastore:",omitempty" firestore:",omitempty"`

	// InteractionsCount is a number of interactions with a bot in this chat
	InteractionsCount int `dalgo:",omitempty" datastore:",omitempty" firestore:",omitempty"`

	// DtForbidden is a time when bot was forbidden to interact with a chat
	DtForbidden time.Time `dalgo:",omitempty" datastore:",omitempty" firestore:",omitempty"`

	// DtForbiddenLast needs documentation on intended usage. TODO: Consider removing
	DtForbiddenLast time.Time `dalgo:",omitempty" datastore:",omitempty" firestore:",omitempty"`
	// contains filtered or unexported fields
}

ChatBaseData hold common properties for bot chat entities not specific to any platform

func (*ChatBaseData) AddClientLanguage added in v0.0.5

func (e *ChatBaseData) AddClientLanguage(languageCode string) (changed bool)

AddClientLanguage adds client UI language

func (*ChatBaseData) AddWizardParam added in v0.0.5

func (e *ChatBaseData) AddWizardParam(key, value string)

AddWizardParam adds context param to state

func (*ChatBaseData) Base added in v0.0.5

func (e *ChatBaseData) Base() *ChatBaseData

func (*ChatBaseData) GetAwaitingReplyTo added in v0.0.5

func (e *ChatBaseData) GetAwaitingReplyTo() string

GetAwaitingReplyTo returns current state

func (*ChatBaseData) GetBotID added in v0.0.5

func (e *ChatBaseData) GetBotID() string

GetBotID returns bot ID

func (*ChatBaseData) GetChatID added in v0.0.5

func (e *ChatBaseData) GetChatID() string

GetChatID returns chat ID

func (*ChatBaseData) GetPreferredLanguage added in v0.0.5

func (e *ChatBaseData) GetPreferredLanguage() string

GetPreferredLanguage returns preferred language

func (*ChatBaseData) GetWizardParam added in v0.0.5

func (e *ChatBaseData) GetWizardParam(key string) string

GetWizardParam returns state param value

func (*ChatBaseData) IsAwaitingReplyTo added in v0.0.5

func (e *ChatBaseData) IsAwaitingReplyTo(code string) bool

IsAwaitingReplyTo returns true if bot us awaiting reply to a specific command

func (*ChatBaseData) IsChanged added in v0.0.5

func (e *ChatBaseData) IsChanged() bool

Indicates that chat data has been changed and record needs to be saved

func (*ChatBaseData) IsGroupChat added in v0.0.5

func (e *ChatBaseData) IsGroupChat() bool

IsGroupChat indicates if it is a group chat

func (*ChatBaseData) Key added in v0.0.5

func (e *ChatBaseData) Key() ChatKey

func (*ChatBaseData) PopStepsFromAwaitingReplyUpToSpecificParent added in v0.0.5

func (e *ChatBaseData) PopStepsFromAwaitingReplyUpToSpecificParent(step string)

PopStepsFromAwaitingReplyUpToSpecificParent go back in state

func (*ChatBaseData) PushStepToAwaitingReplyTo added in v0.0.5

func (e *ChatBaseData) PushStepToAwaitingReplyTo(step string)

PushStepToAwaitingReplyTo go down in state

func (*ChatBaseData) SetAwaitingReplyTo added in v0.0.5

func (e *ChatBaseData) SetAwaitingReplyTo(value string)

SetAwaitingReplyTo sets current state

func (*ChatBaseData) SetBotUserID added in v0.0.5

func (e *ChatBaseData) SetBotUserID(id interface{})

SetBotUserID sets bot user ID

func (*ChatBaseData) SetDtLastInteraction added in v0.0.5

func (e *ChatBaseData) SetDtLastInteraction(v time.Time)

SetDtLastInteraction sets date time of last interaction

func (*ChatBaseData) SetDtUpdateToNow added in v0.0.5

func (e *ChatBaseData) SetDtUpdateToNow()

SetDtUpdateToNow mark entity updated with now

func (*ChatBaseData) SetIsGroupChat added in v0.0.5

func (e *ChatBaseData) SetIsGroupChat(v bool)

SetIsGroupChat marks chat as a group one

func (*ChatBaseData) SetPreferredLanguage added in v0.0.5

func (e *ChatBaseData) SetPreferredLanguage(value string)

SetPreferredLanguage sets preferred language

func (*ChatBaseData) Validate added in v0.0.5

func (e *ChatBaseData) Validate() error

type ChatKey added in v0.0.5

type ChatKey struct {
	// BotID an id of a bot that owns this chat
	BotID string

	// ChatID is an id of a chat as was provided by a bot platform. Might be an integer converted to a string.
	// It's different from ChatInstanceID of Telegram - TODO: document what is the difference an why ChatInstanceID is needed.
	ChatID string
}

ChatKey is a key for a chat that consist of bot ID and chat ID.

func NewChatKey added in v0.0.5

func NewChatKey(botID, chatID string) ChatKey

NewChatKey creates a new chat key

func (ChatKey) String added in v0.0.5

func (k ChatKey) String() string

String returns string representation of a key

func (ChatKey) Validate added in v0.0.5

func (k ChatKey) Validate() error

Validate returns error if key is invalid TODO(StackOverflow): is it better from performance point of view to use a pointer here and in String?

type PreferredLocaleHolder added in v0.3.0

type PreferredLocaleHolder interface {

	// SetPreferredLocale sets preferred locale for the chat as code5 (e.g. en-US)
	SetPreferredLocale(code5 string) error

	// GetPreferredLocale returns preferred locale for the chat as code5 (e.g. en-US)
	GetPreferredLocale() string
}

type UserNamesHolder added in v0.3.0

type UserNamesHolder interface {

	// SetNames sets names of a user.
	SetNames(firstName, lastName, fullName string) error
}

type WithAccessGrantedFlag

type WithAccessGrantedFlag interface {

	// IsAccessGranted returns true if access is granted
	IsAccessGranted() bool

	// SetAccessGranted sets access granted flag
	SetAccessGranted(value bool) bool
}

type WithBotUserIDs added in v0.1.1

type WithBotUserIDs struct {
	BotUserIDs []string `json:"botUserIDs,omitempty" firestore:"botUserIDs,omitempty" dalgo:"botUserIDs,omitempty"`
}

func (*WithBotUserIDs) SetBotUserID added in v0.1.1

func (v *WithBotUserIDs) SetBotUserID(platform, bot, userID string)

Jump to

Keyboard shortcuts

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