Documentation ¶
Index ¶
- Constants
- Variables
- func API(c *Context) *api.Client
- type Attr
- func (u *Attr) Bool() bool
- func (u *Attr) Exists() bool
- func (u *Attr) Float32() float32
- func (u *Attr) Float64() float64
- func (u *Attr) Int() int
- func (u *Attr) Int64() int64
- func (u *Attr) Interface() interface{}
- func (u *Attr) R(key ...string) map[string]string
- func (u *Attr) String() string
- func (u *Attr) StringArr() []string
- func (u *Attr) Unmarshal(data interface{}) error
- type Cardable
- type Context
- func (c *Context) Abort()
- func (c *Context) Ask(speechOutput string, repromptSpeech ...string) *Cardable
- func (a Context) Attr(key string, values ...interface{}) *Attr
- func (c *Context) AudioPlay(audio, id, speech string) *Cardable
- func (c *Context) AudioStop(speech string) *Cardable
- func (c *Context) ConfirmIntent(speechOutput, repromptSpeech string, updatedIntent *dialog.EchoIntent) *Cardable
- func (c *Context) ConfirmSlot(slotToConfirm, speechOutput, repromptSpeech string, ...) *Cardable
- func (c *Context) Delegate(updatedIntent *dialog.EchoIntent)
- func (c *Context) DialogState() string
- func (c *Context) ElicitSlot(slotToElicit, speechOutput, repromptSpeech string, ...) *Cardable
- func (c *Context) Locale() string
- func (c *Context) NewSession() bool
- func (c *Context) Now() time.Time
- func (c *Context) Progress(speech string)
- func (c *Context) SessionID() string
- func (c *Context) Slot(name string) *Slot
- func (c *Context) T(key ...string) string
- func (c *Context) TA(key string) []string
- func (c *Context) TR(key string, replace interface{}) string
- func (c *Context) Tell(speech string) *Cardable
- type IntentHandler
- type IntentHandlers
- type Localisation
- type R
- type Slot
- type SlotValue
- type Translation
- type Translator
Constants ¶
const ( // PermissionFullName - Full Name PermissionFullName = "alexa::profile:name:read" // PermissionGivenName - Given Name (First Name) PermissionGivenName = "alexa::profile:given_name:read" // PermissionEmailAddress - Email Address PermissionEmailAddress = "alexa::profile:email:read" // PermissionPhoneNumber - Phone Number PermissionPhoneNumber = "alexa::profile:mobile_number:read" )
const ( ConfirmationStatusNone = "NONE" ConfirmationStatusDenied = "DENIED" ConfirmationStatusConfirmed = "CONFIRMED" )
Variables ¶
var AppID string
AppID is the ID of the corresponding skill
var BeforeHandler func(*Context)
BeforeHandler can be set with a function to implement any checking before every intent. It returns true for going on with the actual intent or false to skip. Remember to implement a appropriate message to the user on skipping!
var GetTranslation func(locale string) Translation
GetTranslation is called with the current locale code. You must provide the according Translation.
var Handle = func(req *dialog.EchoRequest) (*dialog.EchoResponse, error) { if req == nil { panic("Echo request is nil") } if AppID != "" && !req.VerifyAppID(AppID) { panic("invalid app id") } if Handlers == nil { panic("no handlers set") } var trans *Translator if GetTranslation != nil { if langmap := GetTranslation(req.Request.Locale); langmap != nil { loc := Localisation{req.Request.Locale: langmap} trans = loc.GetTranslator(req.Request.Locale) } } else if LocaleStrings != nil { trans = LocaleStrings.GetTranslator(req.Request.Locale) } if trans == nil { panic("language " + req.Request.Locale + " not implemented") } c := Context{ request: req, handlers: Handlers, response: dialog.NewResponse(), translator: trans, attributes: req.Session.Attributes, System: &req.Context.System, Intent: &req.Request.Intent, Time: req.GetTime(), } c.start(req) return c.getResult() }
Handle is the function you hand over to the lambda.start
Functions ¶
Types ¶
type Attr ¶
type Attr struct {
// contains filtered or unexported fields
}
Attr takes a generic value and converts it with provided functions
func (*Attr) Interface ¶
func (u *Attr) Interface() interface{}
Interface gets attribute as interface{} by given key
func (*Attr) R ¶
R returns a map suitable for TR of localization If no key is provided, the attribute name is taken. If one or more key is provided, all the keys are added with the attributes value.
func (*Attr) String ¶
String gets attribute as string by given key Can convert from float32, float64, int, int64
type Cardable ¶
type Cardable struct {
// contains filtered or unexported fields
}
Cardable is returned by functions, to make them cardable
func (*Cardable) AskPermissionCard ¶
AskPermissionCard adds a "ask for permission" card to the response you can use the constants from this package, prefixed with Permission
func (*Cardable) LinkAccountCard ¶
func (c *Cardable) LinkAccountCard()
LinkAccountCard adds a link account card to the response
func (*Cardable) SimpleCard ¶
SimpleCard adds a simple card to the response
func (*Cardable) StandardCard ¶
StandardCard adds a standard card to the response
type Context ¶
type Context struct { // System contains informations about the calling Device and User System *dialog.EchoSystem // Intent is the intents name Intent *dialog.EchoIntent // Time is the requests timestamp as go time.Time Time time.Time // contains filtered or unexported fields }
Context is the object sent to every intent, collecting infos for response
func (*Context) Abort ¶
func (c *Context) Abort()
Abort prevents the execution of a following handler within an alexa.MultiHandler chain.
func (Context) Attr ¶
Attr gets or sets attributes. Set more than one value and it will become an array
func (*Context) ConfirmIntent ¶
func (c *Context) ConfirmIntent(speechOutput, repromptSpeech string, updatedIntent *dialog.EchoIntent) *Cardable
ConfirmIntent confirm all the slots given to the intent by Alexa
func (*Context) ConfirmSlot ¶
func (c *Context) ConfirmSlot(slotToConfirm, speechOutput, repromptSpeech string, updatedIntent *dialog.EchoIntent) *Cardable
ConfirmSlot confirm a slot value by Alexa
func (*Context) Delegate ¶
func (c *Context) Delegate(updatedIntent *dialog.EchoIntent)
Delegate a slot fullfillment to Alexa
func (*Context) DialogState ¶
DialogState gets the current state of the dialog
func (*Context) ElicitSlot ¶
func (c *Context) ElicitSlot(slotToElicit, speechOutput, repromptSpeech string, updatedIntent *dialog.EchoIntent) *Cardable
ElicitSlot action to fullfill a slot of a certain intent
func (*Context) Locale ¶
Locale gets the locale string like one of: de-DE, en-AU, en-CA, en-GB, en-IN, en-US, ja-JP, fr-FR
func (*Context) NewSession ¶
NewSession determines whether this is a new session that was opened with this call
func (*Context) T ¶
T gets a translated string according to the given key. If the value is an array, a random value is chosen.
type IntentHandler ¶
type IntentHandler func(*Context)
IntentHandler function for the handler
func MultiHandler ¶
func MultiHandler(handlers ...IntentHandler) IntentHandler
MultiHandler if you need more than one handler for an intent
type IntentHandlers ¶
type IntentHandlers map[string]IntentHandler
IntentHandlers for collecting the handler functions
var Handlers IntentHandlers
Handlers are intent functions to be called by name
func (IntentHandlers) Add ¶
func (h IntentHandlers) Add(name string, handler IntentHandler)
Add adds a handler afterwards.
type Localisation ¶
type Localisation map[string]Translation
Localisation maps locale codes to according Translations
var LocaleStrings Localisation
LocaleStrings are all localized strings
func (Localisation) GetTranslator ¶
func (loc Localisation) GetTranslator(locale string) *Translator
GetTranslator gets a translator for the given language
type R ¶
type R map[string]interface{}
R (for Replace) is a shortcut for map[string]interface{}, while the value must be int (any), float (any) or string
type Slot ¶
type Slot struct { // ID is the first ID of that slot value ID string // Value is the first value of slot, not the actual spoken value Value string // Value is the value of slot, not the actual spoken value Values []SlotValue // Spoken is the actual value, spoken by the user Spoken string // ConfirmationStatus is the status of the confirmation of this slot ConfirmationStatus string // Match is true, if the actual speech is a match to one of this slots values or its synonyms Match bool }
Slot is a simple representation of the slot object from the echo request
type Translation ¶
type Translation map[string]interface{}
Translation is a set of translated strings. The value can be either a string or a string array
type Translator ¶
type Translator struct { Phrases Translation // contains filtered or unexported fields }
Translator actively translates keys to values
func (*Translator) GetArray ¶
func (tr *Translator) GetArray(key string) []string
GetArray gets an array from the value according to the given key
func (*Translator) GetString ¶
func (tr *Translator) GetString(key string) string
GetString gets a string from the value according to the given key
func (*Translator) GetStringAndReplace ¶
func (tr *Translator) GetStringAndReplace(key string, replace R) string
GetStringAndReplace gets a translated string and replaces given keys with given values. Place key in {brackets} to be replaced here!
func (*Translator) GetStringWithVariables ¶
func (tr *Translator) GetStringWithVariables(key string, data interface{}) string
GetStringWithVariables gets a translated string, where all placeholders are filled with the values from the given struct. Place key in {brackets} to be replaced here! As tag name use alexa.