GithubHelp home page GithubHelp logo

galice's Introduction

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

galice's People

Contributors

temapavloff avatar

Stargazers

maslennikov avatar Pavel Baybara avatar Artem Novichkov avatar Aleksandr Merekin avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.