alexa

package module
v0.0.0-...-5178dcd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2019 License: MIT Imports: 9 Imported by: 0

README

alexa Build Status GoDoc Go Report Card

Go package for creating Amazon Alexa skills. Not a hundred percent package for all Alexa features. The most basic features exists.

Installation

go get -u github.com/skillkit/go-alexa

Example with HTTP

package main

import (
	"net/http"

	"github.com/skillkit/go-alexa"
)

func main() {
	app := alexa.NewApp(&alexa.Options{
		ApplicationID: "amzn1.ask.skill.aaa",
	})

	app.OnIntent(func(w alexa.ResponseWriter, r *alexa.Request) error {
		w.OutputSpeech("Hello, world!")
		return nil
	})

	http.Handle("/", app.Handler())
	http.ListenAndServe(":3000", nil)
}

License

MIT © Fredrik Forsmo

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyApplicationID        = errors.New("Application ID should not be empty")
	ErrEmptyRequestApplicationID = errors.New("Request Application ID should not be empty")
	ErrNotSameApplicationID      = errors.New("Application ID and Request Application ID is not the same")
	ErrInvalidTimestamp          = errors.New("Invalid timestamp")
	ErrChainURL                  = errors.New("Unable to find certificate chain header")
	ErrBadChainURL               = errors.New("Chain URL is not valid")
	ErrDownloadCert              = errors.New("Certificate could not be downloaded")
	ErrReadCert                  = errors.New("Could not read certification content")
	ErrParsePem                  = errors.New("Failed to parse certificate PEM")
	ErrBadCertDate               = errors.New("Certificate is not valid")
)
View Source
var (
	ErrNoSlotFound = errors.New("No slot found")
)

Functions

This section is empty.

Types

type Alexa

type Alexa struct {
	ApplicationID    string
	IgnoreTimestamp  bool
	IgnoreCertVerify bool
	// contains filtered or unexported fields
}

Alexa represents the Alexa app.

func NewApp

func NewApp(opt *Options) *Alexa

NewApp creates a new Alexa app.

func (*Alexa) Handler

func (a *Alexa) Handler() http.Handler

Handler returns a http handler to hook Alexa app into a http server.

func (*Alexa) OnAudioPlayer

func (a *Alexa) OnAudioPlayer(h HandleFunc)

OnAudioPlayer sets the audio player handler.

func (*Alexa) OnIntent

func (a *Alexa) OnIntent(h HandleFunc)

OnIntent sets the intent handler.

func (*Alexa) OnLaunch

func (a *Alexa) OnLaunch(h HandleFunc)

OnLaunch sets the launch handler.

func (*Alexa) OnSessionEnded

func (a *Alexa) OnSessionEnded(h HandleFunc)

OnSessionEnded sets the session ended handler.

func (*Alexa) OnSessionStarted

func (a *Alexa) OnSessionStarted(h HandleFunc)

OnSessionStarted sets the session started handler.

func (*Alexa) Process

func (a *Alexa) Process(r *Request) (*Response, error)

Process handles a request passed from Alexa.

type Card

type Card struct {
	Type    string `json:"type"`
	Title   string `json:"title,omitempty"`
	Content string `json:"content,omitempty"`
	Text    string `json:"text,omitempty"`
	Image   *Image `json:"image,omitempty"`
}

Card represents the card object in the response to Alexa.

type Directive

type Directive struct {
	Type         string `json:"type"`
	PlayBehavior string `json:"playBehavior,omitempty"`
	AudioItem    *struct {
		Stream *Stream `json:"stream,omitempty"`
	} `json:"audioItem,omitempty"`
}

Directive represents the directive object in the response to Alexa.

type HandleFunc

type HandleFunc func(ResponseWriter, *Request) error

HandleFunc represents the handler function.

type Image

type Image struct {
	SmallImageURL string `json:"smallImageUrl,omitempty"`
	LargeImageURL string `json:"largeImageUrl,omitempty"`
}

Image represents the image object in the response to alexa.

type Intent

type Intent struct {
	Name  string           `json:"name"`
	Slots map[string]*Slot `json:"slots"`
}

Intent represents a intent object from Alexa.

type Options

type Options struct {
	ApplicationID    string
	IgnoreTimestamp  bool
	IgnoreCertVerify bool
}

Options represents Alexa app options.

type OutputSpeech

type OutputSpeech struct {
	Type string `json:"type"`
	Text string `json:"text,omitempty"`
	SSML string `json:"ssml,omitempty"`
}

OutputSpeech represents the output speech object in the response to Alexa.

type Reprompt

type Reprompt struct {
	OutputSpeech *OutputSpeech `json:"outputSpeech,omitempty"`
}

Reprompt represents the reprompt object in the response to Alexa.

type Request

