bots

package
v0.0.0-...-9d454ad Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoAction

func DoAction(name string, args map[string]interface{}, actions Actions, store ActionStore) (interface{}, error)

DoAction does an action

Types

type Action

type Action struct {
	Method string                 `json:"method"`
	Store  string                 `json:"store"`
	Query  map[string]interface{} `json:"query"`
	Data   map[string]interface{} `json:"data"`
	Error  *Error                 `json:"error"`
	Next   *Action                `json:"next"`
}

Action an action that can be performed

type ActionStore

type ActionStore interface {
	Do(action *Action, args map[string]interface{}) (interface{}, error)
}

ActionStore used to get information for action

type Actions

type Actions map[string]*Action

Actions defines certain actions a bot can process

type Answer

type Answer struct {
	ID          string    `json:"id"`
	Action      string    `json:"action"`
	Answer      string    `json:"answer"`
	Created     time.Time `json:"created_at"`
	Modified    time.Time `json:"modified_at"`
	Question    *Question `json:"question"`
	Type        string    `json:"type"`
	MessageText string    `json:"messageText"`
	MessageID   string    `json:"messageID"`
}

Answer stores an answer

type DostowActionStore

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

DostowActionStore an action store that uses dostow

func NewDostowActionStore

func NewDostowActionStore(api *api.Client) *DostowActionStore

NewDostowActionStore create new store

func (*DostowActionStore) Do

func (d *DostowActionStore) Do(action *Action, args map[string]interface{}) (interface{}, error)

Do perform an action

type DostowBot

type DostowBot struct {
	*handlers.MessageHandler
	// contains filtered or unexported fields
}

DostowBot a bot that uses dostow

func NewDostowBot

func NewDostowBot(a *api.Client, questionStore, answerStore string,
	actions Actions, actionStore ActionStore, handler *handlers.MessageHandler) *DostowBot

NewDostowBot create a dostow bot with actions and a message handler

func (*DostowBot) GetLastAnswer

func (d *DostowBot) GetLastAnswer(message *whatsapp.TextMessage) (*Answer, error)

GetLastAnswer get the last answer a whatsapp user sent

func (*DostowBot) HandleTextMessage

func (d *DostowBot) HandleTextMessage(message whatsapp.TextMessage)

HandleTextMessage see MessageHandler.HandleTextMessage

func (*DostowBot) MessageToMap

func (d *DostowBot) MessageToMap(message *whatsapp.TextMessage) map[string]interface{}

MessageToMap convert message to map

func (*DostowBot) SendAnswer

func (d *DostowBot) SendAnswer(q *Question, message *whatsapp.TextMessage, text string) error

SendAnswer send a text message

func (*DostowBot) TriggerAction

func (d *DostowBot) TriggerAction(action string, message *whatsapp.TextMessage, answer *Answer) (interface{}, error)

TriggerAction trigger an action

type Error

type Error struct {
	Message string                 `json:"msg"`
	Data    map[string]interface{} `json:"data"`
}

Error error message template

type Question

type Question struct {
	ID       string    `json:"id"`
	Action   string    `json:"action"`
	Answer   string    `json:"answer"`
	Created  time.Time `json:"created_at"`
	Modified time.Time `json:"modified_at"`
	Next     *Question `json:"next"`
	Question string    `json:"question"`
	Type     string    `json:"type"`
}

Question stores a question

Jump to

Keyboard shortcuts

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