backtalk

package module
v0.0.0-...-078e5a8 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2018 License: BSD-3-Clause Imports: 13 Imported by: 0

README

backtalk GoDoc

Package backtalk is yet another library for writing chatbots in Go.

Status

Backtalk is not production-ready. Its API is not stable and is still subject to dramatic changes.

Documentation

Index

Constants

View Source
const UnableToClassifyIntent = "Backtalk_MetaIntent_UnableToClassifyIntent"

UnableToClassifyIntent is a meta-intent for which a Replyer can be registered to react to unclassifiable inputs.

Variables

View Source
var (
	// ErrUnknownIntent indicates that an intent was claimed in training
	// that wasn't provided to the classifier at construction time.
	ErrUnknownIntent = errors.New("unknown intent")

	// ErrIntentUnclear indicates that the model is unable to provide a
	// classification with high enough confidence to clear the minimum
	// threshold.
	ErrIntentUnclear = errors.New("unable to classify intent")
)

Functions

func ParseTime

func ParseTime(t string) time.Time

ParseTime is a convenience method for converting a Slack timestamp to a native time.Time value.

Types

type Bot

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

func New

func New(api *slack.Client) (*Bot, error)

func (*Bot) RTM

func (b *Bot) RTM() *slack.RTM

RTM provides access to the underlying real-time messaging client to Slack.

func (*Bot) Start

func (b *Bot) Start(ctx context.Context, handler Replyer) error

Start starts listening.

type Classifier

type Classifier interface {
	Train(intent, input string) error
	Classify(input string) (string, error)
}

type IntentMux

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

func NewIntentMux

func NewIntentMux(c Classifier) (*IntentMux, error)

func (*IntentMux) Intent

func (im *IntentMux) Intent(intent string, reply Replyer)

Intent registers a new intent.

func (*IntentMux) Reply

func (im *IntentMux) Reply(rtm *slack.RTM, evt *slack.MessageEvent) error

type NaiveBayesClassifier

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

func NewNaiveBayesClassifier

func NewNaiveBayesClassifier(intents []string, threshold float64) *NaiveBayesClassifier

func NewNaiveBayesClassifierFromModel

func NewNaiveBayesClassifierFromModel(model []byte) (*NaiveBayesClassifier, error)

NewNaiveBayesClassifierFromModel restores a serialized NaiveBayes model.

func (*NaiveBayesClassifier) Classify

func (nbc *NaiveBayesClassifier) Classify(input string) (string, error)

func (*NaiveBayesClassifier) DoneTraining

func (nbc *NaiveBayesClassifier) DoneTraining() error

func (*NaiveBayesClassifier) Train

func (nbc *NaiveBayesClassifier) Train(intent, input string) error

func (*NaiveBayesClassifier) WriteTo

func (nbc *NaiveBayesClassifier) WriteTo(w io.Writer) (n int64, err error)

type ReplyFunc

type ReplyFunc func(rtm *slack.RTM, evt *slack.MessageEvent) error

func (ReplyFunc) Reply

func (rf ReplyFunc) Reply(rtm *slack.RTM, evt *slack.MessageEvent) error

Reply implements Replyer by invoking the ReplyFunc.

type Replyer

type Replyer interface {
	// Reply responds to an RTM event.
	//
	// Returning an error from a handler will kill the bot.
	Reply(rtm *slack.RTM, evt *slack.MessageEvent) error
}

func DirectFilterReplyer

func DirectFilterReplyer(r Replyer) Replyer

DirectFilterReplyer is a filtering Replyer that excludes all messages that aren't explicitly directed at the bot (i.e., @bot).

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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