Giter Site home page Giter Site logo

askgo's Introduction

askgo

License

Alexa Skill Kit for GoLang (askgo) is a lightweight impelementation of the Alexa Skill Kit patterns that is found in both the JavaScript and Java SDKs. While keeping in the spirit of Go.

accept interfaces, return structs

Usage

This explanation assumes familiarity with with AWS Documentation. Please review Developing an Alexa Skill as a Lambda Function before proceeding. This SDK addresses some of the steps documented here for you, but you should be familiar with the entire process.

The examples directory provides example usage.

The Alexa struct is the initial interface point with the SDK. Alexa must be initialized first. The struct is defined as:

type Skill struct {
    ApplicationID       string
    IgnoreTimestamp     bool

    RequestInterceptors  []RequestInterceptor
    Handlers             []RequestHandler
    ResponseInterceptors []ResponseInterceptor
    ErrorHandlers        []ErrorHandler
}

The ApplicationID must match the ApplicationID defined in the Alexa Skills, if it is the empty string it is ignored.

IgnoreTimestamp should be used during debugging to test with hard-coded requests.

Requests from Alexa should be passed into the ProcessRequest method. The askgo.DefaultHandler is a standard wrapper for generating an interface that is compatible with HandleInput.

Sample code from a lambda main function

lambda.Start(func(ctx context.Context, envelope *askgo.RequestEnvelope) (interface{}, error) {
    return skill.ProcessRequest(&askgo.DefaultHandler{Envelope: envelope})
})

To be consistent with the AWS skills kit, request handling is broken up into some clear steps.

  • Preprocessing -- RequestInterceptor
  • Handling -- RequstHandler
  • Preprocessing -- ResponseInterceptor
  • Errors -- if any of the Pre/Handle/Post processors return an error, this is passed to the Error Handler

There is no magic support for SessionEnd or OnLaunch, please make sure you're handling those events.

// RequestHandler interface
type RequestHandler interface {
    CanHandle(input HandlerInput) bool
    Handle(input HandlerInput) (*ResponseEnvelope, error)
}
// ErrorHandler interface
type ErrorHandler interface {
    CanHandle(input HandlerInput, e error) bool
    Handle(input HandlerInput, e error) (*ResponseEnvelope, error)
}
// RequestInterceptor interface
type RequestInterceptor interface {
    Process(input HandlerInput) error
}
// ResponseInterceptor interface
type ResponseInterceptor interface {
    Process(input HandlerInput, response *ResponseEnvelope) error
}

Response generation, to generate a response it's similar to the Builder model that is found in the Java/JavaScript SDKs however, we're subscribing to the pass interfaces return structs model of Go the response object is fully constructed as methods are called

For example a response can be as simple as this

return input.GetResponse().WithShouldEndSession(false).Speak("Shall we play a game?"), nil

samples

Quiz Game

Limitations

This version does not support use as a standalone web server as it does not implement any of the HTTPS validation. It was developed to be used as an AWS Lambda function using AWS Labda Go support.

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.