alexa

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NamespaceAlexa                = "Alexa"
	NamespaceAuthorization        = "Alexa.Authorization"
	NamespaceDiscovery            = "Alexa.Discovery"
	NamespacePercentageController = "Alexa.PercentageController"
	NamespacePowerController      = "Alexa.PowerController"
	NamespaceSceneController      = "Alexa.SceneController"
	NamespaceTemperatureSensor    = "Alexa.TemperatureSensor"
)

Namespace enums

View Source
const (
	DisplayCategoryActivityTrigger   = "ACTIVITY_TRIGGER"
	DisplayCategoryDoor              = "DOOR"
	DisplayCategoryExteriorBlind     = "EXTERIOR_BLIND"
	DisplayCategoryInteriorBlind     = "INTERIOR_BLIND"
	DisplayCategorySwitch            = "SWITCH"
	DisplayCategoryTemperatureSensor = "TEMPERATURE_SENSOR"
	DisplayCategoryOther             = "OTHER"
)

DisplayCategory enums

View Source
const (
	InterfacePercentageController = NamespacePercentageController
	InterfacePowerController      = NamespacePowerController
	InterfaceSceneController      = NamespaceSceneController
	InterfaceTemperatureSensor    = NamespaceTemperatureSensor
)

Interface enums

View Source
const (
	TemperatureScaleFahrenheit = "FAHRENHEIT"
)

TemperatureScale enums

Variables

View Source
var EmptyPayload = json.RawMessage("{}")

EmptyPayload is a payload with no content

Functions

func UUIDMessageID

func UUIDMessageID() string

UUIDMessageID generates a uuid suitable for use as a MessageID

Types

type AcceptGrantGrant

type AcceptGrantGrant struct {
	Type string `json:"type"`
	Code string `json:"code"`
}

type AcceptGrantGrantee

type AcceptGrantGrantee struct {
	Type  string `json:"type"`
	Token string `json:"token"`
}

type AcceptGrantPayload

type AcceptGrantPayload struct {
	Grant   AcceptGrantGrant   `json:"grant"`
	Grantee AcceptGrantGrantee `json:"grantee"`
}

type AdjustPercentagePayload added in v0.0.2

type AdjustPercentagePayload struct {
	PercentageDelta int8 `json:"percentageDelta"`
}

type ContextProperty

type ContextProperty struct {
	Namespace                 string          `json:"namespace"`
	Name                      string          `json:"name"`
	Value                     json.RawMessage `json:"value"`
	TimeOfSample              time.Time       `json:"timeOfSample"`
	UncertaintyInMilliseconds int32           `json:"uncertaintyInMilliseconds"`
}

type DebugTokenStore

type DebugTokenStore struct {
	TokenStore TokenReaderWriter
}

DebugTokenStore logs reads/writes to tokens

func (*DebugTokenStore) Read

func (d *DebugTokenStore) Read(ctx context.Context, id string) (*oauth2.Token, error)

func (*DebugTokenStore) Write

func (d *DebugTokenStore) Write(ctx context.Context, id string, token *oauth2.Token) error

type DiscoverCapability

type DiscoverCapability struct {
	Type                 string              `json:"type"`
	Interface            string              `json:"interface"`
	Version              string              `json:"version"`
	Properties           *DiscoverProperties `json:"properties,omitempty"`
	SupportsDeactivation *bool               `json:"supportsDeactivation,omitempty"`
	ProactivelyReported  *bool               `json:"proactivelyReported,omitempty"`
}

type DiscoverEndpoint

type DiscoverEndpoint struct {
	EndpointID        string               `json:"endpointId"`
	ManufacturerName  string               `json:"manufacturerName"`
	FriendlyName      string               `json:"friendlyName"`
	Description       string               `json:"description"`
	DisplayCategories []string             `json:"displayCategories"`
	Cookie            map[string]string    `json:"cookie,omitempty"`
	Capabilities      []DiscoverCapability `json:"capabilities"`
}

type DiscoverPayload

type DiscoverPayload struct {
	Endpoints []DiscoverEndpoint `json:"endpoints"`
}

type DiscoverProperties

type DiscoverProperties struct {
	Supported           []DiscoverProperty `json:"supported,omitempty"`
	ProactivelyReported bool               `json:"proactivelyReported"`
	Retrievable         bool               `json:"retrievable"`
}

type DiscoverProperty

type DiscoverProperty struct {
	Name string `json:"name"`
}

type EndpointMux

type EndpointMux struct {
	// contains filtered or unexported fields
}

EndpointMux routes a request based on the requested endpoint

