interact

package
v1.26.1 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2022 License: MIT Imports: 14 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAuthenticationFailed = errors.New("authentication failed")

Functions

func AddCustomInteraction added in v1.26.0

func AddCustomInteraction(custom CustomInteraction)

func SetMessenger added in v1.26.0

func SetMessenger(messenger Messenger)

func Start added in v1.26.0

func Start(ctx context.Context) error

Types

type AuthInteract

type AuthInteract struct {
	Strict bool `json:"strict,omitempty"`

	Mode AuthMode `json:"authMode"`

	Token string `json:"authToken,omitempty"`

	OneTimePasswordKey *otp.Key `json:"otpKey,omitempty"`
}

func (*AuthInteract) Commands

func (it *AuthInteract) Commands(interact *Interact)

type AuthMode

type AuthMode string
const (
	AuthModeOTP   AuthMode = "OTP"
	AuthModeToken AuthMode = "TOKEN"
)

type Authorizer

type Authorizer interface {
	StartAuthorizing()
	Authorize() error
}

type BaseSession added in v1.26.1

type BaseSession struct {
	OriginState  State     `json:"originState,omitempty"`
	CurrentState State     `json:"currentState,omitempty"`
	Authorized   bool      `json:"authorized,omitempty"`
	StartedTime  time.Time `json:"startedTime,omitempty"`
	// contains filtered or unexported fields
}

func (*BaseSession) GetOriginState added in v1.26.1

func (s *BaseSession) GetOriginState() State

func (*BaseSession) GetState added in v1.26.1

func (s *BaseSession) GetState() State

func (*BaseSession) IsAuthorized added in v1.26.1

func (s *BaseSession) IsAuthorized() bool

func (*BaseSession) SetAuthorized added in v1.26.1

func (s *BaseSession) SetAuthorized()

func (*BaseSession) SetAuthorizing added in v1.26.1

func (s *BaseSession) SetAuthorizing(b bool)

func (*BaseSession) SetOriginState added in v1.26.1

func (s *BaseSession) SetOriginState(state State)

func (*BaseSession) SetState added in v1.26.1

func (s *BaseSession) SetState(state State)

type Command

type Command struct {
	// Name is the command name
	Name string

	// Desc is the command description
	Desc string

	// StateF is the command handler function
	F interface{}
	// contains filtered or unexported fields
}

Command is a domain specific language syntax helper It's used for helping developer define the state and transition function

func NewCommand

func NewCommand(name, desc string, f interface{}) *Command

func (*Command) Cycle added in v1.26.0

func (c *Command) Cycle(f interface{}) *Command

func (*Command) NamedNext

func (c *Command) NamedNext(n State, f interface{}) *Command

func (*Command) Next

func (c *Command) Next(f interface{}) *Command

Next defines the next state with the transition function from the last defined state.

func (*Command) Transit

func (c *Command) Transit(state1, state2 State, f interface{}) *Command

Transit defines the state transition that is not related to the last defined state.

type CommandResponder

type CommandResponder interface {
	AddCommand(command *Command, responder Responder)
}

type CustomInteraction

type CustomInteraction interface {
	Commands(interact *Interact)
}

type Initializer added in v1.26.0

type Initializer interface {
	Initialize() error
}

type Interact

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

Interact implements the interaction between bot and message software.

func Default added in v1.26.0

func Default() *Interact

func New

func New() *Interact

func (*Interact) AddCustomInteraction

func (it *Interact) AddCustomInteraction(custom CustomInteraction)

func (*Interact) Command

func (it *Interact) Command(command string, desc string, f interface{}) *Command

func (*Interact) PrivateCommand

func (it *Interact) PrivateCommand(command, desc string, f interface{}) *Command

func (*Interact) SetMessenger

func (it *Interact) SetMessenger(messenger Messenger)

func (*Interact) Start

func (it *Interact) Start(ctx context.Context) error

type Messenger

type Messenger interface {
	TextMessageResponder
	CommandResponder
	Start(ctx context.Context)
}

type Reply

type Reply interface {
	Send(message string)
	Message(message string)
	AddButton(text string)
	RemoveKeyboard()
}

type Responder

type Responder func(session Session, message string, reply Reply, ctxObjects ...interface{}) error

Responder defines the logic of responding the message

type Session added in v1.26.1

type Session interface {
	ID() string
	SetOriginState(state State)
	GetOriginState() State
	SetState(state State)
	GetState() State
	IsAuthorized() bool
	SetAuthorized()
	SetAuthorizing(b bool)
}

type State

type State string
const (
	StatePublic        State = "public"
	StateAuthenticated State = "authenticated"
)

type Telegram

type Telegram struct {
	Bot *telebot.Bot `json:"-"`

	// Private is used to protect the telegram bot, users not authenticated can not see messages or sending commands
	Private bool `json:"private,omitempty"`
	// contains filtered or unexported fields
}

func (*Telegram) AddCommand

func (tm *Telegram) AddCommand(cmd *Command, responder Responder)

func (*Telegram) EmitAuthorized added in v1.26.0

func (tm *Telegram) EmitAuthorized(s *TelegramSession)

func (*Telegram) OnAuthorized added in v1.26.0

func (tm *Telegram) OnAuthorized(cb func(s *TelegramSession))

func (*Telegram) RestoreSessions added in v1.26.1

func (tm *Telegram) RestoreSessions(sessions TelegramSessionMap)

func (*Telegram) Sessions added in v1.26.1

func (tm *Telegram) Sessions() TelegramSessionMap

func (*Telegram) SetTextMessageResponder

func (tm *Telegram) SetTextMessageResponder(textMessageResponder Responder)

func (*Telegram) Start

func (tm *Telegram) Start(context.Context)

type TelegramReply

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

func (*TelegramReply) AddButton

func (r *TelegramReply) AddButton(text string)

func (*TelegramReply) Message

func (r *TelegramReply) Message(message string)

func (*TelegramReply) RemoveKeyboard

func (r *TelegramReply) RemoveKeyboard()

func (*TelegramReply) Send added in v1.26.0

func (r *TelegramReply) Send(message string)

type TelegramSession added in v1.26.0

type TelegramSession struct {
	BaseSession

	User *telebot.User `json:"user"`
	Chat *telebot.Chat `json:"chat"`
	// contains filtered or unexported fields
}

func NewTelegramSession added in v1.26.0

func NewTelegramSession(telegram *Telegram, message *telebot.Message) *TelegramSession

func (*TelegramSession) ID added in v1.26.1

func (s *TelegramSession) ID() string

func (*TelegramSession) SetAuthorized added in v1.26.1

func (s *TelegramSession) SetAuthorized()

type TelegramSessionMap added in v1.26.1

type TelegramSessionMap map[int64]*TelegramSession

type TextMessageResponder

type TextMessageResponder interface {
	SetTextMessageResponder(responder Responder)
}

Jump to

Keyboard shortcuts

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