alexa

package
v0.0.0-...-2ebb6ce Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2021 License: MIT Imports: 10 Imported by: 0

README

OBSOLETE!

see https://github.com/DrPsychick/go-alexa-lambda

Alexa Dialog

Example lambda request: Alexa asked, but could not match the user response to a valid slot value: ER_SUCCESS_NO_MATCH

"request": {
    "type": "IntentRequest",
    "requestId": "amzn1.echo-api.request.806dc75f-5ee0-44a2-913d-29b5be44ad54",
    "timestamp": "2019-11-03T11:50:06Z",
    "locale": "en-US",
    "intent": {
        "name": "AWSStatus",
        "confirmationStatus": "NONE",
        "slots": {
            "Region": {
                "name": "Region",
                "value": "franfrut",
                "resolutions": {
                    "resolutionsPerAuthority": [
                        {
                            "authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.8f065707-2c82-49b4-a78f-6a1fba6c8bae.AWSRegion",
                            "status": {
                                "code": "ER_SUCCESS_NO_MATCH"
                            }
                        }
                    ]
                },
                "confirmationStatus": "NONE",
                "source": "USER"
            },
            "Area": {
                "name": "Area",
                "confirmationStatus": "NONE",
                "source": "USER"
            }
        }
    },
    "dialogState": "COMPLETED"
}

Successful match: ER_SUCCESS_MATCH

"request": {
    "type": "IntentRequest",
    "requestId": "amzn1.echo-api.request.b8683011-7bde-4ad3-bdb0-3814764e2dff",
    "timestamp": "2019-11-02T20:52:38Z",
    "locale": "LOCALE",
    "intent": {
      "name": "AWSStatus",
      "confirmationStatus": "NONE",
      "slots": {
        "Region": {
          "name": "Region",
          "value": "frankfurt",
          "resolutions": {
            "resolutionsPerAuthority": [
              {
                "authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.8f065707-2c82-49b4-a78f-6a1fba6c8bae.AWSRegion",
                "status": {
                  "code": "ER_SUCCESS_MATCH"
                },
                "values": [
                  {
                    "value": {
                      "name": "Frankfurt",
                      "id": "4312d5c8cdda027420c474e2221abc34"
                    }
                  }
                ]
              }
            ]
          },
          "confirmationStatus": "NONE",
          "source": "USER"
        },
        "Area": {
          "name": "Area",
          "confirmationStatus": "NONE",
          "source": "USER"
        }
      }
    },
    "dialogState": "COMPLETED"
  }
Credits

basic code thanks to: https://github.com/soloworks/go-alexa-models

Documentation

Overview

Package alexa enables parsing request and building responses.

Index

Constants

View Source
const (
	// ConfirmationStatusNone is constant `NONE`.
	ConfirmationStatusNone = "NONE"

	// ConfirmationStatusConfirmed is constant `CONFIRMED`.
	ConfirmationStatusConfirmed = "CONFIRMED"

	// ConfirmationStatusDenied is constant `DENIED`.
	ConfirmationStatusDenied = "DENIED"
)
View Source
const (
	// HelpIntent is the Alexa built-in Help Intent.
	HelpIntent = "AMAZON.HelpIntent"

	// CancelIntent is the Alexa built-in Cancel Intent.
	CancelIntent = "AMAZON.CancelIntent"

	// StopIntent is the Alexa built-in Stop Intent.
	StopIntent = "AMAZON.StopIntent"
)

Built in intents.

Variables

View Source
var (
	ErrUnknown                   = errors.New("unknown error")
	ErrSlotNoResolutionWithMatch = errors.New("no resolution with match")
)

Error constants.

View Source
var DefaultServerMux = NewServerMux(log.Null)

DefaultServerMux is the default mux.

Functions

func CheckForLocaleError

func CheckForLocaleError(loc l10n.LocaleInstance) error

CheckForLocaleError returns a ResponseError for the last locale error.

func HandleError

func HandleError(b *ResponseBuilder, loc l10n.LocaleInstance, err error) bool

HandleError handles default and ResponseErrors. Returns true if the error was handled.

func HandleIntent

func HandleIntent(intent string, handler Handler)

