bot

package
v0.0.0-...-522903d Latest Latest
Warning

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

Go to latest
Published: May 9, 2016 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RouteAccept handle the message
	RouteAccept = 1 << iota
	// RouteStop stop handling more messages after this one
	RouteStop
)
View Source
const RouteNothing = 0

RouteNothing do nothing in handling

Variables

This section is empty.

Functions

func MainLoop

func MainLoop(channel chan *telegram.Message, router Router)

MainLoop of the bot to get messages and route them

func NewStorage

func NewStorage(conf *ConfService) (*goejdb.Ejdb, error)

NewStorage creates a new storage

Types

type ConfService

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

ConfService is the configuration service

func LoadConf

func LoadConf(fileName string) (*ConfService, error)

LoadConf loads the configuration from a file

func (*ConfService) Get

func (service *ConfService) Get(in interface{}) error

Get a configuraiton area It unmashals the structure you give from the loaded configuration.

type Context

type Context struct {
	Storage *goejdb.Ejdb
	Conf    *ConfService
	API     telegram.API
}

Context is the global bot context

func CreateContext

func CreateContext(configurationFile string) (*Context, error)

CreateContext for the bot from a configuration file

type Handler

type Handler interface {
	Check(messages *MessageContext) int
	Handle(messages *MessageContext)
}

Handler pairs a check and a handle function

type MessageContext

type MessageContext struct {
	Params  map[string]string
	Message *telegram.AnswerBack
}

MessageContext for each received message

type Router

type Router interface {
	Route(message *telegram.Message)
}

Router routes messages

type Routes

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

Routes stores handlers for messages

func (*Routes) AddHandler

func (router *Routes) AddHandler(definition string, givenHandler Handler)

AddHandler for incoming messages

func (*Routes) Route

func (router *Routes) Route(message *telegram.Message)

Route from a telegram message channel to the respective handler

type StorageConfiguration

type StorageConfiguration struct {
	DBName string `yaml:"dbName"`
}

StorageConfiguration configuration

Jump to

Keyboard shortcuts

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