alexa

package
v0.0.0-...-6e49c5b Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Day is a time.Duration of 24 hours
	Day time.Duration = time.Hour * 24
	// Week is a time.Duration of 7 days
	Week time.Duration = Day * 7
)

Variables

View Source
var ErrNotUS = errors.New("this API only works for devices in the US")

ErrNotUS is an error indicating that the requeting user does not reside in the USA

View Source
var ErrUnknownZipcode = errors.New("unknown zipcode")

ErrUnknownZipcode is set when the Alexa API returns 204 staus code saying that the device has no zipcode stored in their system

Functions

func ResponseText

func ResponseText(msg string) interface{}

ResponseText creates a response message to send to an alexa request

Types

type API

type API interface {
	DeviceZip(ctx context.Context, deviceID, apiAccessToken string) (string, error)
}

API loads zipcodes for devices

type Client

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

Client is an api for interacting with the Alexa HTTP Client

func NewAPI

func NewAPI() *Client

NewAPI creates a new API that connects to the Alexa API for retrieving zipcodes for deviceIDs provided with requests

func (*Client) DeviceZip

func (api *Client) DeviceZip(ctx context.Context, deviceID, apiAccessToken string) (string, error)

DeviceZip gets the zipcode from the amazon alexa request using the API instructions found here https://developer.amazon.com/docs/custom-skills/device-address-api.html

Accept: application/json Authorization: Bearer {apiAccessToken} GET https://api.amazonalexa.com/v1/devices/{deviceId}/settings/address/countryAndPostalCode

type JSON

type JSON map[string]interface{}

JSON is json

type Request

type Request struct {
	Version string `json:"version"`
	Session struct {
		New         bool   `json:"new"`
		SessionID   string `json:"sessionId"`
		Application struct {
			ApplicationID string `json:"applicationId"`
		} `json:"application"`
		Attributes struct {
			Key string `json:"key"`
		} `json:"attributes"`
		User struct {
			UserID      string `json:"userId"`
			AccessToken string `json:"accessToken"`
			Permissions struct {
				ConsentToken string `json:"consentToken"`
			} `json:"permissions"`
		} `json:"user"`
	} `json:"session"`
	Context struct {
		System struct {
			Device struct {
				DeviceID            string `json:"deviceId"`
				SupportedInterfaces struct {
					AudioPlayer struct {
					} `json:"AudioPlayer"`
				} `json:"supportedInterfaces"`
			} `json:"device"`
			Application struct {
				ApplicationID string `json:"applicationId"`
			} `json:"application"`
			User struct {
				UserID      string `json:"userId"`
				AccessToken string `json:"accessToken"`
				Permissions struct {
					ConsentToken string `json:"consentToken"`
				} `json:"permissions"`
			} `json:"user"`
			APIEndpoint    string `json:"apiEndpoint"`
			APIAccessToken string `json:"apiAccessToken"`
		} `json:"System"`
		AudioPlayer struct {
			PlayerActivity       string `json:"playerActivity"`
			Token                string `json:"token"`
			OffsetInMilliseconds int    `json:"offsetInMilliseconds"`
		} `json:"AudioPlayer"`
	} `json:"context"`
	Request RequestBody `json:"request"`
}

Request is found here https://developer.amazon.com/docs/custom-skills/request-and-response-json-reference.html

type RequestBody

type RequestBody struct {
	Type      string `json:"type"`
	RequestID string `json:"requestId"`
	Intent    struct {
		Name  string `json:"name"`
		Slots struct {
			Condition struct {
				Value string `json:"value"`
			} `json:"condition"`
			Time struct {
				Value string `json:"value"`
			} `json:"time"`
			Day struct {
				Value string `json:"value"`
			} `json:"day"`
		} `json:"slots"`
	} `json:"intent"`
	Locale    string    `json:"locale"`
	Timestamp time.Time `json:"timestamp"`
}

RequestBody is the body of the specific request

type TimeSpan

type TimeSpan struct {
	Start time.Time
	End   time.Time
}

TimeSpan is a period of time indicating a start time, a Span, and a count

func (TimeSpan) Diff

func (ts TimeSpan) Diff() time.Duration

func (TimeSpan) IsZero

func (ts TimeSpan) IsZero() bool

IsZero returns true if TimeSpan is zero value

func (TimeSpan) String

func (ts TimeSpan) String() string

type WeatherRequest

type WeatherRequest struct {
	Condition string
	TimeSpan
}

WeatherRequest is a formatted RequestBody

func ParseWeatherRequest

func ParseWeatherRequest(r RequestBody, loc *time.Location) WeatherRequest

ParseWeatherRequest parses the RequestBody as a WeatherRequest

Jump to

Keyboard shortcuts

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