func NewEndpointMux

func NewEndpointMux() *EndpointMux

NewEndpointMux creates an EndpointMux

func (*EndpointMux) Handle

func (e *EndpointMux) Handle(endpoint string, handler Handler)

Handle registers a Handler for the endpoint

func (*EndpointMux) HandleFunc

func (e *EndpointMux) HandleFunc(endpoint string, handler HandlerFunc)

HandleFunc registers a HandlerFunc for the namespace

func (*EndpointMux) HandleRequest

func (e *EndpointMux) HandleRequest(ctx context.Context, req *Request) (*Response, error)

HandleRequest delegates the request to the handler registered for the request's endpoint. An error is returned if the endpoint is unregistered.

type Event

type Event struct {
	Header   Header            `json:"header"`
	Endpoint *ResponseEndpoint `json:"endpoint,omitempty"`
	Payload  json.RawMessage   `json:"payload"`
}

type HTTPDoer

type HTTPDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPDoer performs a HTTP request (HTTPClient implements this)

type Handler

type Handler interface {
	HandleRequest(ctx context.Context, req *Request) (*Response, error)
}

Handler responds to an Alexa smart home skill request

func DebugHandler

func DebugHandler(handler Handler) Handler

DebugHandler wraps handler and logs the contents of the request and response for debugging. The response is also validated against the smart home schema.

type HandlerFunc

type HandlerFunc func(ctx context.Context, req *Request) (*Response, error)

HandlerFunc implements Handler as a func

func AuthorizationHandler

func AuthorizationHandler(clientID, clientSecret string,
	userIDReader UserIDReader, tokenWriter TokenWriter, respBuilder *ResponseBuilder) HandlerFunc

AuthorizationHandler handles an Authorization AcceptGrant request and fetches credentials required to post events to the smart home api

func DeferredRelayHandler

func DeferredRelayHandler(relayer Relayer, builder *ResponseBuilder) HandlerFunc

DeferredRelayHandler handles a request by relaying it to the relayer and returning a DeferredResponse indicating that the actual response will be sent to the smart home api

func PercentageControllerHandler added in v0.0.2

func PercentageControllerHandler(setPct, adjustPct Handler) HandlerFunc

PercentageControllerHandler routes handling of set & adjust directives

func PowerControllerHandler

func PowerControllerHandler(turnOn, turnOff Handler) HandlerFunc

PowerControllerHandler routes turn on & off requests

func RequestDebugHandler

func RequestDebugHandler(handler Handler) HandlerFunc

RequestDebugHandler wraps handler and logs the contents of the request for debugging.

func ResponseDebugHandler

func ResponseDebugHandler(handler Handler) HandlerFunc

ResponseDebugHandler wraps handler and logs the contents of the response for debugging. The response is also validated against the smart home schema.

func SceneControllerHandler added in v0.0.2

func SceneControllerHandler(activate, deactivate Handler) HandlerFunc

SceneControllerHandler routes activate & deactivate requests

func StaticDiscoveryHandler

func StaticDiscoveryHandler(builder *ResponseBuilder, endpoints ...DiscoverEndpoint) HandlerFunc

StaticDiscoveryHandler handles discovery requests with a hardcoded set of endpoints

func (HandlerFunc) HandleRequest

func (h HandlerFunc) HandleRequest(ctx context.Context, req *Request) (*Response, error)

HandleRequest calls the HandlerFunc

type Header struct {
	Namespace        string `json:"namespace"`
	Name             string `json:"name"`
	MessageID        string `json:"messageId"`
	CorrelationToken string `json:"correlationToken,omitempty"`
	PayloadVersion   string `json:"payloadVersion"`
}

type NamespaceMux

type NamespaceMux struct {
	// contains filtered or unexported fields
}

NamespaceMux performs routing of skill requests to handlers based on the namespace value in the request.

func NewNamespaceMux

func NewNamespaceMux() *NamespaceMux

NewNamespaceMux creates a NamespaceMux

func (*NamespaceMux) Handle

func (n *NamespaceMux) Handle(namespace string, handler Handler)

Handle registers a Handler for the namespace

func (*NamespaceMux) HandleFunc

func (n *NamespaceMux) HandleFunc(namespace string, handler HandlerFunc)

HandleFunc registers a HandlerFunc for the namespace

func (*NamespaceMux) HandleRequest

func (n *NamespaceMux) HandleRequest(ctx context.Context, req *Request) (*Response, error)

HandleRequest delegates the request to the handler registered for the request's namespace. An error is returned if the namespace is unregistered.

type ProfileUserIDReader

