go209

package
v0.0.0-...-6870718 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2019 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package go209 is the core package used to build go209 slack RTM bot (and associated web app)

Index

Constants

View Source
const PreloadedModules = "email-mod:slackwebhook-mod"

PreloadedModules is the list of .so files from the root directory we load by default

View Source
const RedisDefaultExpiration = "29m"

RedisDefaultExpiration is the default period of time a redis state should last for slack has a 30 min window for interactive messages and the response_url even though we don't use the response_url, let's set the timeout slightly shorter

@TODO: Should this be much much shorter, like, 5 minutes? How long is an interaction meant to take?

View Source
const RedisSubTermExpiration = "5m"

RedisSubTermExpiration is the default period of time a redis state should last when handling sub-term matching

View Source
const TemplatePreParserRegex = `\[\[[\w+\|\|]+\w+\]\]`

TemplatePreParserRegex is the regular expression to parse our template pre-parser

View Source
const Version = "0.6.0"

Version of go209

Variables

This section is empty.

Functions

func DumpMods

func DumpMods() error

DumpMods prints information about the loaded modules

func DumpRules

func DumpRules(cfg *BotConfig) error

DumpRules takes the rules.json and dumps it out.

func StartBot

func StartBot(cfg *BotConfig) error

StartBot starts the slack bot

func StartWeb

func StartWeb(cfg *BotConfig) error

StartWeb starts the web server

Types

type BotConfig

type BotConfig struct {
	SlackToken         string
	SlackSigningSecret string
	Debug              bool
	RulesFileLocation  string
	RedisAddr          string
	RedisPwd           string
	RedisDB            int
	WebListen          string
	DynamicModules     string
}

BotConfig defines the configuration that is used by both the slack bot app and web server

type DynamicNext

type DynamicNext struct {
	Response        string `json:"response"`
	NextInteraction string `json:"next_interaction"`
}

DynamicNext defines dynamic branching. This occurs after an interaction, with an attachment, is responded to by a user, which subsequently sends a web hook. We use these to determine the next interaction to present to the user

type Interaction

type Interaction struct {
	InteractionID          string           `json:"interaction_id"`
	StopWord               string           `json:"stop_word"`
	Type                   string           `json:"type"`
	Response               string           `json:"response,omitempty"`
	Question               string           `json:"question,omitempty"`
	NextInteraction        string           `json:"next_interaction"`
	Attachment             slack.Attachment `json:"attachment,omitempty"`
	NextInteractionDynamic []DynamicNext    `json:"next_interaction_dynamic,omitempty"`
}

Interaction defines our interactions we want to present (and handle) from a user. These could be a simple question (storing the next message from the user as a response), or a Slack Attachment (i.e. menu drop down, button)

type LoadedModules

type LoadedModules struct {
	Modules []Module
}

LoadedModules is a struct we use to hold modules and load modules etc

func FetchMods

func FetchMods() LoadedModules

FetchMods returns the modules

func (*LoadedModules) LoadModules

func (m *LoadedModules) LoadModules() error

LoadModules loads up the plugin .so files

type Module

type Module interface {
	Name() string
	EnvVars() []string
	Run(in interface{}, ev map[string]string, interactions map[string]string) error
}

Module defines what our plugins have to define

type Rule

type Rule struct {
	SearchTerms        []string         `json:"terms"`
	Response           string           `json:"response,omitempty"`
	Attachment         slack.Attachment `json:"attachment,omitempty"`
	Interactions       []Interaction    `json:"interactions,omitempty"`
	InteractionStart   string           `json:"interaction_start,omitempty"`
	InteractionEndMods []string         `json:"interaction_end_mods,omitempty"`
	SubTerms           []SubTerm        `json:"subterms,omitempty"`
}

Rule defines the mapping of search terms (i.e. words a user may say to the bot), to a simple response, OR, the initiation of a more complex interaction

type RuleSet

type RuleSet struct {
	Rules                        []Rule `json:"rules"`
	DefaultResponse              string `json:"default"`
	InteractionCancelledResponse string `json:"interaction_cancelled_response,omitempty"`
	InteractionCompleteResponse  string `json:"interaction_complete_response,omitempty"`
}

RuleSet is the parent struct that defines the rules.json file

type SlackUser

type SlackUser struct {
	Username string
	UserID   string
}

SlackUser is only used for template parsing

type SubTerm

type SubTerm struct {
	SearchTerms []string  `json:"terms"`
	Response    string    `json:"response,omitempty"`
	SubTerms    []SubTerm `json:"subterms,omitempty"`
}

SubTerm defines the mapping of a sub-search term The idea is that if a Rule is kicked off, we keep state, and allow secondary or more, search terms, offering simple responses. These are different from Interactions in that we aren't storing state to report anything back.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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