HandleIntent registers the handler for the given intent on the DefaultServeMux.

func HandleIntentFunc

func HandleIntentFunc(intent string, handler HandlerFunc)

HandleIntentFunc registers the handler function for the given intent on the DefaultServeMux.

func HandleRequestType

func HandleRequestType(requestType RequestType, handler Handler)

HandleRequestType registers the handler for the given request type on the DefaultServeMux.

Any attempt to handle the IntentRequest type will be ignored, use Intent instead.

func HandleRequestTypeFunc

func HandleRequestTypeFunc(requestType RequestType, handler HandlerFunc)

HandleRequestTypeFunc registers the handler function for the given request type on the DefaultServeMux.

Any attempt to handle the IntentRequest type will be ignored, use Intent instead.

func Serve

func Serve(h Handler) error

Serve serves the given handler.

Types

type Application

type Application interface {
	log.Loggable
	stats.Statable
}

Application defines the interface used of the app.

type AudioItem

type AudioItem struct {
	Stream Stream `json:"stream,omitempty"`
}

AudioItem represents a response directive audio item.

type AudioPlayerActivity

type AudioPlayerActivity string

AudioPlayerActivity defines the activities of an audio player.

const (
	// AudioPlayerActivityIDLE Nothing was playing, no enqueued items.
	AudioPlayerActivityIDLE AudioPlayerActivity = "IDLE"
	// AudioPlayerActivityPAUSED Stream was paused.
	AudioPlayerActivityPAUSED AudioPlayerActivity = "PAUSED"
	// AudioPlayerActivityPLAYING Stream was playing.
	AudioPlayerActivityPLAYING AudioPlayerActivity = "PLAYING"
	// AudioPlayerActivityBufferUnderrun Buffer underrun.
	AudioPlayerActivityBufferUnderrun AudioPlayerActivity = "BUFFER_UNDERRUN"
	// AudioPlayerActivityFINISHED Stream was finished playing.
	AudioPlayerActivityFINISHED AudioPlayerActivity = "FINISHED"
	// AudioPlayerActivitySTOPPED Stream was interrupted.
	AudioPlayerActivitySTOPPED AudioPlayerActivity = "STOPPED"
)

type AuthorityValue

type AuthorityValue struct {
	Value *AuthorityValueValue `json:"value,omitempty"`
}

AuthorityValue is an entry in the list of values.

type AuthorityValueValue

type AuthorityValueValue struct {
	Name string `json:"name"`
	ID   string `json:"id"`
}

AuthorityValueValue points to the unique ID and value.

type CanFulfillIntent

type CanFulfillIntent struct {
	CanFulfill string                    `json:"canFulfill"`
	Slots      map[string]CanFulfillSlot `json:"slots"`
}

CanFulfillIntent represents a response indicating if an intent can be fulfilled.

type CanFulfillSlot

type CanFulfillSlot struct {
	CanUnderstand string `json:"canUnderstand"`
	CanFulfill    string `json:"canFulfill"`
}

CanFulfillSlot represents a slots fulfillment.

type Card

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

Card presents a card response.

type ConfirmationStatus

type ConfirmationStatus string

ConfirmationStatus represents confirmationStatus in JSON.

type Context

type Context struct {
	System      *ContextSystem         `json:"System,omitempty"`
	AudioPlayer *ContextAudioPlayer    `json:"audioPlayer,omitempty"`
	Viewport    *ContextViewport       `json:"Viewport,omitempty"`
	Viewports   []*ContextViewportType `json:"Viewports,omitempty"`
}

Context represents the Alexa skill request context.

type ContextApplication

type ContextApplication struct {
	ApplicationID string `json:"applicationId"`
}

ContextApplication is used to verify that the request was intended for your service

The ID is the application ID for your skill.

type ContextAudioPlayer

type ContextAudioPlayer struct {
	Token                string              `json:"token"`
	OffsetInMilliseconds int                 `json:"offsetInMilliseconds"`
	PlayerActivity       AudioPlayerActivity `json:"playerActivity"`
}

ContextAudioPlayer is available when the device has an audio player.

type ContextSystem