type ProfileUserIDReader struct {
	HTTPDoer HTTPDoer
}

ProfileUserIDReader retrieves the user's Amazon account user id. It also has access to the user's name and email but it is not returned.

func (*ProfileUserIDReader) Read

func (p *ProfileUserIDReader) Read(ctx context.Context, bearerToken string) (string, error)

type Relayer

type Relayer interface {
	Relay(ctx context.Context, req *Request) error
}

Relayer sends the request somewhere else for handling. It's expected that a response will be posted back to the smart home api.

type Request

type Request struct {
	Directive RequestDirective `json:"directive"`
}

Request represents an incoming request from the smart home service

type RequestDirective

type RequestDirective struct {
	Header   Header          `json:"header"`
	Endpoint RequestEndpoint `json:"endpoint"`
	Payload  json.RawMessage `json:"payload"`
}

type RequestEndpoint

type RequestEndpoint struct {
	Scope      Scope             `json:"scope,omitempty"`
	EndpointID string            `json:"endpointId,omitempty"`
	Cookie     map[string]string `json:"cookie,omitempty"`
}

type Response

type Response struct {
	Context *ResponseContext `json:"context,omitempty"`
	Event   Event            `json:"event"`
}

Response represents a response to a request from the smart home service

type ResponseBuilder

type ResponseBuilder struct {
	// MessageID should generate a unique identifier for a response. UUID recommended.
	MessageID func() string
}

ResponseBuilder assists in generating proper responses for the smart home skill api

func NewResponseBuilder

func NewResponseBuilder() *ResponseBuilder

NewResponseBuilder creates a new ResponseBuilder with a UUID MessageID generator.

func (*ResponseBuilder) AcceptGrantResponse

func (r *ResponseBuilder) AcceptGrantResponse() *Response

AcceptGrantResponse returns a successful accept grant response

func (*ResponseBuilder) BasicErrorResponse

func (r *ResponseBuilder) BasicErrorResponse(req *Request, errorType, msg string) (*Response, error)

BasicErrorResponse creates a response for simple errors

func (*ResponseBuilder) BasicResponse

func (r *ResponseBuilder) BasicResponse(req *Request, properties ...ContextProperty) *Response

BasicResponse returns a response event response

func (*ResponseBuilder) CustomErrorResponse

func (r *ResponseBuilder) CustomErrorResponse(req *Request, payload json.RawMessage) *Response

CustomErrorResponse returns an error response with custom payload

func (*ResponseBuilder) DeferredResponse

func (r *ResponseBuilder) DeferredResponse(req *Request) *Response

DeferredResponse creates a response that indicates that a response will be sent to the smart home event api rather than being returned immediately.

func (*ResponseBuilder) DiscoverResponse

func (r *ResponseBuilder) DiscoverResponse(endpoints ...DiscoverEndpoint) (*Response, error)

DiscoverResponse creates a response that describes the available capabilities

func (*ResponseBuilder) StateReportResponse

func (r *ResponseBuilder) StateReportResponse(req *Request, properties ...ContextProperty) *Response

StateReportResponse builds a StateReport response with the provided properties

type ResponseContext

type ResponseContext struct {
	Properties []ContextProperty `json:"properties,omitempty"`
}

type ResponseEndpoint

type ResponseEndpoint struct {
	EndpointID string            `json:"endpointId,omitempty"`
	Cookie     map[string]string `json:"cookie,omitempty"`
	Scope      Scope             `json:"scope,omitempty"`
}

type Scope

type Scope struct {
	Type  string `json:"type"`
	Token string `json:"token"`
}

type SetPercentagePayload added in v0.0.2

type SetPercentagePayload struct {
	Percentage uint8 `json:"percentage"`
}

type TemperatureValue

type TemperatureValue struct {
	Value float32 `json:"value"`
	Scale string  `json:"scale"`
}

type TokenReader

type TokenReader interface {
	Read(ctx context.Context, id string) (*oauth2.Token, error)
}

TokenReader provides secure retrieval for a user's oauth tokens

type TokenReaderWriter

type TokenReaderWriter interface {
	TokenReader
	TokenWriter
}

TokenReaderWriter provides read & write access to tokens

type TokenWriter

type TokenWriter interface {
	Write(ctx context.Context, id string, token *oauth2.Token) error
}

TokenWriter provides secure storage for a user's oauth tokens

type UserIDReader

type UserIDReader interface {
	Read(ctx context.Context, bearerToken string) (string, error)
}

UserIDReader uses the bearerToken from the skill request to look up the user's id

Jump to

Keyboard shortcuts

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