Documentation ¶
Index ¶
- Constants
- func Start(skill Skill)
- type Application
- type Device
- type HandlerFunc
- type Middleware
- type MiddlewareFunc
- type Request
- type Response
- func (r Response) ElicitSlot(intentName, slotName string) Response
- func (r Response) EndSession(flag bool) Response
- func (r Response) Ok() (Response, error)
- func (r Response) Reprompt(textOrSSML string) Response
- func (r Response) SimpleCard(title, text string) Response
- func (r Response) Speak(textOrSSML string) Response
- func (r Response) SpeakTemplate(template speech.Template, value interface{}) Response
- type Skill
- type Slot
- type Slots
- type User
Constants ¶
const ( RequestTypeCanFulfillIntent = "CanFulfillIntentRequest" RequestTypeIntent = "IntentRequest" RequestTypeLaunch = "LaunchRequest" )
const ( IntentNameCancel = "AMAZON.CancelIntent" IntentNameFallback = "AMAZON.FallbackIntent" IntentNameHelp = "AMAZON.HelpIntent" IntentNameStop = "AMAZON.StopIntent" )
The standard intents that your skill should implement to handle standard Alexa interactions.
Variables ¶
This section is empty.
Functions ¶
func Start ¶
func Start(skill Skill)
Start turns on the appropriate listener to handle incoming requests for the given skill. It will automatically detect if you're just running the process on your local machine or some testing cluster or if you are actually running it as an AWS Lambda function. When not running in Lambda it will simply fire up an HTTP server that listens on port 20123 for equivalent incoming blocks of JSON as you'd receive from the Alexa API to your Lambda function. You can use a different port by setting the GOLEXA_HTTP_PORT environment variable.
You should only call this once per process!
Types ¶
type Application ¶
type Application struct {
ID string `json:"applicationId,omitempty"`
}
Application identifies the skill whose interaction model was used to invoke this request.
type Device ¶
type Device struct { ID string `json:"deviceId,omitempty"` SupportedInterfaces map[string]interface{} `json:"supportedInterfaces"` }
Device contains information about the type of Echo device that the request came from.
type HandlerFunc ¶
HandlerFunc defines a core operation of your skill. It takes the request with all incoming user interaction information and returns a Response w/ instructions for how Alexa should react to the user's utterance/request.
type Middleware ¶
type Middleware []MiddlewareFunc
Middleware represents a chain of units of work to execute before your intent/request handler.
func (Middleware) Then ¶
func (m Middleware) Then(handler HandlerFunc) HandlerFunc
Then creates a wrapper function that forces a request to run through a your gauntlet of middleware functions before finally executing the intent/request handler you're registering.
type MiddlewareFunc ¶
MiddlewareFunc defines a standardized unit of work that you want to execute after an Alexa request comes in, but before your actual intent handler fires. By simply not invoking the 'next' function, you can short circuit the execution without running your intent handler at all (think restricting access to intents based on whether they're account linked or not).
type Request ¶
type Request struct { Version string `json:"version"` Session requestSession `json:"session"` Body requestBody `json:"request"` Context requestContext `json:"context"` }
Request is the core data structure that encapsulates all of the different pieces of data that the Alexa API provides in their JSON.
This struct is an adaptation of the one provided by: https://github.com/arienmalec/alexa-go
func NewIntentRequest ¶
NewIntentRequest creates a minimal request instance you can use to write unit tests for your intent requests.
func (Request) DeviceID ¶
DeviceID traverses the request structure to extract the id of the device making the call.
func (Request) Language ¶
Language parses the incoming 'locale' attribute to determine the language we should use for translating text.
func (Request) SessionID ¶
SessionID traverses the request structure to extract the id of the Amazon/Alexa session making the call.
func (Request) SkillID ¶
SkillID returns the id of the skill that was invoked to handle this request.
func (Request) UserAccessToken ¶
UserAccessToken traverses the request structure to extract the account-linked access token for the caller.
type Response ¶
type Response struct { Request Request `json:"-"` Version string `json:"version"` SessionAttributes map[string]interface{} `json:"sessionAttributes,omitempty"` Body responseBody `json:"response"` }
Response encapsulates all of the various options that your skill can respond with to control the audio and visual aspects of the experience. It is a builder that lets you add on additional pieces to the experience as you deem necessary. For instance you can invoke `Speak()` to control what Alexa will say to the user then call `SimpleCard()` to provide some basic visual feedback.
This struct is an adaptation of the one provided by: https://github.com/arienmalec/alexa-go
func Fail ¶
Fail should be used in only the most dire of unrecoverable circumstances. It will respond with no Alexa instructions and an error w/ the given message. You should NOT use this in instances where your skill can't give a meaningful response to a question. It should only be used for critical, unexpected paths such as receiving a request for an intent your code doesn't have registered.
func NewResponse ¶
NewResponse create a bare-bones response instance that you can continue to expand on with additional instructions for Alexa like `Speak()` or `SimpleCard()`.
func (Response) ElicitSlot ¶
ElicitSlot keeps the current session open and has the user's echo device go back into capture mode. Whatever the user speaks next will be applied to the specified slot and all other slots from this request will be sent along to the slot you named. You should use this in conjunction with `Speak()` so that Alexa will give a meaningful prompt rather than just displaying a blue ring.
For example, if you're setting up some sort of game, you might respond with the speech "How many players?" and `ElicitSlot(req, "StartGameIntent", "num_players")`. Once the user tell you how many players then that slot info will be sent to your "StartGameIntent".
func (Response) EndSession ¶
EndSession indicates whether or not the user is at the end of a dialog w/ Alexa. This defaults to 'true' so that all interactions are terminal unless otherwise specified.
func (Response) Ok ¶
Ok simply returns the Response in its current state and a 'nil' error. This is a convenience so that you can build your response at the end of your handlers which require a response and an error.
func (Response) Reprompt ¶
Reprompt should be used in conjunction w/ an `ElicitSlot()` call. If the user doesn't say anything when they're asked to fill in one of the slots, this will be a second audio prompt to try to get them to say something. If the user actually responded the first time, they won't actually hear this.
func (Response) SimpleCard ¶
SimpleCard customizes what the user should see on an Echo device that supports a screen or what shows up when they look at their interaction history in the Alexa app.
type Skill ¶
type Skill struct { Name string // contains filtered or unexported fields }
Skill is the root data structure for your program. It wrangles all of the handlers for the different types of requests your skill is expected to encounter.
func (*Skill) CanFulfillIntent ¶
func (skill *Skill) CanFulfillIntent(handlerFunc HandlerFunc)
CanFulfillIntent allows you to support the "pre-flight" CanFulfillIntentRequest if you want to have your skill undergo name free certification.
func (*Skill) Launch ¶
func (skill *Skill) Launch(handlerFunc HandlerFunc)
Launch registers the handler for when the user utters "Alexa, open XXX" to launch your skill.
func (*Skill) RouteIntent ¶
func (skill *Skill) RouteIntent(intentName string, handlerFunc HandlerFunc)
RouteIntent indicates that any "IntentRequest" with the specified intent name should be handled by the given function.
type Slot ¶
type Slot struct { Name string `json:"name"` Value string `json:"value"` Resolutions resolutions `json:"resolutions"` }
Slot is one of placeholder for the important data used in an utterance/query. It can be a very open-ended bit of text as you'd have in an AMAZON.SearchQuery slot or one of the phrases w/ synonyms you set up in a custom slot.
func NewResolvedSlot ¶
NewResolvedSlot is mainly used for faking test data to create a slot that has an uttered value as well as a resolution value.
type Slots ¶
Slots represents a set of runtime values that the Alexa interaction model parsed out for you.
func NewSlots ¶
NewSlots creates a Slots map containing entries for all of the individual slot values.
func (Slots) Clone ¶
Clone creates a copy of all of the slots and their RESOLVED values. Typically you use this when you want to include a set of slots in your response w/o modifying the map in the request. Be aware that while it preserves the resolved value, you will lose the resolution authority data from the original.