type ContextSystem struct {
	// APIAccessToken a string containing a token that can be used to access Alexa-specific APIs
	APIAccessToken string `json:"apiAccessToken,omitempty"`
	// APIEndpoint a string that references the correct base URI to refer to by region, for use with APIs
	APIEndpoint string       `json:"apiEndpoint,omitempty"`
	User        *ContextUser `json:"user,omitempty"`
	// Device provides information about the device used to send the request
	Device struct {
		DeviceID            string              `json:"deviceId,omitempty"`
		SupportedInterfaces map[string]struct{} `json:"supportedInterfaces,omitempty"`
	} `json:"device,omitempty"`
	Application *ContextApplication `json:"application"`
	// Unit represents a logical construct organizing actors
	Unit struct {
		UnitID           string `json:"unitId"`
		PersistentUnitID string `json:"persistentUnitId"`
	} `json:"unit,omitempty"`
	// Person describes the person who is making the request to Alexa (user recognized by voice, not account)
	Person *ContextSystemPerson `json:"person,omitempty"`
}

ContextSystem provides information about the current state of the Alexa service and the interacting device.

type ContextSystemPerson

type ContextSystemPerson struct {
	PersonID    string `json:"personId"`
	AccessToken string `json:"accessToken,omitempty"`
}

ContextSystemPerson describes the person who is making the request to Alexa

This is the user recognized by voice, not account from which the request came.

type ContextUser

type ContextUser struct {
	UserID      string `json:"userId"`
	AccessToken string `json:"accessToken,omitempty"`
}

ContextUser a string that represents a unique identifier for the Amazon account for which the skill is enabled.

type ContextViewport

type ContextViewport struct {
	Experiences        []*ViewportExperience `json:"experiences,omitempty"`
	Mode               ContextViewportMode   `json:"mode"`
	Shape              ContextViewportShape  `json:"shape"`
	PixelWidth         int                   `json:"pixelWidth"`
	PixelHeight        int                   `json:"pixelHeight"`
	CurrentPixelWidth  int                   `json:"currentPixelWidth"`
	CurrentPixelHeight int                   `json:"currentPixelHeight"`
	DPI                int                   `json:"dpi"`
	Touch              []string              `json:"touch"`
	Keyboard           []string              `json:"keyboard"`
	Video              struct {
		Codecs []string `json:"codecs"`
	} `json:"video"`
}

ContextViewport provides information about the viewport if the device has a screen.

type ContextViewportMode

type ContextViewportMode string

ContextViewportMode is the mode for the device.

const (
	// ContextViewportModeHUB defines a HUB device.
	ContextViewportModeHUB ContextViewportMode = "HUB"
	// ContextViewportModeTV defines a TV device.
	ContextViewportModeTV ContextViewportMode = "TV"
	// ContextViewportModePC defines a PC device.
	ContextViewportModePC ContextViewportMode = "PC"
	// ContextViewportModeMobile defines a MOBILE device.
	ContextViewportModeMobile ContextViewportMode = "MOBILE"
	// ContextViewportModeAuto defines a AUTO device.
	ContextViewportModeAuto ContextViewportMode = "AUTO"
)

type ContextViewportShape

type ContextViewportShape string

ContextViewportShape is the shape of the device.

const (
	// ContextViewportShapeRound defines a round shape.
	ContextViewportShapeRound ContextViewportShape = "ROUND"
	// ContextViewportShapeRectangle defines a rectangular shape.
	ContextViewportShapeRectangle ContextViewportShape = "RECTANGLE"
)

type ContextViewportType

type ContextViewportType struct {
	ID               string `json:"id"`
	Type             string `json:"type"`
	Shape            string `json:"shape"`
	DPI              int    `json:"dpi"`
	PresentationType string `json:"presentationType"`
	CanRotate        bool   `json:"canRotate"`
	Configuration    struct {
		Current ViewportConfiguration `json:"current"`
	} `json:"configuration"`
}

ContextViewportType defines an available viewport of the device.

type DialogStateType

type DialogStateType string

DialogStateType represents JSON request `request.dialogState`

see https://developer.amazon.com/docs/custom-skills/delegate-dialog-to-alexa.html

const (
	// DialogStateStarted defines a started dialog.
	DialogStateStarted DialogStateType = "STARTED"
	// DialogStateInProgress defines a dialog in progress.
	DialogStateInProgress DialogStateType = "IN_PROGRESS"
	// DialogStateCompleted defines a completed dialog.
	DialogStateCompleted DialogStateType = "COMPLETED"
)

type Directive

type Directive struct {
	Type          DirectiveType `json:"type,omitempty"`
	SlotToElicit  string        `json:"slotToElicit,omitempty"`
	UpdatedIntent *Intent       `json:"updatedIntent,omitempty"`
	PlayBehavior  string        `json:"playBehavior,omitempty"`
	AudioItem     *AudioItem    `json:"audioItem,omitempty"`
}

Directive represents a response directive.

type DirectiveType

type DirectiveType string

DirectiveType represents various Directive Types.

const (
	DirectiveTypeDialogDelegate      DirectiveType = "Dialog.Delegate"
	DirectiveTypeDialogElicitSlot    DirectiveType = "Dialog.ElicitSlot"
	DirectiveTypeDialogConfirmSlot   DirectiveType = "Dialog.ConfirmSlot"
	DirectiveTypeDialogConfirmIntent DirectiveType = "Dialog.ConfirmIntent"
)

Directive types.

type Handler

type Handler interface {
	Serve(*ResponseBuilder, *RequestEnvelope)
}

Handler represents an alexa request handler.

type HandlerFunc

type HandlerFunc func(*ResponseBuilder, *RequestEnvelope)

HandlerFunc is an adapter allowing a function to be used as a handler.

func (HandlerFunc) Serve

func (fn HandlerFunc) Serve(b *ResponseBuilder, r *RequestEnvelope)

Serve serves the request.

type Image

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

Image represents a card image.

type Intent

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

Intent is the Alexa skill intent.

type NotFoundError

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

NotFoundError defines a generic not found error.

func (NotFoundError) Error

func (e NotFoundError) Error() string

Error returns a string representing the error including the element missing.

type OutputSpeech

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

OutputSpeech represents a speech response.

type PerAuthority

type PerAuthority struct {
	Authority string            `json:"authority"`
	Status    *ResolutionStatus `json:"status,omitempty"`
	Values    []*AuthorityValue `json:"values,omitempty"`
}

PerAuthority encapsulates an Authority which is the source of the data provided.

type Reprompt

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

Reprompt represents a reprompt response.

type Request

type Request struct {
	Type        RequestType     `json:"type"`
	RequestID   string          `json:"requestId"`
	Timestamp   string          `json:"timestamp"`
	Locale      RequestLocale   `json:"locale"`
	Intent      Intent          `json:"intent,omitempty"`
	Reason      string          `json:"reason,omitempty"`
	DialogState DialogStateType `json:"dialogState,omitempty"`

	Context *Context `json:"-"`
	Session *Session `json:"-"`
}

Request represents the information about the request.

type RequestEnvelope

type RequestEnvelope struct {
	Version string   `json:"version"`
	Session *Session `json:"session"`
	Context *Context `json:"context"`
	Request *Request `json:"request"`
}

RequestEnvelope represents the alexa request envelope.

func (*RequestEnvelope) ApplicationID

func (r *RequestEnvelope) ApplicationID() (string, error)

ApplicationID returns the application ID from the session first, then system or returns an error

Use it to verify the request is meant for your Skill.

func (*RequestEnvelope) ContextPerson

func (r *RequestEnvelope) ContextPerson() (*ContextSystemPerson, error)

ContextPerson returns the person in the context or returns an error if no person exists.

func (*RequestEnvelope) ContextUser

func (r *RequestEnvelope) ContextUser() (*ContextUser, error)

ContextUser returns the user in the context or returns an error if no user exists.

func (*RequestEnvelope) Intent

func (r *RequestEnvelope) Intent() (Intent, error)

Intent returns the intent or an empty intent.

func (*RequestEnvelope) IntentName

func (r *RequestEnvelope) IntentName() string

IntentName returns the name of the intent or "" if it's no intent request.

func (*RequestEnvelope) IsIntentConfirmed

func (r *RequestEnvelope) IsIntentConfirmed() bool

