pkg

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigPath = path.Join(configDir, "config.yaml")
View Source
var DataPath = path.Join(dataDir, "data.json")
View Source
var FacebookApi = "https://graph.facebook.com/v2.6/me/messages?access_token=%s"

Functions

func Find

func Find(values []string, val string) (int, bool)

Types

type Attachment added in v0.0.2

type Attachment struct {
	Type    string  `json:"type,omitempty"`
	Payload Payload `json:"payload,omitempty"`
}

type Bot

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

Bot is the data structure of the ChatBot.

func NewBot

func NewBot(strategy string, path string) (*Bot, error)

NewBot creates New Bot with empty learned phrases and chosen Strategy

func (*Bot) Add

func (bot *Bot) Add(q string, r string)

Add appends new phrase (query and response) into the ChatBot database

func (*Bot) Adds

func (bot *Bot) Adds(qs []string, rs []string) error

Adds appends multiple phrases (queries, responses) into the ChatBot Database

func (*Bot) CallbackHandler

func (bot *Bot) CallbackHandler(w http.ResponseWriter, r *http.Request)

func (*Bot) Debug

func (bot *Bot) Debug() string

Debug displays the learned queries and possible responses in a nice format

func (*Bot) FullDebug

func (bot *Bot) FullDebug() string

FullDebug displays the learned queries, possible responses and its weights in a nice format

func (*Bot) Get

func (bot *Bot) Get(q string) (string, error)

Get allows the ChatBot to reply a query, according to its intrinsic Strategy

func (*Bot) GetLastMessage

func (bot *Bot) GetLastMessage(id string) (string, error)

func (*Bot) HandleMessage

func (bot *Bot) HandleMessage(inMessage Message, id string)

func (*Bot) LenQueries

func (bot *Bot) LenQueries() int

LenQueries get the total number of learned queries by the ChatBot

func (*Bot) LenResponses

func (bot *Bot) LenResponses(q string) (int, error)

LenResponses get the total number of learned responses for a query by the ChatBot

func (*Bot) Load

func (bot *Bot) Load(path string) error

func (*Bot) PeriodicSave

func (bot *Bot) PeriodicSave(path string)

func (*Bot) RemoveQueries

func (bot *Bot) RemoveQueries(qs []string) error

RemoveQueries delete multiple queries from the ChatBot Database

func (*Bot) RemoveQuery

func (bot *Bot) RemoveQuery(q string) error

RemoveQuery delete a specific query from the ChatBot Database

func (*Bot) RemoveResponse

func (bot *Bot) RemoveResponse(q string, r string) error

RemoveResponse delete a specific response for a specific query from the DataBase

func (*Bot) RemoveResponses

func (bot *Bot) RemoveResponses(qs []string, rs []string) error

RemoveResponses delete responses from the respective queries from the DataBase

func (*Bot) Save

func (bot *Bot) Save(path string) error

func (*Bot) ShowQueries

func (bot *Bot) ShowQueries() []string

ShowQueries shows all of the learned queries by the ChatBot

func (*Bot) ShowResponses

func (bot *Bot) ShowResponses(q string) ([]string, error)

ShowResponses shows all of the learned responses by the ChatBot

func (*Bot) TestHandler

func (bot *Bot) TestHandler(w http.ResponseWriter, r *http.Request)

func (*Bot) UpdateLastMessage

func (bot *Bot) UpdateLastMessage(id string, message string)

func (*Bot) ValidStrategy

func (bot *Bot) ValidStrategy() bool

func (*Bot) VerificationHandler

func (bot *Bot) VerificationHandler(w http.ResponseWriter, r *http.Request)

type Callback added in v0.0.2

type Callback struct {
	Object  string  `json:"object,omitempty"`
	Entries []Entry `json:"entry,omitempty"`
}

type Config

type Config struct {
	Strategy string `yaml:"Strategy"`
}

func LoadConfig

func LoadConfig(path string) (Config, error)

type Entry added in v0.0.2

type Entry struct {
	ID         string      `json:"id,omitempty"`
	Time       int         `json:"time,omitempty"`
	Messagings []Messaging `json:"messaging,omitempty"`
}

type Env

type Env struct {
	VerifyToken     string `required:"true"`
	PageAccessToken string `required:"true"`
	Port            string `required:"true"`
}

func LoadEnv

func LoadEnv() (Env, error)

type GombalErrors

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

func (*GombalErrors) Error

func (e *GombalErrors) Error() string

Error returns the error message related to the Gombal Package

type Message added in v0.0.2

type Message struct {
	MID         string        `json:"mid,omitempty"`
	Text        string        `json:"text,omitempty"`
	QuickReply  *QuickReply   `json:"quick_reply,omitempty"`
	ReplyTo     *ReplyTo      `json:"reply_to,omitempty"`
	Attachments *[]Attachment `json:"attachments,omitempty"`
}

type Messaging added in v0.0.2

type Messaging struct {
	Sender    UserWithRef `json:"sender,omitempty"`
	Recipient User        `json:"recipient,omitempty"`
	Timestamp int         `json:"timestamp,omitempty"`
	Message   Message     `json:"message,omitempty"`
	Postback  Postback    `json:"postback,omitempty"`
}

type Payload added in v0.0.2

type Payload struct {
	URL       string `json:"url,omitempty"`
	Title     string `json:"title,omitempty"`
	StickerId string `json:"sticker_id,omitempty"`
}

type Postback added in v0.0.2

type Postback struct {
	Title   string `json:"title,omitempty"`
	Payload string `json:"payload,omitempty"`
}

type QuickReply added in v0.0.2

type QuickReply struct {
	Payload string `json:"payload,omitempty"`
}

type ReplyTo added in v0.0.2

type ReplyTo struct {
	MID string `json:"mid,omitempty"`
}

type Response added in v0.0.2

type Response struct {
	Recipient User    `json:"recipient,omitempty"`
	Message   Message `json:"message,omitempty"`
}

type Tuple

type Tuple struct {
	Q, R string
}

func Zip

func Zip(as []string, bs []string) ([]Tuple, error)

Zip combines two slices of string into a slice of Tuple

type User added in v0.0.2

type User struct {
	ID string `json:"id,omitempty"`
}

type UserWithRef added in v0.0.2

type UserWithRef struct {
	ID      string `json:"id,omitempty"`
	UserRef string `json:"user_ref,omitempty"`
}

Jump to

Keyboard shortcuts

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