bot

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrValidationFailed = errors.New("the callback token is invalid")

ErrValidationFailed happens when a channel cannot validate an incoming callback

Functions

This section is empty.

Types

type Auth added in v0.6.0

type Auth struct {
	Token string `mapstructure:"token"`
}

Auth is authorization for the bot API

type Bot

type Bot struct {
	Name       string
	Store      store.Store
	Domain     *fsm.Domain
	Classifier *clf.Classifier
	Extensions extension.ServerMap
	Channels   *channels.Channels
	Config     *Config
	Router     *mux.Router
}

Bot models a bot with a Classifier and an FSM

func New

func New(botConfig *Config) (*Bot, error)

New initializes and returns a new Bot

func (*Bot) Answer

func (b *Bot) Answer(receiveMsg *messages.Receive) ([]query.Answer, error)

Answer takes a user input and executes a transition on the FSM if possible

func (*Bot) ChannelHandler added in v0.7.0

func (b *Bot) ChannelHandler(w http.ResponseWriter, r *http.Request, chnl channels.Channel)

ChannelHandler takes an incoming http.Request and passes it to a channel for it to respond

func (*Bot) RegisterRoutes

func (b *Bot) RegisterRoutes()

RegisterRoutes with the bot router

func (*Bot) Run

func (b *Bot) Run()

Run starts the bot which is a long running process

type Config

type Config struct {
	Name           string                  `mapstructure:"bot_name"`
	Extensions     extension.ConfigMap     `mapstructure:"extensions"`
	Store          storeconfig.StoreConfig `mapstructure:"store"`
	Port           int                     `mapstructure:"port"`
	Path           string
	Conversation   Conversation `mapstructure:"conversation"`
	Auth           Auth         `mapstructure:"auth"`
	EnableRESTCORS bool         `mapstructure:"enable_rest_cors"`
}

Config struct models the bot.yml configuration file

func LoadConfig

func LoadConfig(path string, port int) (*Config, error)

LoadConfig loads bot configuration from bot.yml

func (*Config) ShouldReplyError added in v0.6.0

func (c *Config) ShouldReplyError(isExistingConversation bool) bool

ShouldReplyError depending on the conversational settings lets the bot know if it should reply with Error to the channel

func (*Config) ShouldReplyUnknown added in v0.6.0

func (c *Config) ShouldReplyUnknown(isExistingConversation bool) bool

ShouldReplyUnknown depending on the conversational settings lets the bot know if it should reply with Unknown to the channel

func (*Config) ShouldReplyUnsure added in v0.6.0

func (c *Config) ShouldReplyUnsure(isExistingConversation bool) bool

ShouldReplyUnsure depending on the conversational settings lets the bot know if it should reply with Unsure to the channel

type Conversation added in v0.6.0

type Conversation struct {
	New      ConversationConfig `mapstructure:"new"`
	Existing ConversationConfig `mapstructure:"existing"`
}

Conversation settings for new and existing conversations

type ConversationConfig added in v0.6.0

type ConversationConfig struct {
	ReplyUnsure  bool `mapstructure:"reply_unsure"`
	ReplyUnknown bool `mapstructure:"reply_unknown"`
	ReplyError   bool `mapstructure:"reply_error"`
}

ConversationConfig for the bot

type ErrUnknownExtension added in v0.6.0

type ErrUnknownExtension struct {
	Extension string
}

ErrUnknownExtension is returned by the Bot when the provided extension name does not exist

func (*ErrUnknownExtension) Error added in v0.6.0

func (e *ErrUnknownExtension) Error() string

Error returns the ErrUnknownExtension error message

type Prediction

type Prediction struct {
	Original    string  `json:"original"`
	Predicted   string  `json:"predicted"`
	Probability float32 `json:"probability"`
}

Prediction models a classifier prediction and its original string

Jump to

Keyboard shortcuts

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