IsIntentConfirmed returns true if the confirmation status is CONFIRMED.

func (*RequestEnvelope) IsIntentRequest

func (r *RequestEnvelope) IsIntentRequest() bool

IsIntentRequest returns tru when the request is a TypeIntentRequest.

func (*RequestEnvelope) RequestDialogState

func (r *RequestEnvelope) RequestDialogState() DialogStateType

RequestDialogState returns the dialog state of the request.

func (*RequestEnvelope) RequestLocale

func (r *RequestEnvelope) RequestLocale() string

RequestLocale returns the locale of the request as string (e.g. "en-US").

func (*RequestEnvelope) RequestType

func (r *RequestEnvelope) RequestType() RequestType

RequestType returns the type of the request.

func (*RequestEnvelope) SessionID

func (r *RequestEnvelope) SessionID() string

SessionID returns the sessionID or an empty string.

func (*RequestEnvelope) Slot

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

Slot returns the named slot or an error.

func (*RequestEnvelope) SlotValue

func (r *RequestEnvelope) SlotValue(name string) string

SlotValue returns the value of the slot if it exists.

func (*RequestEnvelope) Slots

func (r *RequestEnvelope) Slots() map[string]*Slot

Slots returns the list of slots, an empty list if no intent was found.

func (*RequestEnvelope) System

func (r *RequestEnvelope) System() (*ContextSystem, error)

System returns the system object if it exists in the context.

type RequestLocale

type RequestLocale string

RequestLocale represents the locale of the request.

const (
	// LocaleAmericanEnglish is the locale for American English.
	LocaleAmericanEnglish RequestLocale = "en-US"

	// LocaleAustralianEnglish is the locale for Australian English.
	LocaleAustralianEnglish RequestLocale = "en-AU"

	// LocaleBritishEnglish is the locale for UK English.
	LocaleBritishEnglish RequestLocale = "en-GB"

	// LocaleCanadianEnglish is the locale for Canadian English.
	LocaleCanadianEnglish RequestLocale = "en-CA"

	// LocaleCanadianFrench is the locale for Canadian French.
	LocaleCanadianFrench RequestLocale = "fr-CA"

	// LocaleFrench is the locale for French (France).
	LocaleFrench RequestLocale = "fr-FR"

	// LocaleGerman is the locale for standard dialect German (Germany).
	LocaleGerman RequestLocale = "de-DE"

	// LocaleIndianEnglish is the locale for Indian English.
	LocaleIndianEnglish RequestLocale = "en-IN"

	// LocaleItalian is the locale for Italian (Italy).
	LocaleItalian RequestLocale = "it-IT"

	// LocaleJapanese is the locale for Japanese (Japan).
	LocaleJapanese RequestLocale = "ja-JP"

	// LocaleMexicanSpanish is the locale for Mexican Spanish.
	LocaleMexicanSpanish RequestLocale = "es-MX"

	// LocaleSpanish is the  for Spanish (Spain).
	LocaleSpanish RequestLocale = "es-ES"
)

Locale constants.

type RequestType

type RequestType string

RequestType represents JSON request `request.type`

see https://developer.amazon.com/docs/custom-skills/request-types-reference.html

const (
	// TypeLaunchRequest defines a launch request type.
	TypeLaunchRequest RequestType = "LaunchRequest"
	// TypeIntentRequest defines a intent request type.
	TypeIntentRequest RequestType = "IntentRequest"
	// TypeSessionEndedRequest defines a session end request type.
	TypeSessionEndedRequest RequestType = "SessionEndedRequest"
	// TypeCanFulfillIntentRequest defines a can fulfill intent request type.
	TypeCanFulfillIntentRequest RequestType = "CanFulfillIntentRequest"
)

Request type constants.

type ResolutionStatus

type ResolutionStatus struct {
	Code StatusCode `json:"code"`
}

ResolutionStatus indicates the results of attempting to resolve the user utterance against the defined slot types.

type Resolutions

type Resolutions struct {
	ResolutionsPerAuthority []*PerAuthority `json:"resolutionsPerAuthority"`
}

Resolutions is an Alexa skill resolution.

type Response

type Response struct {
	Title    string
	Text     string
	Speech   string
	Image    string
	Reprompt bool
	End      bool
}