type Request struct {
	Context struct {
		AudioPlayer struct {
			OffsetInMilliseconds int    `json:"offsetInMilliseconds"`
			PlayerActivity       string `json:"playerActivity"`
			Token                string `json:"token"`
		} `json:"AudioPlayer"`
		System struct {
			APIAccessToken string `json:"apiAccessToken"`
			APIEndpoint    string `json:"apiEndpoint"`
			Application    struct {
				ApplicationID string `json:"applicationId"`
			} `json:"application"`
			Device struct {
				DeviceID            string `json:"deviceId"`
				SupportedInterfaces struct {
					AudioPlayer struct{} `json:"AudioPlayer"`
				} `json:"supportedInterfaces"`
			} `json:"device"`
			User struct {
				AccessToken string `json:"accessToken"`
				Permissions struct {
					ConsentToken string `json:"consentToken"`
				} `json:"permissions"`
				UserID string `json:"userId"`
			} `json:"user"`
		} `json:"System"`
	} `json:"context"`
	Session struct {
		New        bool   `json:"new"`
		SessionID  string `json:"sessionId"`
		Attributes struct {
		} `json:"attributes"`
		User struct {
			AccessToken string `json:"accessToken"`
			UserID      string `json:"userId"`
		} `json:"user"`
		Application struct {
			ApplicationID string `json:"applicationId"`
		} `json:"application"`
	} `json:"session"`
	Request struct {
		Locale    string  `json:"locale"`
		Timestamp string  `json:"timestamp"`
		Type      string  `json:"type"`
		RequestID string  `json:"requestId"`
		Intent    *Intent `json:"intent"`
	} `json:"request"`
	Version string `json:"version"`
}

Request represents the payload object from Alexa.

func (*Request) APIAccessToken

func (r *Request) APIAccessToken() string

APIAccessToken returns the access token for Alexa API.

func (*Request) APIEndpoint

func (r *Request) APIEndpoint() string

APIEndpoint returns Alexa API endpoint.

func (*Request) ApplicationID

func (r *Request) ApplicationID() string

ApplicationID returns the application id.

func (*Request) DeviceID

func (r *Request) DeviceID() string

DeviceID returns the device id.

func (*Request) IntentName

func (r *Request) IntentName() string

IntentName returns the intent name.

func (*Request) SessionID

func (r *Request) SessionID() string

SessionID returns the session id.

func (*Request) Slot

func (r *Request) Slot(name string) (*Slot, error)

Slot will find a slot by name if it exists or return a error.

func (*Request) UserID

func (r *Request) UserID() string

UserID returns the user id.

type Response

type Response struct {
	Response          *ResponseObject        `json:"response"`
	SessionAttributes map[string]interface{} `json:"sessionAttributes,omitempty"`
	Version           string                 `json:"version"`
}

Response represents the top level response object to Alexa.

func NewResponse

func NewResponse() *Response

NewResponse creates a new default response.

func (*Response) EndSession

func (r *Response) EndSession(end bool)

EndSession will set the should session end value.

func (*Response) LinkAccountCard

func (r *Response) LinkAccountCard()

LinkAccountCard will set the response card as a link account card.

func (*Response) OutputSpeech

func (r *Response) OutputSpeech(content string)

OutputSpeech will set the output speech as plain text.

func (*Response) OutputSpeechSSML

func (r *Response) OutputSpeechSSML(content string)

OutputSpeechSSML will set the output speech as SSML.

func (*Response) RepromptSSML

func (r *Response) RepromptSSML(content string)

RepromptSSML will set the reprompt output speech as SSML.

func (*Response) RepromptSpeech

func (r *Response) RepromptSpeech(content string)

RepromptSpeech will set the reprompt output speech as plain text.

func (*Response) SimpleCard

func (r *Response) SimpleCard(title, content string)

SimpleCard will set the response card as a simple card.

func (*Response) StandardCard

func (r *Response) StandardCard(title, content, smallImageURL, largeImageURL string)

StandardCard will set the response card as a standard card with images.

func (*Response) String

func (r *Response) String() (string, error)

String will return the response as JSON.

type ResponseObject

type ResponseObject struct {
	OutputSpeech     *OutputSpeech `json:"outputSpeech,omitempty"`
	Card             *Card         `json:"card,omitempty"`
	Reprompt         *Reprompt     `json:"reprompt,omitempty"`
	Directives       *[]Directive  `json:"directives,omitempty"`
	ShouldSessionEnd bool          `json:"shouldEndSession"`
}

ResponseObject represents the response object in the response to Alexa.

type ResponseWriter

type ResponseWriter interface {
	EndSession(bool)
	LinkAccountCard()
	OutputSpeech(string)
	OutputSpeechSSML(string)
	RepromptSpeech(string)
	RepromptSSML(string)
	SimpleCard(string, string)
	StandardCard(string, string, string, string)
	String() (string, error)
}

ResponseWriter represents the interface that handle a response to Alexa.

type Slot

type Slot struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

Slot represents a slot object from Alexa.

type Stream

type Stream struct {
	Token                string `json:"token"`
	URL                  string `json:"url"`
	OffsetInMilliseconds int    `json:"offsetInMilliseconds"`
}

Stream represents the stream object in the response to Alexa.

Directories

Path Synopsis
examples
lambda-apex command
lambda-aws command
lambda-eawsy command
simple command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL