alexa

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2022 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TriggerName ...
	TriggerName = "alexa"
	// TriggerFunctionName ...
	TriggerFunctionName = "automationTriggerAlexa"
)
View Source
const (
	// Name ...
	Name = "alexa"
	// TopicPluginAlexa ...
	TopicPluginAlexa = "plugin.alexa"
)
View Source
const (
	// Started indicates that the dialog interaction has just begun.
	Started string = "STARTED"

	// InProgress indicates that the dialog interation is continuing.
	InProgress string = "IN_PROGRESS"

	// Completed indicates that the dialog interaction has finished.
	// The intent and slot confirmation status should be checked.
	Completed string = "COMPLETED"
)
View Source
const (
	// TriggerOptionSkillId ...
	TriggerOptionSkillId = "skillId"
)

Variables

This section is empty.

Functions

func HTTPError

func HTTPError(w http.ResponseWriter, logMsg string, err string, errCode int)

HTTPError is a convenience method for logging a message and writing the provided error message and error code to the HTTP response.

func IsValidAlexaRequest

func IsValidAlexaRequest(w http.ResponseWriter, r *http.Request) bool

IsValidAlexaRequest handles all the necessary steps to validate that an incoming http.Request has actually come from the Server service. If an error occurs during the validation process, an http.Error will be written to the provided http.ResponseWriter. The required steps for request validation can be found on this page: --insecure-skip-verify flag will disable all validations https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/developing-an-alexa-skill-as-a-web-service#hosting-a-custom-skill-as-a-web-service

func New

func New() plugins.Plugable

New ...

func NewTrigger

func NewTrigger(eventBus event_bus.EventBus) (tr triggers.ITrigger)

NewTrigger ...

Types

type AlexaBind

type AlexaBind struct {
	Slots map[string]string `json:"slots"`
	// contains filtered or unexported fields
}

AlexaBind ...

func NewAlexaBind

func NewAlexaBind(eventBus event_bus.EventBus, skillId int64) (alex *AlexaBind)

NewAlexaBind ...

func (*AlexaBind) Card

func (r *AlexaBind) Card(title string, content string) *AlexaBind

Card ...

func (*AlexaBind) EndSession

func (r *AlexaBind) EndSession(flag bool) *AlexaBind

EndSession ...

func (*AlexaBind) OutputSpeech

func (r *AlexaBind) OutputSpeech(text string) *AlexaBind

OutputSpeech ...

func (*AlexaBind) SendMessage

func (r *AlexaBind) SendMessage(msg interface{})

SendMessage ...

func (*AlexaBind) Session

func (r *AlexaBind) Session() string

Session ...

type AlexaPlugin

type AlexaPlugin interface {
	Server() IServer
}

AlexaPlugin ...

type Config

type Config struct {
	Host string
	Port int
}

Config ...

func NewConfig

func NewConfig(appConfig *models.AppConfig) Config

NewConfig ...

func (Config) String

func (c Config) String() string

String ...

type ConfirmationStatus

type ConfirmationStatus string

ConfirmationStatus represents the status of either a dialog or slot confirmation.

const (
	// ConfConfirmed indicates the intent or slot has been confirmed by the end user.
	ConfConfirmed ConfirmationStatus = "CONFIRMED"

	// ConfDenied means the end user indicated the intent or slot should NOT proceed.
	ConfDenied ConfirmationStatus = "DENIED"

	// ConfNone means there has been not acceptance or denial of the intent or slot.
	ConfNone ConfirmationStatus = "NONE"
)

type Context

type Context struct {
	System struct {
		Device struct {
			DeviceID string `json:"deviceId,omitempty"`
		} `json:"device,omitempty"`
		Application struct {
			ApplicationID string `json:"applicationId,omitempty"`
		} `json:"application,omitempty"`
		User struct {
			UserId string `json:"userId"`
		} `json:"user,omitempty"`
		ApiEndpoint    string `json:"apiEndpoint"`
		ApiAccessToken string `json:"apiAccessToken"`
	} `json:"System,omitempty"`
}

Context contains information about the context in which the request was sent. This could be information about the device from which the request was sent or about the invoked Server application.

type DialogType

type DialogType string

Type will indicate type of dialog interaction to be sent to the user.

const (
	// Delegate will indicate that the Server service should continue the dialog ineraction.
	Delegate DialogType = "Dialog.Delegate"

	// ElicitSlot will indicate to the Server service that the specific slot should be elicited from the user.
	ElicitSlot DialogType = "Dialog.ElicitSlot"

	// ConfirmSlot indicates to the Server service that the slot value should be confirmed by the user.
	ConfirmSlot DialogType = "Dialog.ConfirmSlot"

	// ConfirmIntent indicates to the Server service that the complete intent should be confimed by the user.
	ConfirmIntent DialogType = "Dialog.ConfirmIntent"
)

type Directive

type Directive struct {
	Type            DialogType `json:"type"`
	UpdatedIntent   *Intent    `json:"updatedIntent,omitempty"`
	SlotToConfirm   string     `json:"slotToConfirm,omitempty"`
	SlotToElicit    string     `json:"slotToElicit,omitempty"`
	IntentToConfirm string     `json:"intentToConfirm,omitempty"`
}

Directive includes information about intents and slots that should be confirmed or elicted from the user. The type value can be used to delegate the action to the Server service. In this case, a pre-configured prompt will be used from the developer console.

type EchoRespImage

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

EchoRespImage represents a single image with two variants that should be returned as part of a response. Small and Large image sizes can be provided.

type EventAlexaAction

type EventAlexaAction struct {
	SkillId    int64
	IntentName string
	Payload    interface{}
}

EventAlexaAction ...

type EventAlexaAddSkill

type EventAlexaAddSkill struct {
	Skill *m.AlexaSkill
}

EventAlexaAddSkill ...

type EventAlexaDeleteSkill

type EventAlexaDeleteSkill struct {
	Skill *m.AlexaSkill
}

EventAlexaDeleteSkill ...

type EventAlexaUpdateSkill

type EventAlexaUpdateSkill struct {
	Skill *m.AlexaSkill
}

EventAlexaUpdateSkill ...

type IServer

type IServer interface {
	Start()
	Stop()
	OnLaunchHandler(ctx *gin.Context, req *Request, resp *Response)
	OnIntentHandle(ctx *gin.Context, req *Request, resp *Response)
	OnSessionEndedHandler(ctx *gin.Context, req *Request, resp *Response)
	OnAudioPlayerHandler(ctx *gin.Context, req *Request, resp *Response)
	AddSkill(skill *m.AlexaSkill)
	UpdateSkill(skill *m.AlexaSkill)
	DeleteSkill(skill *m.AlexaSkill)
}

IServer ...

type Intent

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

Intent represents the intent that is sent as part of an Request. This includes the name of the intent configured in the Server developers dashboard as well as any slots and the optional confirmation status if one is needed to complete an intent.

type Reprompt

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

Reprompt contains speech that should be spoken back to the end user to retrieve additional information or to confirm an action.

type ReqBody

type ReqBody struct {
	Type        string `json:"type"`
	RequestID   string `json:"requestId"`
	Timestamp   string `json:"timestamp"`
	Intent      Intent `json:"intent,omitempty"`
	Reason      string `json:"reason,omitempty"`
	Locale      string `json:"locale,omitempty"`
	DialogState string `json:"dialogState,omitempty"`
}

ReqBody contains all data related to the type of request sent.

type Request

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

Request represents all fields sent from the Server service to the skillserver. Convenience methods are provided to pull commonly used properties out of the request.

func (*Request) AllSlots

func (r *Request) AllSlots() map[string]Slot

AllSlots will return a map of all the slots in the Request mapped by their name.

func (*Request) GetIntentName

func (r *Request) GetIntentName() string

GetIntentName is a convenience method for getting the intent name out of an Request.

func (*Request) GetRequestType

func (r *Request) GetRequestType() string

GetRequestType is a convenience method for getting the request type out of an Request.

func (*Request) GetSessionID

func (r *Request) GetSessionID() string

GetSessionID is a convenience method for getting the session ID out of an Request.

func (*Request) GetSlot

func (r *Request) GetSlot(slotName string) (Slot, error)

GetSlot will return an Slot from the Request with the given name.

func (*Request) GetSlotValue

func (r *Request) GetSlotValue(slotName string) (string, error)

GetSlotValue is a convenience method for getting the value of the specified slot out of an Request as a string. An error is returned if a slot with that value is not found in the request.

func (*Request) GetUserID

func (r *Request) GetUserID() string

GetUserID is a convenience method for getting the user identifier out of an Request.

func (*Request) Locale

func (r *Request) Locale() string

Locale returns the locale specified in the request.

func (*Request) VerifyAppID

func (r *Request) VerifyAppID(myAppID string) bool

VerifyAppID check that the incoming application ID matches the application ID provided when running the server. This is a step required for skill certification.

func (*Request) VerifyTimestamp

func (r *Request) VerifyTimestamp() bool