Response wraps the data needed for a skill response.

func GetLocaleWithFallback

func GetLocaleWithFallback(registry l10n.LocaleRegistry, locale string) (l10n.LocaleInstance, Response)

GetLocaleWithFallback falls back to default locale which must be considered carefully.

type ResponseBuilder

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

ResponseBuilder builds a response.

func (*ResponseBuilder) AddDirective

func (b *ResponseBuilder) AddDirective(directive *Directive) *ResponseBuilder

AddDirective adds a directive tp the response.

func (*ResponseBuilder) Build

func (b *ResponseBuilder) Build() *ResponseEnvelope

Build builds the response from the given information.

func (*ResponseBuilder) With

func (b *ResponseBuilder) With(resp Response)

With applies an Response.

func (*ResponseBuilder) WithCanFulfillIntent

func (b *ResponseBuilder) WithCanFulfillIntent(response *CanFulfillIntent) *ResponseBuilder

WithCanFulfillIntent sets the can fulfill intent response on the response.

func (*ResponseBuilder) WithReprompt

func (b *ResponseBuilder) WithReprompt(text string) *ResponseBuilder

WithReprompt sets the reprompt output speech on the response.

func (*ResponseBuilder) WithSessionAttributes

func (b *ResponseBuilder) WithSessionAttributes(attr map[string]interface{}) *ResponseBuilder

WithSessionAttributes sets the session attributes on the response.

func (*ResponseBuilder) WithShouldEndSession

func (b *ResponseBuilder) WithShouldEndSession(end bool) *ResponseBuilder

WithShouldEndSession determines if the session should end after the current response.

func (*ResponseBuilder) WithSimpleCard

func (b *ResponseBuilder) WithSimpleCard(title, text string) *ResponseBuilder

WithSimpleCard sets a simple card on the response.

func (*ResponseBuilder) WithSpeech

func (b *ResponseBuilder) WithSpeech(text string) *ResponseBuilder

WithSpeech sets the output speech on the response.

If the text contains SSML speak tags, it will be set as SSML speech, otherwise it will be set as plain text speech.

func (*ResponseBuilder) WithStandardCard

func (b *ResponseBuilder) WithStandardCard(title, text string, image *Image) *ResponseBuilder

WithStandardCard sets a standard card on the response.

type ResponseEnvelope

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

ResponseEnvelope represents the wrapper for a response.

type ResponseError

type ResponseError interface {
	error

	Response(loc l10n.LocaleInstance) Response
}

ResponseError defines a response error.

type ServeMux

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

ServeMux is an Alexa request multiplexer.

func NewServerMux

func NewServerMux(log log.Logger) *ServeMux

NewServerMux creates a new server mux.

func (*ServeMux) HandleIntent

func (m *ServeMux) HandleIntent(intent string, handler Handler)

HandleIntent registers the handler for the given intent.

func (*ServeMux) HandleIntentFunc

func (m *ServeMux) HandleIntentFunc(intent string, handler HandlerFunc)

HandleIntentFunc registers the handler function for the given intent.

func (*ServeMux) HandleRequestType

func (m *ServeMux) HandleRequestType(requestType RequestType, handler Handler)

HandleRequestType registers the handler for the given request type.

Any attempt to handle the IntentRequest type will be ignored, use Intent instead.

func (*ServeMux) HandleRequestTypeFunc

func (m *ServeMux) HandleRequestTypeFunc(requestType RequestType, handler HandlerFunc)

HandleRequestTypeFunc registers the handler function for the given request type.

Any attempt to handle the IntentRequest type will be ignored, use Intent instead.

func (*ServeMux) Handler

func (m *ServeMux) Handler(r *RequestEnvelope) (Handler, error)

Handler returns the matched handler for a request, or an error.

func (*ServeMux) Logger

func (m *ServeMux) Logger() log.Logger

Logger returns the application logger.

func (*ServeMux) Serve

func (m *ServeMux) Serve(b *ResponseBuilder, r *RequestEnvelope)

Serve serves the matched handler.

type Server

type Server struct {
	Handler Handler
}

A Server defines parameters for running an Alexa server.

func (*Server) Invoke

