interact

package
v1.25.5 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

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 Command

type Command struct {
	// Name is the command name
	Name 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 string, 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 string, responder Responder)
}

type CustomInteraction

type CustomInteraction interface {
	Commands(interact *Interact)
}

type Interact

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

Interact implements the interaction between bot and message software.

func New

func New() *Interact

func (*Interact) AddCustomInteraction

func (it *Interact) AddCustomInteraction(custom CustomInteraction)

func (*Interact) Command

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

func (*Interact) PrivateCommand

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

func (*Interact) SetMessenger

func (it *Interact) SetMessenger(messenger Messenger)

func (*Interact) SetOriginState

func (it *Interact) SetOriginState(s State)

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 {
	Message(message string)
	AddButton(text string)
	RemoveKeyboard()
}

type Responder

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

Responder defines the logic of responding the message

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"`

	// Owner is the authorized bot owner
	// This field is exported in order to be stored in file
	Owner *telebot.User `json:"owner,omitempty"`

	// OwnerChat is the chat of the authorized bot owner
	// This field is exported in order to be stored in file
	OwnerChat *telebot.Chat `json:"chat,omitempty"`
	// contains filtered or unexported fields
}

func (*Telegram) AddCommand

func (tm *Telegram) AddCommand(command string, responder Responder)

func (*Telegram) SetTextMessageResponder

func (tm *Telegram) SetTextMessageResponder(textMessageResponder Responder)

func (*Telegram) Start

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

type TelegramAuthorizer

type TelegramAuthorizer struct {
	Telegram *Telegram
	Message  *telebot.Message
}

func (*TelegramAuthorizer) Authorize

func (a *TelegramAuthorizer) Authorize() error

func (*TelegramAuthorizer) StartAuthorizing

func (a *TelegramAuthorizer) StartAuthorizing()

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()

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