VerifyTimestamp will parse the timestamp in the Request and verify that it is in the correct format and is not too old. True will be returned if the timestamp is valid; false otherwise.

type Resolution

type Resolution struct {
	ResolutionsPerAuthority []ResolutionPerAuthority `json:"resolutionsPerAuthority"`
}

Resolution contains the results of entity resolutions when it relates to slots and how the values are resolved. The resolutions will be organized by authority, for custom slots the authority will be the custom slot type that was defined. Find more information here: https://developer.amazon.com/docs/custom-skills/define-synonyms-and-ids-for-slot-type-values-entity-resolution.html#intentrequest-changes

type ResolutionPerAuthority

type ResolutionPerAuthority struct {
	Authority string `json:"authority"`
	Status    struct {
		Code string `json:"code"`
	} `json:"status"`
	Values []map[string]struct {
		Name string `json:"name"`
		ID   string `json:"id"`
	} `json:"values"`
}

ResolutionPerAuthority contains information about a single slot resolution from a single authority. The values silce will contain all possible matches for different slots. These resolutions are most interesting when working with synonyms.

type RespBody

type RespBody struct {
	OutputSpeech     *RespPayload `json:"outputSpeech,omitempty"`
	Card             *RespPayload `json:"card,omitempty"`
	Reprompt         *Reprompt    `json:"reprompt,omitempty"` // Pointer so it's dropped if empty in JSON response.
	ShouldEndSession bool         `json:"shouldEndSession"`
	Directives       []*Directive `json:"directives,omitempty"`
}

RespBody contains the body of the response to be sent back to the Server service. This includes things like the text that should be spoken or any cards that should be shown in the Server companion app.

type RespPayload

type RespPayload struct {
	Type    string        `json:"type,omitempty"`
	Title   string        `json:"title,omitempty"`
	Text    string        `json:"text,omitempty"`
	SSML    string        `json:"ssml,omitempty"`
	Content string        `json:"content,omitempty"`
	Image   EchoRespImage `json:"image,omitempty"`
}

RespPayload contains the interesting parts of the Echo response including text to be spoken, card attributes, and images.

type Response

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

Response represents the information that should be sent back to the Server service from the skillserver.

func NewResponse

func NewResponse() *Response

NewEchoResponse will construct a new response instance with the required metadata and an empty speech string. By default the response will indicate that the session should be ended. Use the `EndSession(bool)` method if the session should be left open.

func (*Response) Card

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

Card will add a card to the Server app's response with the provided title and content strings.

func (*Response) EndSession

func (r *Response) EndSession(flag bool) *Response

EndSession is a convenience method for setting the flag in the response that will indicate if the session between the end user's device and the skillserver should be closed.

func (*Response) LinkAccountCard

func (r *Response) LinkAccountCard() *Response

LinkAccountCard is used to indicate that account linking still needs to be completed to continue using the Server skill. This will force an account linking card to be shown in the user's companion app.

func (*Response) OutputSpeech

func (r *Response) OutputSpeech(text string) *Response

OutputSpeech will replace any existing text that should be spoken with this new value. If the output needs to be constructed in steps or special speech tags need to be used, see the `SSMLTextBuilder`.

func (*Response) OutputSpeechSSML

func (r *Response) OutputSpeechSSML(text string) *Response

OutputSpeechSSML will add the text string provided and indicate the speech type is SSML in the response. This should only be used if the text to speech string includes special SSML tags.

func (*Response) Reprompt

func (r *Response) Reprompt(text string) *Response

Reprompt will send a prompt back to the user, this could be used to request additional information from the user.

func (*Response) RepromptSSML

func (r *Response) RepromptSSML(text string) *Response

RepromptSSML is similar to the `Reprompt` method but should be used when the prompt to the user should include special speech tags.

func (*Response) RespondToIntent

func (r *Response) RespondToIntent(name DialogType, intent *Intent, slot *Slot) *Response

