This library provides some basic helpers for Yandex Alice API:
- go structs for representing API entities;
- helper function for creating incoming webhook HTTP handler.
For more details on Alice API see official documentation and package godoc.
Note. Responses with image cards not supported in this SDK version!
go get -u github.com/temapavloff/galice
Setting up client:
c:= galice.New(
// autoPings=true; automatically handle Alice API healthcheck requests (respond with pond to pings);
// if false, you have to handle such requests in your own AliceHandler
true,
// autoDanderousContext=true; automatically handle requests marked as dangerous by Alice API.
// Dangerous requests may contain suicide thoughts, hate speech, threats, etc.
// If false, you have to handle such requests in your own AliceHandler
true)
// Logger function will be called if some error occured while handling Alice API incoming request:
// bad requests, invalid responses, unexpected panics, etc.
// Default logger simply writes to stderr
c.SetLogger(func (err error) {
fmt.Print(err)
})
Setting up request handler for simple skill which respond with user input message and closes session:
h := cli.CreateHandler(func(i InputData) (OutputData, error) {
r := NewResponse(i.Request.OriginalUtterance, "", true)
return NewOutput(i, r), nil
})
http.Handle("/skill", h)
log.Fatal(http.ListenAndServe(":8080", nil))
Adding buttons to response:
h := cli.CreateHandler(func(i InputData) (OutputData, error) {
r := NewResponse("Hi!", "", true)
r.AddButton("Link somewhere", false, "https://yandex.ru", nil) // Add Link button
p := map[string]string{"key1": "val1", "key2": "val2"}
r.AddButton("Payload", false, "", p) // Add button with some payload
return NewOutput(i, r), nil
})
http.Handle("/skill", h)
log.Fatal(http.ListenAndServe(":8080", nil))