github.com/arienmalec/alexa-go@v0.0.0-20181025212142-975687393e90/request.go (about) 1 package alexa 2 3 // constants 4 5 // built in intents 6 const ( 7 //HelpIntent is the Alexa built-in Help Intent 8 HelpIntent = "AMAZON.HelpIntent" 9 10 //CancelIntent is the Alexa built-in Cancel Intent 11 CancelIntent = "AMAZON.CancelIntent" 12 13 //StopIntent is the Alexa built-in Stop Intent 14 StopIntent = "AMAZON.StopIntent" 15 ) 16 17 // locales 18 const ( 19 // LocaleItalian is the locale for Italian 20 LocaleItalian = "it-IT" 21 22 // LocaleGerman is the locale for standard dialect German 23 LocaleGerman = "de-DE" 24 25 // LocaleAustralianEnglish is the locale for Australian English 26 LocaleAustralianEnglish = "en-AU" 27 28 //LocaleCanadianEnglish is the locale for Canadian English 29 LocaleCanadianEnglish = "en-CA" 30 31 //LocaleBritishEnglish is the locale for UK English 32 LocaleBritishEnglish = "en-GB" 33 34 //LocaleIndianEnglish is the locale for Indian English 35 LocaleIndianEnglish = "en-IN" 36 37 //LocaleAmericanEnglish is the locale for American English 38 LocaleAmericanEnglish = "en-US" 39 40 // LocaleJapanese is the locale for Japanese 41 LocaleJapanese = "ja-JP" 42 ) 43 44 func IsEnglish(locale string) bool { 45 switch locale { 46 case LocaleAmericanEnglish: 47 return true 48 case LocaleIndianEnglish: 49 return true 50 case LocaleBritishEnglish: 51 return true 52 case LocaleCanadianEnglish: 53 return true 54 case LocaleAustralianEnglish: 55 return true 56 default: 57 return false 58 } 59 } 60 61 // request 62 63 // Request is an Alexa skill request 64 // see https://developer.amazon.com/docs/custom-skills/request-and-response-json-reference.html#request-format 65 type Request struct { 66 Version string `json:"version"` 67 Session Session `json:"session"` 68 Body ReqBody `json:"request"` 69 Context Context `json:"context"` 70 } 71 72 // Session represents the Alexa skill session 73 type Session struct { 74 New bool `json:"new"` 75 SessionID string `json:"sessionId"` 76 Application struct { 77 ApplicationID string `json:"applicationId"` 78 } `json:"application"` 79 Attributes map[string]interface{} `json:"attributes"` 80 User struct { 81 UserID string `json:"userId"` 82 AccessToken string `json:"accessToken,omitempty"` 83 } `json:"user"` 84 } 85 86 // Context represents the Alexa skill request context 87 type Context struct { 88 System struct { 89 APIAccessToken string `json:"apiAccessToken"` 90 Device struct { 91 DeviceID string `json:"deviceId,omitempty"` 92 } `json:"device,omitempty"` 93 Application struct { 94 ApplicationID string `json:"applicationId,omitempty"` 95 } `json:"application,omitempty"` 96 } `json:"System,omitempty"` 97 } 98 99 // ReqBody is the actual request information 100 type ReqBody struct { 101 Type string `json:"type"` 102 RequestID string `json:"requestId"` 103 Timestamp string `json:"timestamp"` 104 Locale string `json:"locale"` 105 Intent Intent `json:"intent,omitempty"` 106 Reason string `json:"reason,omitempty"` 107 DialogState string `json:"dialogState,omitempty"` 108 } 109 110 // Intent is the Alexa skill intent 111 type Intent struct { 112 Name string `json:"name"` 113 Slots map[string]Slot `json:"slots"` 114 } 115 116 // Slot is an Alexa skill slot 117 type Slot struct { 118 Name string `json:"name"` 119 Value string `json:"value"` 120 Resolutions Resolutions `json:"resolutions"` 121 } 122 123 type Resolutions struct { 124 ResolutionPerAuthority []struct{ 125 Values []struct{ 126 Value struct{ 127 Name string `json:"name"` 128 Id string `json:"id"` 129 } `json:"value"` 130 } `json:"values"` 131 } `json:"resolutionsPerAuthority"` 132 }