This repository has been archived on 2023-07-05. You can view files and clone it, but cannot push or open issues or pull requests.
clessy/mods/talk.go

59 lines
1.2 KiB
Go
Raw Normal View History

2017-04-19 16:10:33 +00:00
package main
import (
"errors"
"fmt"
"github.com/hamcha/clessy/tg"
"github.com/kurrik/witgo/v1/witgo"
)
type ClessyHandler struct {
}
var wit *witgo.Witgo
var witHandler ClessyHandler
func inittalk() {
// Disable if token is not provided
if *wittoken == "" {
panic(errors.New("No or empty wit token provided (-wit)"))
}
witgo.NewWitgo(witgo.NewClient(*wittoken), &witHandler)
}
func talk(broker *tg.Broker, update tg.APIMessage) {
}
func (h *ClessyHandler) Action(session *witgo.Session, action string) (response *witgo.Session, err error) {
response = session
response.Context.Set("forecast", "sunny")
return
}
func (h *ClessyHandler) Say(session *witgo.Session, msg string) (response *witgo.Session, err error) {
response = session
fmt.Printf("< %v\n", msg)
return
}
func (h *ClessyHandler) Merge(session *witgo.Session, entities witgo.EntityMap) (response *witgo.Session, err error) {
var (
value string
)
response = session
if value, err = entities.FirstEntityValue("location"); err != nil {
response.Context = witgo.Context{}
err = nil
} else {
response.Context.Merge(witgo.Context{
"loc": value,
})
}
return
}
func (h *ClessyHandler) Error(session *witgo.Session, msg string) {
}