Documentation ¶
Index ¶
- func DepthField(s interface{}, index ...interface{}) (field interface{}, err error)
- func ForMethod(x interface{}) string
- func ForType(x interface{}) string
- func InDirect(v reflect.Value) reflect.Value
- func TypeSelect(v reflect.Value) interface{}
- type Alexa
- type EchoApplication
- type EchoIntent
- type EchoRequest
- func (T *EchoRequest) GetAccessToken() string
- func (T *EchoRequest) GetApplicationID() string
- func (T *EchoRequest) GetIntentName() string
- func (T *EchoRequest) GetLocale() string
- func (T *EchoRequest) GetRequestType() string
- func (T *EchoRequest) GetSessionID() string
- func (T *EchoRequest) GetSlot(slotName string) (slot *EchoRequestRequestIntentSlot, err error)
- func (T *EchoRequest) GetSlotNames() (names []string)
- func (T *EchoRequest) GetSlotValue(slotName string) (val string, err error)
- func (T *EchoRequest) GetSlots() (slots map[string]*EchoRequestRequestIntentSlot, err error)
- func (T *EchoRequest) GetUserID() string
- func (T *EchoRequest) GetValueSlots() (slots map[string]*EchoRequestRequestIntentSlot, err error)
- func (T *EchoRequest) VerifyTimestamp(second int) bool
- type EchoRequestContext
- type EchoRequestContextAudioPlayer
- type EchoRequestContextSystem
- type EchoRequestContextSystemApplication
- type EchoRequestContextSystemDevice
- type EchoRequestContextSystemDeviceSupportedInterfaces
- type EchoRequestContextSystemUser
- type EchoRequestContextSystemUserPermissions
- type EchoRequestRequest
- type EchoRequestRequestError
- type EchoRequestRequestIntent
- type EchoRequestRequestIntentSlot
- type EchoRequestSession
- type EchoRequestSessionApplication
- type EchoRequestSessionUser
- type EchoRequestSessionUserPermissions
- type EchoResponse
- func (T *EchoResponse) LinkAccountCard() *EchoResponse
- func (T *EchoResponse) OutputSpeech(text string) *EchoResponse
- func (T *EchoResponse) OutputSpeechSSML(text string) *EchoResponse
- func (T *EchoResponse) RepromptSSML(text string) *EchoResponse
- func (T *EchoResponse) RepromptText(text string) *EchoResponse
- func (T *EchoResponse) SetEndSession(ok bool) *EchoResponse
- func (T *EchoResponse) SimpleCard(title string, content string) *EchoResponse
- func (T *EchoResponse) StandardCard(title string, text string, smallImg string, largeImg string) *EchoResponse
- func (T *EchoResponse) String() string
- type EchoResponseResponse
- type EchoResponseResponseCard
- type EchoResponseResponseCardImage
- type EchoResponseResponseDirectives
- type EchoResponseResponseDirectivesAudioItem
- type EchoResponseResponseDirectivesAudioItemStream
- type EchoResponseResponseOutputSpeech
- type EchoResponseResponseReprompt
- type EchoResponseResponseRepromptOutputSpeech
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DepthField ¶
func DepthField(s interface{}, index ...interface{}) (field interface{}, err error)
DepthField 快速深入读取字段
s interface{} Struct ndex ... interface{} 字段 field interface{} 字段 err error 错误 例: type A struct { B } type B struct { C F map[string]string G []string } type C struct { D int } func main(){ a := A{} fidld, err := DepthField(a, "B", "C", "D") fmt.Println(fidld, err) //0 <nil> }
Types ¶
type Alexa ¶
type Alexa struct { //如:https://www.xxx.com/?appid=amzn1.ask.skill.594232d8-4095-499b-9ba3-11701107834s&type=1 //这个 appid 是程序属性名称,其中的值是 amzn1.ask.skill.594232d8-4095-499b-9ba3-11701107834s //这个 type 是程序类型属性名称,暂时仅支持 Echo,值也就是 1。其它值不支持 //在Alexa后台,Configuration->Global Fields->Endpoint->Service Endpoint Type->选择HTTPS //Default 填入 https://www.xxx.com/?appid=amzn1.ask.skill.594232d8-4095-499b-9ba3-11701107834s&type=1 AppIdAttr string //程序的名称,如:appid // contains filtered or unexported fields }
func (*Alexa) ServeHTTP ¶
func (T *Alexa) ServeHTTP(w http.ResponseWriter, r *http.Request)
服务处理
w http.ResponseWriter http响应对象 r *http.Request http请求对象
func (*Alexa) SetEchoApp ¶
func (T *Alexa) SetEchoApp(alexaAppId string, app *EchoApplication)
设置Echo程序
alexaAppId string Alexa程序ID名 app *EchoApplication Echo对象
type EchoApplication ¶
type EchoApplication struct { Version []string // 支持的版本号 IsDevelop bool // 调试 ValidReqTimestamp int // 有效时间,秒为单位 CertFolder string // 证书保存目录 HandleFunc http.HandlerFunc // 原生处理函数 }
Echo程序的配置
type EchoIntent ¶
type EchoIntent struct { Request *EchoRequest //Echo请求 Response *EchoResponse //Echo响应 App *EchoApplication //Echo配置 }
Echo意图处理
func (*EchoIntent) ServeHTTP ¶
func (T *EchoIntent) ServeHTTP(w http.ResponseWriter, r *http.Request)
服务处理
w http.ResponseWriter http响应对象 r *http.Request http请求对象
type EchoRequest ¶
type EchoRequest struct { Context EchoRequestContext `json:"context"` Request EchoRequestRequest `json:"request"` Session EchoRequestSession `json:"session"` Version string `json:"version"` }
func (*EchoRequest) GetAccessToken ¶
func (T *EchoRequest) GetAccessToken() string
读取用户的令牌
string 令牌
func (*EchoRequest) GetApplicationID ¶
func (T *EchoRequest) GetApplicationID() string
读取程序ID
string 程序ID
func (*EchoRequest) GetIntentName ¶
func (T *EchoRequest) GetIntentName() string
读取意图名称,如标注符:{Map}
string 意图名称
func (*EchoRequest) GetRequestType ¶
func (T *EchoRequest) GetRequestType() string
读取意图类型,有效:LaunchRequest, IntentRequest, SessionEndedRequest
string 意图类型
func (*EchoRequest) GetSessionID ¶
func (T *EchoRequest) GetSessionID() string
读取本次会话的ID。如果用户结束会话,再发起会话,这个ID将是一个全新ID。
string 会话ID
func (*EchoRequest) GetSlot ¶
func (T *EchoRequest) GetSlot(slotName string) (slot *EchoRequestRequestIntentSlot, err error)
读取Solt对象
slotName 跟踪名称 slot 跟踪的对象 err 错误,如果这个名称不存在,将会返回错误
func (*EchoRequest) GetSlotNames ¶
func (T *EchoRequest) GetSlotNames() (names []string)
读取出所有Solt名称
names 所有跟踪名称
func (*EchoRequest) GetSlotValue ¶
func (T *EchoRequest) GetSlotValue(slotName string) (val string, err error)
读取Solt值
slotName 跟踪名称 val 跟踪的值 err 错误,如果这个名称不存在,将会返回错误
func (*EchoRequest) GetSlots ¶
func (T *EchoRequest) GetSlots() (slots map[string]*EchoRequestRequestIntentSlot, err error)
读取出所有Solt对象,所有值,包含空值
slots 所有跟踪名称和值 err 错误,如果不是意图类型请求,调用这个方法,将会返回错误
func (*EchoRequest) GetValueSlots ¶
func (T *EchoRequest) GetValueSlots() (slots map[string]*EchoRequestRequestIntentSlot, err error)
读取出所有Solt对象,非空值的
slots 所有跟踪名称和值 err 错误,如果不是意图类型请求,调用这个方法,将会返回错误
func (*EchoRequest) VerifyTimestamp ¶
func (T *EchoRequest) VerifyTimestamp(second int) bool
验证请求是否有效
second int 允许过时多久? bool true有效,false无效
type EchoRequestContext ¶
type EchoRequestContext struct { AudioPlayer EchoRequestContextAudioPlayer `json:"AudioPlayer"` System EchoRequestContextSystem `json:"System"` }
Alexa服务和设备的当前状态的信息。用于在会话(的上下文中发送的请求LaunchRequest和IntentRequest)时, context对象将复制user和application其也可在信息session对象。 https://developer.amazon.com/docs/custom-skills/request-and-response-json-reference.html#context-object
type EchoRequestContextAudioPlayer ¶
type EchoRequestContextAudioPlayer struct { //发送请求时的轨道偏移量(以毫秒为单位)。 //如果曲目在开头,这是0。AudioPlayer当您的技能是最近在设备上播放音频的技能时,这只会包含在对象中。 OffsetInMilliseconds int `json:"offsetInMilliseconds"` //音频播放的最后已知状态。 //IDLE:没有什么,没有入队的项目。 //PAUSED:流已暂停。 //PLAYING:流正在播放。 //BUFFER_UNDERRUN:缓冲区不足 //FINISHED:流完了。STOPPED:流被中断。 PlayerActivity string `json:"playerActivity"` //音频流的不透明标记。发送Play指令时提供此标记。 //AudioPlayer当您的技能是最近在设备上播放音频的技能时,这只会包含在对象中。 Token string `json:"token"` }
提供AudioPlayer接口当前状态的对象 https://developer.amazon.com/docs/custom-skills/request-and-response-json-reference.html#audioplayer-object
type EchoRequestContextSystem ¶
type EchoRequestContextSystem struct { APIAccessToken string `json:"apiAccessToken"` APIEndpoint string `json:"apiEndpoint"` Application EchoRequestContextSystemApplication `json:"application"` Device EchoRequestContextSystemDevice `json:"device"` User EchoRequestContextSystemUser `json:"user"` }
type EchoRequestContextSystemApplication ¶
type EchoRequestContextSystemApplication struct {
ApplicationID string `json:"applicationId"`
}
type EchoRequestContextSystemDevice ¶
type EchoRequestContextSystemDevice struct { DeviceID string `json:"deviceId"` SupportedInterfaces EchoRequestContextSystemDeviceSupportedInterfaces `json:"supportedInterfaces"` }
type EchoRequestContextSystemDeviceSupportedInterfaces ¶
type EchoRequestContextSystemDeviceSupportedInterfaces struct {
AudioPlayer struct{} `json:"AudioPlayer"`
}
type EchoRequestContextSystemUser ¶
type EchoRequestContextSystemUser struct { AccessToken string `json:"accessToken"` Permissions EchoRequestContextSystemUserPermissions `json:"permissions"` UserID string `json:"userId"` }
type EchoRequestContextSystemUserPermissions ¶
type EchoRequestContextSystemUserPermissions struct {
ConsentToken string `json:"consentToken"`
}
type EchoRequestRequest ¶
type EchoRequestRequest struct { DialogState string `json:"dialogState"` Error EchoRequestRequestError `json:"error"` Intent EchoRequestRequestIntent `json:"intent"` Locale string `json:"locale"` Reason string `json:"reason"` RequestID string `json:"requestId"` Timestamp string `json:"timestamp"` Type string `json:"type"` }
type EchoRequestRequestError ¶
type EchoRequestRequestIntent ¶
type EchoRequestRequestIntent struct { ConfirmationStatus string `json:"confirmationStatus"` Name string `json:"name"` Slots map[string]*EchoRequestRequestIntentSlot `json:"slots"` }
type EchoRequestSession ¶
type EchoRequestSession struct { Application EchoRequestSessionApplication `json:"application"` Attributes struct{} `json:"attributes"` New bool `json:"new"` SessionID string `json:"sessionId"` User EchoRequestSessionUser `json:"user"` }
type EchoRequestSessionApplication ¶
type EchoRequestSessionApplication struct {
ApplicationID string `json:"applicationId"`
}
type EchoRequestSessionUser ¶
type EchoRequestSessionUser struct { AccessToken string `json:"accessToken"` Permissions EchoRequestSessionUserPermissions `json:"permissions"` UserID string `json:"userId"` }
type EchoRequestSessionUserPermissions ¶
type EchoRequestSessionUserPermissions struct {
ConsentToken string `json:"consentToken"`
}
type EchoResponse ¶
type EchoResponse struct { Response EchoResponseResponse `json:"response"` SessionAttributes map[string]interface{} `json:"sessionAttributes,omitempty"` Version string `json:"version"` }
func (*EchoResponse) LinkAccountCard ¶
func (T *EchoResponse) LinkAccountCard() *EchoResponse
设置在屏幕上显示的卡片,仅用于用户认证
*EchoResponse 响应对象
func (*EchoResponse) OutputSpeech ¶
func (T *EchoResponse) OutputSpeech(text string) *EchoResponse
设置语音输出
text 语音文本 *EchoResponse 响应对象
func (*EchoResponse) OutputSpeechSSML ¶
func (T *EchoResponse) OutputSpeechSSML(text string) *EchoResponse
设置语音输出 更多浏览这里: https://developer.amazon.com/docs/custom-skills/speech-synthesis-markup-language-ssml-reference.html
text 语音文本(支持语气表达,等等) *EchoResponse 响应对象
func (*EchoResponse) RepromptSSML ¶
func (T *EchoResponse) RepromptSSML(text string) *EchoResponse
设置回复确认输出 更多浏览这里: https://developer.amazon.com/docs/custom-skills/speech-synthesis-markup-language-ssml-reference.html
text 语音文本(支持语气表达,等等) *EchoResponse 响应对象
func (*EchoResponse) RepromptText ¶
func (T *EchoResponse) RepromptText(text string) *EchoResponse
设置回复确认输出
text 内容 *EchoResponse 响应对象
func (*EchoResponse) SetEndSession ¶
func (T *EchoResponse) SetEndSession(ok bool) *EchoResponse
设置是否结束本次会活,默认是结束会话
ok true结束会话,fales不结束会话
func (*EchoResponse) SimpleCard ¶
func (T *EchoResponse) SimpleCard(title string, content string) *EchoResponse
设置在屏幕上显示的卡片
title 标题 content 内容 *EchoResponse 响应对象
func (*EchoResponse) StandardCard ¶
func (T *EchoResponse) StandardCard(title string, text string, smallImg string, largeImg string) *EchoResponse
设置在屏幕上显示的卡片,支持图片
title 标题 text 内容 smallImg 小图片 720w x 480h largeImg 中图片 1200w x 800h *EchoResponse 响应对象
func (*EchoResponse) String ¶
func (T *EchoResponse) String() string
type EchoResponseResponse ¶
type EchoResponseResponse struct { Card *EchoResponseResponseCard `json:"card,omitempty"` Directives []EchoResponseResponseDirectives `json:"directives,omitempty"` OutputSpeech *EchoResponseResponseOutputSpeech `json:"outputSpeech,omitempty"` Reprompt *EchoResponseResponseReprompt `json:"reprompt,omitempty"` ShouldEndSession bool `json:"shouldEndSession"` }
type EchoResponseResponseCard ¶
type EchoResponseResponseCard struct { Content string `json:"content,omitempty"` Image EchoResponseResponseCardImage `json:"image,omitempty"` Text string `json:"text,omitempty"` Title string `json:"title,omitempty"` Type string `json:"type,omitempty"` }
type EchoResponseResponseCardImage ¶
type EchoResponseResponseCardImage struct { LargeImageURL string `json:"largeImageUrl,omitempty"` SmallImageURL string `json:"smallImageUrl,omitempty"` }
https://developer.amazon.com/zh/docs/custom-skills/request-and-response-json-reference.html
HTTP/1.1 200 OK Content-Type: application/json;charset=UTF-8 Content-Length:
{ "version": "string", "sessionAttributes": { "key": "value" }, "response": { "outputSpeech": { "type": "PlainText", "text": "Plain text string to speak", "ssml": "<speak>SSML text string to speak</speak>", "playBehavior": "REPLACE_ENQUEUED" }, "card": { "type": "Standard", "title": "Title of the card", "content": "Content of a simple card", "text": "Text content for a standard card", "image": { "smallImageUrl": "https://url-to-small-card-image...", "largeImageUrl": "https://url-to-large-card-image..." } }, "reprompt": { "outputSpeech": { "type": "PlainText", "text": "Plain text string to speak", "ssml": "<speak>SSML text string to speak</speak>", "playBehavior": "REPLACE_ENQUEUED" } }, "directives": [ { "type": "InterfaceName.Directive" (...properties depend on the directive type) } ], "shouldEndSession": true } }
Response Examples:
{ "version": "1.0", "sessionAttributes": { "supportedHoroscopePeriods": { "daily": true, "weekly": false, "monthly": false } }, "response": { "outputSpeech": { "type": "PlainText", "text": "Today will provide you a new learning opportunity. Stick with it and the possibilities will be endless. Can I help you with anything else?" }, "card": { "type": "Simple", "title": "Horoscope", "content": "Today will provide you a new learning opportunity. Stick with it and the possibilities will be endless." }, "reprompt": { "outputSpeech": { "type": "PlainText", "text": "Can I help you with anything else?" } }, "shouldEndSession": false } }
Response to IntentRequest or Launch Request with Directives Example:
{ "version": "1.0", "sessionAttributes": {}, "response": { "outputSpeech": { "type": "PlainText", "text": "Playing the requested song." }, "card": { "type": "Simple", "title": "Play Audio", "content": "Playing the requested song." }, "reprompt": { "outputSpeech": { "type": "PlainText", "text": null } }, "directives": [ { "type": "AudioPlayer.Play", "playBehavior": "ENQUEUE", "audioItem": { "stream": { "token": "this-is-the-audio-token", "url": "https://my-audio-hosting-site.com/audio/sample-song.mp3", "offsetInMilliseconds": 0 } } } ], "shouldEndSession": true } }
Response to AudioPlayer or PlaybackController Example (Directives Only):
{ "version": "1.0", "response": { "directives": [ { "type": "AudioPlayer.Play", "playBehavior": "REPLACE_ALL", "audioItem": { "stream": { "token": "track2-long-audio", "url": "https://my-audio-hosting-site.com/audio/sample-song-2.mp3", "offsetInMilliseconds": 0 } } } ] } }
type EchoResponseResponseDirectives ¶
type EchoResponseResponseDirectives struct { AudioItem EchoResponseResponseDirectivesAudioItem `json:"audioItem"` PlayBehavior string `json:"playBehavior"` Type string `json:"type"` }
type EchoResponseResponseDirectivesAudioItem ¶
type EchoResponseResponseDirectivesAudioItem struct {
Stream EchoResponseResponseDirectivesAudioItemStream `json:"stream"`
}
type EchoResponseResponseReprompt ¶
type EchoResponseResponseReprompt struct {
OutputSpeech EchoResponseResponseRepromptOutputSpeech `json:"outputSpeech,omitempty"`
}