-
Notifications
You must be signed in to change notification settings - Fork 2
/
cognitive.go
40 lines (33 loc) 路 930 Bytes
/
cognitive.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package uselessbox
import (
"context"
neo "github.com/bregydoc/neocortex"
"github.com/rs/xid"
)
type Cognitive struct {
doneContextCallbacks []*func(c *neo.Context)
}
func NewCognitive() *Cognitive {
return &Cognitive{}
}
func (useless *Cognitive) CreateNewContext(c *context.Context, info neo.PersonInfo) *neo.Context {
id := xid.New()
return &neo.Context{
Context: c,
SessionID: id.String(),
Person: info,
Variables: map[string]interface{}{},
}
}
func (useless *Cognitive) GetProtoResponse(c *neo.Context, in *neo.Input) (*neo.Output, error) {
if c == nil {
return nil, neo.ErrContextNotExist
}
return useless.NewOutputText(c), nil
}
func (useless *Cognitive) OnContextIsDone(callback func(c *neo.Context)) {
if useless.doneContextCallbacks == nil {
useless.doneContextCallbacks = []*func(c *neo.Context){}
}
useless.doneContextCallbacks = append(useless.doneContextCallbacks, &callback)
}