interact

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: AGPL-3.0 Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func AddCustomInteraction

func AddCustomInteraction(custom CustomInteraction)

func AddMessenger

func AddMessenger(messenger Messenger)

func Start

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

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

func (s *BaseSession) GetOriginState() State

func (*BaseSession) GetState

func (s *BaseSession) GetState() State

func (*BaseSession) IsAuthorized

func (s *BaseSession) IsAuthorized() bool

func (*BaseSession) SetAuthorized

func (s *BaseSession) SetAuthorized()

func (*BaseSession) SetAuthorizing

func (s *BaseSession) SetAuthorizing(b bool)

func (*BaseSession) SetOriginState

func (s *BaseSession) SetOriginState(state State)

func (*BaseSession) SetState

func (s *BaseSession) SetState(state State)

type Button

type Button struct {
	Text  string
	Name  string
	Value string
}

type ButtonReply

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

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

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

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

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

func Default() *Interact

func New

func New() *Interact

func (*Interact) AddCustomInteraction

func (it *Interact) AddCustomInteraction(custom CustomInteraction)

func (*Interact) AddMessenger

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

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

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

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

type Slack

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

func NewSlack

func NewSlack(client *slack.Client) *Slack

func (*Slack) AddCommand

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

func (*Slack) EmitAuthorized

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

func (*Slack) EmitEventsApi

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

func (*Slack) OnAuthorized

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

func (*Slack) OnEventsApi

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

func (*Slack) SetTextMessageResponder

func (s *Slack) SetTextMessageResponder(responder Responder)

func (*Slack) Start

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

type SlackReply

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

func (*SlackReply) AddButton

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

func (*SlackReply) AddMultipleButtons

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

func (*SlackReply) Choose

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

func (*SlackReply) InputText

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

func (*SlackReply) Message

func (reply *SlackReply) Message(message string)

func (*SlackReply) RemoveKeyboard

func (reply *SlackReply) RemoveKeyboard()

RemoveKeyboard is not supported by Slack

func (*SlackReply) Send

func (reply *SlackReply) Send(message string)

type SlackSession

type SlackSession struct {
	BaseSession

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

func NewSlackSession

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

func (*SlackSession) ID

func (s *SlackSession) ID() string

func (*SlackSession) SetAuthorized

func (s *SlackSession) SetAuthorized()

type SlackSessionMap

type SlackSessionMap map[string]*SlackSession

type State

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

func ParseFuncArgsAndCall

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

func NewTelegram(bot *telebot.Bot) *Telegram

func (*Telegram) AddCommand

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

func (*Telegram) EmitAuthorized

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

func (*Telegram) OnAuthorized

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

func (*Telegram) RestoreSessions

func (tm *Telegram) RestoreSessions(sessions TelegramSessionMap)

func (*Telegram) Sessions

func (tm *Telegram) Sessions() TelegramSessionMap

func (*Telegram) SetCallbackResponder

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

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

func (r *TelegramReply) Send(message string)

type TelegramSession

type TelegramSession struct {
	BaseSession

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

func NewTelegramSession

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

func (*TelegramSession) ID

func (s *TelegramSession) ID() string

func (*TelegramSession) SetAuthorized

func (s *TelegramSession) SetAuthorized()

type TelegramSessionMap

type TelegramSessionMap map[int64]*TelegramSession

type TextField

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