interact

package
v1.44.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2023 License: AGPL-3.0 Imports: 22 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 AddMessenger added in v1.27.0

func AddMessenger(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 Button added in v1.27.0

type Button struct {
	Text  string
	Name  string
	Value string
}

type ButtonReply added in v1.27.0

type ButtonReply interface {
	// AddButton adds the button to the reply
	AddButton(text string)
}

ButtonReply can be used if your reply needs button user interface.

type CallbackResponder added in v1.27.0

type CallbackResponder interface {
	SetCallbackResponder(responder Responder)
}

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 DialogReply added in v1.27.0

type DialogReply interface {
	// AddButton adds the button to the reply
	Dialog(title, text string, buttons []string)
}

DialogReply can be used if your reply needs Dialog user interface

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) AddMessenger added in v1.27.0

func (it *Interact) AddMessenger(messenger Messenger)

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

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

type KeyboardController added in v1.27.0

type KeyboardController interface {
	// RemoveKeyboard hides the keyboard from the client user interface
	RemoveKeyboard()
}

KeyboardController is used when messenger supports keyboard controls

type Messenger

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

type Option added in v1.27.0

type Option struct {
	// Name is the form field name
	Name string

	// Label is the option label for display
	Label string

	// Value is the option value
	Value string
}

type Reply

type Reply interface {
	// Send sends the message directly to the client's session
	Send(message string)

	// Message sets the message to the reply
	Message(message string)

	// AddButton adds the button to the reply
	AddButton(text string, name, value string)

	// AddMultipleButtons adds multiple buttons to the reply
	AddMultipleButtons(buttonsForm [][3]string)
}

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 Slack added in v1.27.0

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

func NewSlack added in v1.27.0

func NewSlack(client *slack.Client) *Slack

func (*Slack) AddCommand added in v1.27.0

func (s *Slack) AddCommand(command *Command, responder Responder)

func (*Slack) EmitAuthorized added in v1.27.0

func (s *Slack) EmitAuthorized(userSession *SlackSession)

func (*Slack) EmitEventsApi added in v1.27.0

func (s *Slack) EmitEventsApi(evt slackevents.EventsAPIEvent)

func (*Slack) OnAuthorized added in v1.27.0

func (s *Slack) OnAuthorized(cb func(userSession *SlackSession))

func (*Slack) OnEventsApi added in v1.27.0

func (s *Slack) OnEventsApi(cb func(evt slackevents.EventsAPIEvent))

func (*Slack) SetTextMessageResponder added in v1.27.0

func (s *Slack) SetTextMessageResponder(responder Responder)

func (*Slack) Start added in v1.27.0

func (s *Slack) Start(ctx context.Context)

type SlackReply added in v1.27.0

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

func (*SlackReply) AddButton added in v1.27.0

func (reply *SlackReply) AddButton(text string, name string, value string)

func (*SlackReply) AddMultipleButtons added in v1.29.0

func (reply *SlackReply) AddMultipleButtons(buttonsForm [][3]string)

func (*SlackReply) Choose added in v1.27.0

func (reply *SlackReply) Choose(prompt string, options ...Option)

func (*SlackReply) InputText added in v1.27.0

func (reply *SlackReply) InputText(prompt string, textFields ...TextField)

func (*SlackReply) Message added in v1.27.0

func (reply *SlackReply) Message(message string)

func (*SlackReply) RemoveKeyboard added in v1.27.0

func (reply *SlackReply) RemoveKeyboard()

RemoveKeyboard is not supported by Slack

func (*SlackReply) Send added in v1.27.0

func (reply *SlackReply) Send(message string)

type SlackSession added in v1.27.0

type SlackSession struct {
	BaseSession

	ChannelID string
	UserID    string
	// contains filtered or unexported fields
}

func NewSlackSession added in v1.27.0

func NewSlackSession(slack *Slack, userID, channelID string) *SlackSession

func (*SlackSession) ID added in v1.27.0

func (s *SlackSession) ID() string

func (*SlackSession) SetAuthorized added in v1.27.0

func (s *SlackSession) SetAuthorized()

type SlackSessionMap added in v1.27.0

type SlackSessionMap map[string]*SlackSession

type State

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

func ParseFuncArgsAndCall added in v1.36.0

func ParseFuncArgsAndCall(f interface{}, args []string, objects ...interface{}) (State, error)

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 NewTelegram added in v1.27.0

func NewTelegram(bot *telebot.Bot) *Telegram

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) SetCallbackResponder added in v1.27.0

func (tm *Telegram) SetCallbackResponder(responder CallbackResponder)

func (*Telegram) SetTextMessageResponder

func (tm *Telegram) SetTextMessageResponder(responder Responder)

func (*Telegram) Start

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

type TelegramReply

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

func (*TelegramReply) AddButton

func (r *TelegramReply) AddButton(text string, name string, value string)

func (*TelegramReply) AddMultipleButtons added in v1.29.0

func (r *TelegramReply) AddMultipleButtons(buttonsForm [][3]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 TextField added in v1.27.0

type TextField struct {
	// Name is the form field name
	Name string

	// Label is the field label
	Label string

	// PlaceHolder is the sample text in the text input
	PlaceHolder string
}

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