RespondToIntent is used to Delegate/Elicit/Confirm a dialog or an entire intent with user of server. The func takes in name of the dialog, updated intent/intent to confirm if any and optional slot value. It prepares a Echo Response to be returned. Multiple directives can be returned by calling the method in chain (eg. RespondToIntent(...).RespondToIntent(...), each RespondToIntent call appends the data to Directives array and will return the same at the end.

func (*Response) SimpleCard

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

SimpleCard will indicate that a card should be included in the Server companion app as part of the response. The card will be shown with the provided title and content.

func (*Response) StandardCard

func (r *Response) StandardCard(title string, content string, smallImg string, largeImg string) *Response

StandardCard will indicate that a card should be shown in the Server companion app as part of the response. The card shown will include the provided title and content as well as images loaded from the locations provided as remote locations.

func (*Response) String

func (r *Response) String() ([]byte, error)

String ...

type Server

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

Server ...

func NewServer

func NewServer(adaptors *adaptors.Adaptors,
	config Config,
	scriptService scripts.ScriptService,
	gateClient *gate_client.GateClient,
	eventBus event_bus.EventBus) *Server

NewServer ...

func (*Server) AddSkill

func (s *Server) AddSkill(skill *m.AlexaSkill)

AddSkill ...

func (Server) Auth

func (s Server) Auth(ctx *gin.Context)

Auth ...

func (*Server) DeleteSkill

func (s *Server) DeleteSkill(skill *m.AlexaSkill)

DeleteSkill ...

func (*Server) OnAudioPlayerHandler

func (s *Server) OnAudioPlayerHandler(ctx *gin.Context, req *Request, resp *Response)

OnAudioPlayerHandler ...

func (*Server) OnIntentHandle

func (s *Server) OnIntentHandle(ctx *gin.Context, req *Request, resp *Response)

OnIntentHandle ...

func (*Server) OnLaunchHandler

func (s *Server) OnLaunchHandler(ctx *gin.Context, req *Request, resp *Response)

OnLaunchHandler ...

func (*Server) OnSessionEndedHandler

func (s *Server) OnSessionEndedHandler(ctx *gin.Context, req *Request, resp *Response)

OnSessionEndedHandler ...

func (*Server) Start

func (s *Server) Start()

Start ...

func (*Server) Stop

func (s *Server) Stop()

Stop ...

func (*Server) UpdateSkill

func (s *Server) UpdateSkill(skill *m.AlexaSkill)

UpdateSkill ...

type ServerLogger

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

ServerLogger ...

func NewLogger

func NewLogger() *ServerLogger

NewLogger ...

func (ServerLogger) Write

func (s ServerLogger) Write(b []byte) (i int, err error)

Write ...

type Session

type Session struct {
	New         bool   `json:"new"`
	SessionID   string `json:"sessionId"`
	Application struct {
		ApplicationID string `json:"applicationId"`
	} `json:"application"`
	Attributes map[string]interface{} `json:"attributes"`
	User       struct {
		UserID      string `json:"userId"`
		AccessToken string `json:"accessToken,omitempty"`
	} `json:"user"`
}

Session contains information about the ongoing session between the Server server and the skillserver. This session is stored as part of each request.

type Skill

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

Skill ...

func NewSkill

func NewSkill(model *m.AlexaSkill,
	adaptors *adaptors.Adaptors,
	scriptService scripts.ScriptService,
	eventBus event_bus.EventBus) (skill *Skill)

NewSkill ...

func (Skill) GetAppID

func (h Skill) GetAppID() string

GetAppID ...

func (Skill) OnAudioPlayerState

func (h Skill) OnAudioPlayerState(ctx *gin.Context, req *Request, resp *Response)

OnAudioPlayerState ...

func (*Skill) OnIntent

func (h *Skill) OnIntent(_ *gin.Context, req *Request, resp *Response)

OnIntent ...

func (*Skill) OnLaunch

func (h *Skill) OnLaunch(_ *gin.Context, req *Request, resp *Response)

OnLaunch ...

func (*Skill) OnSessionEnded

func (h *Skill) OnSessionEnded(_ *gin.Context, req *Request, resp *Response)

OnSessionEnded ...

type Slot

type Slot struct {
	Name               string             `json:"name"`
	Value              string             `json:"value"`
	Resolutions        Resolution         `json:"resolutions"`
	ConfirmationStatus ConfirmationStatus `json:"confirmationStatus"`
}

Slot represents variable values that can be sent that were specified by the end user when invoking the Server application.

type Trigger

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

Trigger ...

func (Trigger) AsyncAttach

func (t Trigger) AsyncAttach(wg *sync.WaitGroup)

AsyncAttach ...

func (Trigger) CallManual added in v0.5.3

func (t Trigger) CallManual()

CallManual ...

func (Trigger) FunctionName

func (t Trigger) FunctionName() string

FunctionName ...

func (Trigger) Name

func (t Trigger) Name() string

Name ...

func (Trigger) Subscribe

func (t Trigger) Subscribe(options triggers.Subscriber) error

Subscribe ...

func (Trigger) Unsubscribe

func (t Trigger) Unsubscribe(options triggers.Subscriber) error

Unsubscribe ...

Jump to

Keyboard shortcuts

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