func (s *Server) Invoke(ctx context.Context, payload []byte) ([]byte, error)

Invoke calls the handler, and serializes the response.

func (*Server) Serve

func (s *Server) Serve() error

Serve serves the handler.

type Session

type Session struct {
	New         bool                   `json:"new"`
	SessionID   string                 `json:"sessionId"`
	Application *ContextApplication    `json:"application"`
	Attributes  map[string]interface{} `json:"attributes"`
	User        *ContextUser           `json:"user"`
}

Session represents the Alexa skill session.

type Slot

type Slot struct {
	Name        string       `json:"name"`
	Value       string       `json:"value"`
	Resolutions *Resolutions `json:"resolutions"`
	Source      string       `json:"source"`
	SlotValue   *SlotValue   `json:"slotValue"`
}

Slot is an Alexa skill slot.

func (*Slot) FirstAuthorityWithMatch

func (s *Slot) FirstAuthorityWithMatch() (*PerAuthority, error)

FirstAuthorityWithMatch returns the first authority with ResolutionStatusMatch.

func (*Slot) SlotResolutionsPerAuthority

func (s *Slot) SlotResolutionsPerAuthority() ([]*PerAuthority, error)

SlotResolutionsPerAuthority returns the list of ResolutionsPerAuthority.

type SlotValue

type SlotValue struct {
	Type        string       `json:"type"`
	Value       string       `json:"value"`
	Resolutions *Resolutions `json:"resolutions"`
}

SlotValue defines the value or values captured by the slot.

type StatusCode

type StatusCode string

StatusCode represents the status code of a slot resolution.

const (
	// ResolutionStatusMatch is the status code for match.
	ResolutionStatusMatch StatusCode = "ER_SUCCESS_MATCH"
	// ResolutionStatusNoMatch is the status code for no match.
	ResolutionStatusNoMatch StatusCode = "ER_SUCCESS_NO_MATCH"
	// ResolutionStatusTimeout is the status code for an error due to timeout.
	ResolutionStatusTimeout StatusCode = "ER_ERROR_TIMEOUT"
	// ResolutionStatusException is the status code for an error in processing.
	ResolutionStatusException StatusCode = "ER_ERROR_EXCEPTION"
)

type Stream

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

Stream represents a response directive audio item stream.

type TextError

type TextError struct {
	Locale string
	Text   string
}

TextError returns the error text to Alexa.

func (TextError) Error

func (e TextError) Error() string

Error returns the text of the error.

func (TextError) Response

func (e TextError) Response(loc l10n.LocaleInstance) Response

Response returns and ApplicationResponse including the error text.

type TranslationError

type TranslationError struct {
	Locale string
	Key    string
}

TranslationError defines a missing translation error.

func (TranslationError) Error

func (e TranslationError) Error() string

Error returns a string representing the error including the key missing.

func (TranslationError) Response

func (e TranslationError) Response(loc l10n.LocaleInstance) Response

Response returns a Response for the user.

type ViewportConfiguration

type ViewportConfiguration struct {
	Video struct {
		Codecs []string `json:"codecs"`
	} `json:"video,omitempty"`
	Size struct {
		Type        string `json:"type"`
		PixelWidth  int    `json:"pixelWidth"`
		PixelHeight int    `json:"pixelHeight"`
	} `json:"size,omitempty"`
}

ViewportConfiguration contains the viewport configuration of the device in use.

type ViewportExperience

type ViewportExperience struct {
	ArcMinuteWidth  int  `json:"arcMinuteWidth"`
	ArcMinuteHeight int  `json:"arcMinuteHeight"`
	CanRotate       bool `json:"canRotate"`
	CanResize       bool `json:"canResize"`
}

ViewportExperience has info about the device.

Directories

Path Synopsis
Package l10n provides locale helpers (LocaleRegistry) and predefined standard keys for Alexa skills
Package l10n provides locale helpers (LocaleRegistry) and predefined standard keys for Alexa skills
Package skill serves generating the skill and model.
Package skill serves generating the skill and model.
Package ssml provides functions to simplify working with SSML speech.
Package ssml provides functions to simplify working with SSML speech.

Jump to

Keyboard shortcuts

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