temapavloff / galice

Golang SDK for Yandex Alice

Home Page:https://godoc.org/github.com/temapavloff/galice

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

galice - golang SDK for Yandex Alice Build Status Go Report Card

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!

Installation

go get -u github.com/temapavloff/galice

Usage

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))

About

Golang SDK for Yandex Alice

https://godoc.org/github.com/temapavloff/galice

License:MIT License


Languages

Language:Go 100.0%