Documentation
¶
Overview ¶
Package amsapi is a golang implementation of the json structures required to interact with the Alexa Music, Radio, and Podcast Skill API.
The documentation text was copied as is from the Alexa documentation site with minor corrections and formatting.
https://developer.amazon.com/en-US/docs/alexa/music-skills/api-reference-overview.html
Note: See top README.md for current status / completeness.
Index ¶
- Constants
- func Bind[K any](j *Request, value K) K
- type Art
- type ArtSource
- type Content
- type ContentActions
- type EntityMetadata
- type Feedback
- type Filter
- type GetNextItem
- type GetNextItemResponse
- type GetPlayableContent
- type GetPlayableContentResponse
- type GetPreviousItem
- type GetPreviousItemResponse
- type Initiate
- type InitiateResponse
- type Item
- type ItemControl
- type ItemControlName
- type ItemControlType
- type ItemReference
- type ItemRules
- type JumpToItem
- type JumpToItemResponse
- type Location
- type MediaMetadata
- type MediaReference
- type MetadataName
- type MetadataNameProperty
- type PlaybackInfo
- type PlaybackInfoType
- type PlaybackMethod
- type PlaybackModes
- type QueueControl
- type QueueFeedbackRule
- type QueueRules
- type Request
- type RequestContext
- type ResolvedSelectionCriteria
- type ResolvedSelectionCriteriaAttribute
- type Response
- type SpeechInfo
- type SpeechInfoType
- type Stream
- type User
Constants ¶
const PlaybackMethodType = "ALEXA_AUDIO_PLAYER_QUEUE"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Art ¶
type Art struct {
Sources []ArtSource `json:"sources"`
}
Art contains artwork for a media content. Images must be in PNG or JPG file format. For other requirements for Alexa skill content, including background images, see Policy Testing.
https://developer.amazon.com/en-US/docs/alexa/music-skills/api-components-reference.html#art
type ArtSource ¶
type ArtSource struct {
// The URL for the image of this size. URL must be HTTPS.
Url string `json:"url"`
// The size for the image. Alexa can use this optional field to help determine which size of ArtSource to use.
// "X_SMALL" (recommended for images approximately 48 x 48 pixels)
// "SMALL" (recommended for 60 x 60 pixels)
// "MEDIUM" (recommended for 110 x 110 pixels)
// "LARGE" (recommended for 256 x 256 pixels)
// "X_LARGE" (recommended for 600 x 600 pixels)
Size string `json:"size,omitempty"`
WidthPixels int `json:"widthPixels,omitempty"`
HeightPixels int `json:"heightPixels,omitempty"`
}
ArtSource contains information about a single size of a media content's art (for example, album cover art). Images must be in PNG or JPG file format.
https://developer.amazon.com/en-US/docs/alexa/music-skills/api-components-reference.html#artsource
type Content ¶
type Content struct {
Id string `json:"id"`
Actions ContentActions `json:"actions"`
Metadata MediaMetadata `json:"metadata"`
}
Content includes an identifier (reference) and metadata (for example, album name, author name, title, type, etc.).
The content object can represent a single track, an album, a playlist, a custom station, a live station, or a program. content objects are global and can be shared between different users.
For example, if content object 1234 is the album "King Animal" by Soundgarden, this is true for any user who receives content object 1234, and if a user receives content object 1234 a year later, it should still represent the album King Animal by Soundgarden.
The content object is the primary object for the Alexa.Media.Search interface.
https://developer.amazon.com/en-US/docs/alexa/music-skills/api-components-reference.html#content
type ContentActions ¶
ContentActions describes whether a content object represents content that's playable, browsable, or both.
The flags in this object are intended to support display use cases where the user can click a content object to play all its contents (for example, play an entire album) or the user can click a content object to view the items within (for example, see the tracks listing for the album) and perhaps play one item.
type EntityMetadata ¶
type EntityMetadata struct {
Name MetadataNameProperty `json:"name"`
}
EntityMetadata is for entities like artists, songs, etc.
func BuildAuthors ¶ added in v0.2.0
func BuildAuthors(text, display string) []EntityMetadata
BuildAuthors builds a slice of one author with the given text and display data.
type Feedback ¶
Feedback describes the user's feedback or preference about an item.
For example, if the user had previously indicated "thumbs up" for the item, the skill should set the feedback type to PREFERENCE and the feedback value to POSITIVE.
https://developer.amazon.com/en-US/docs/alexa/music-skills/api-components-reference.html#feedback
type Filter ¶
type Filter struct {
ExplicitLanguageAllowed bool `json:"explicitLanguageAllowed"`
}
Filter describes filters that the skill should apply to search results (selection criteria and content) before returning a response to the Alexa service.
https://developer.amazon.com/en-US/docs/alexa/music-skills/api-components-reference.html#filters
type GetNextItem ¶ added in v0.1.2
type GetNextItem struct {
// Context information about the request.
RequestContext *RequestContext `json:"requestContext"`
// The currently playing item.
CurrentItemReference *ItemReference `json:"currentItemReference"`
// true if the user explicitly asked to skip to the next track (for music) or program (for podcasts),
// false if the current track or program will soon end and the next item is needed.
IsUserInitiated bool `json:"isUserInitiated,omitempty"`
}
GetNextItem is sent to the skill when a content queue exists and playback has started on the Alexa device. https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-audio-playqueue.html#getnextitem-directive
type GetNextItemResponse ¶ added in v0.1.2
type GetNextItemResponse struct {
// A flag that indicates whether the currently playing item is the last item in the queue.
// When this value is false, the item field must be present and contain a non-null value.
// When this value is true, the item field must be absent or set to null.
IsQueueFinished bool `json:"isQueueFinished"`
// The requested item in the play queue.
Item *Item `json:"item"`
}
GetNextItemResponse is the reply to a GetNextItem request. If your skill has a next item to return, return the next item. If the currently playing item is the last item in the queue, your skill should send "isQueueFinished": true to indicate that there are no more items. https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-audio-playqueue.html#getnextitem-response-event
type GetPlayableContent ¶
type GetPlayableContent struct {
RequestContext RequestContext `json:"requestContext"`
Filters Filter `json:"filters"`
SelectionCriteria ResolvedSelectionCriteria `json:"selectionCriteria"`
}
GetPlayableContent supports the GetPlayableContent directive so that customers can request content.
type GetPlayableContentResponse ¶
type GetPlayableContentResponse struct {
Content Content `json:"content"`
}
GetPlayableContentResponse is the reply to GetPlayableContent. If you handle a GetPlayableContent directive successfully, respond with an Alexa.Response event. If your skill can successfully find playable content to satisfy the request, it should respond with GetPlayableContentResponse.
type GetPreviousItem ¶ added in v0.1.2
type GetPreviousItem struct {
// Context information about the request.
RequestContext *RequestContext `json:"requestContext"`
// The currently playing item.
CurrentItemReference *ItemReference `json:"currentItemReference"`
}
GetPreviousItem request is sent to the skill when a content queue exists and playback has started on the Alexa device. https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-audio-playqueue.html#getpreviousitem-directive
type GetPreviousItemResponse ¶ added in v0.1.2
type GetPreviousItemResponse struct {
// The previous item in the play queue.
Item *Item `json:"item"`
}
GetPreviousItemResponse should be returned when the skill has a previous item to return. https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-audio-playqueue.html#getpreviousitem-response-event
type Initiate ¶
type Initiate struct {
RequestContext RequestContext `json:"requestContext"`
Filters Filter `json:"filters"`
ContentId string `json:"contentId"`
CurrentItemReference MediaReference `json:"currentItemReference"`
PlaybackModes PlaybackModes `json:"playbackModes"`
}
Initiate payloads are sent when Alexa receives a content identifier from a skill's GetPlayableContent response.
The skill responds with the Stream URI, and playback begins.
type InitiateResponse ¶
type InitiateResponse struct {
PlaybackMethod PlaybackMethod `json:"playbackMethod"`
}
InitiateResponse is a reply to an Initiate directive.
The skill's Initiate response includes a play queue based on the requested ContentId, the first playable track, and enough information for Alexa to manage the queue.
To get the second track, Alexa calls GetNextItem after the first track begins.
Subsequent tracks are also retrieved with GetNextItem. For details, see Alexa.Audio.PlayQueue Interface.
https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-media-playback.html
type Item ¶
type Item struct {
// A identifier for the item that is opaque to Alexa.
// Note that the item should be unique within the queue.
Id string `json:"id"`
// Describes which business rules Alexa should run when playing or displaying this item. See the PlaybackInfo object for details.
PlaybackInfo PlaybackInfo `json:"playbackInfo"`
// Metadata for the item.
//
// For playbackInfo types DEFAULT and SAMPLE, the value is an instance of MediaMetadata, where the metadata
// type field can be TRACK (for music), STATION (for radio), or PROGRAM (for podcasts).
// See the MediaMetadata object for details.
//
// For playbackInfo type AD, the value is an instance of AdMetadata. See the AdMetadata object for details.
// (Note: Ads aren't supported for podcasts.)
// TODO: support AdMetadata also with common interface or generics
Metadata MediaMetadata `json:"metadata"`
// Duration of the item in milliseconds. If the item is a live stream, do not return this field.
DurationInMilliseconds int `json:"durationInMilliseconds,omitempty"`
// List of ItemControl objects used by Alexa to determine which controls should be clickable in the Alexa app.
Controls []ItemControl `json:"controls,omitempty"`
// Object which contains rules for the item. See ItemRules for details.
Rules ItemRules `json:"rules"`
// Object that contains stream information for this item. See the Stream object for more information.
Stream Stream `json:"stream"`
Feedback *Feedback `json:"feedback,omitempty"`
}
Item is an audio item that contains within it an identifier and metadata (for example, art URLs, author name, title, etc.), and a Stream containing the playback URL.
Note that in some cases, the duration of an item needs to be displayed when there is no stream for that item. That is why the duration field is a peer to the stream field and not a member of it.
https://developer.amazon.com/en-US/docs/alexa/music-skills/api-components-reference.html#item
type ItemControl ¶
type ItemControl struct {
// The type of the control. This can be one of the following:
// ADJUST - for controls such as seeking
// COMMAND - for controls such as skipping
Type ItemControlType `json:"type"`
// The name of the control.
//
// For type ADJUST, the value for name can be one of the following:
// SEEK_POSITION - enables user to seek forward and back within a currently playing track
//
// For type COMMAND, the value for name can be one of the following:
// NEXT - for skipping to the next item
// PREVIOUS - for skipping to the previous item
Name ItemControlName `json:"name"`
// Informs Alexa whether the control is enabled.
// For some control types, this determines whether the button for the control should be clickable:
// set the value to true when the control should be clickable by the user in the Alexa app.
Enabled bool `json:"enabled"`
}
ItemControl describes a control that the user can take on an item.
Examples are skip forward and skip backward buttons.
Note that item controls will override any existing queue controls of the same type.
The object has the same structure as BaseControl.
https://developer.amazon.com/en-US/docs/alexa/music-skills/api-components-reference.html#itemcontrol
func BuildItemControlNext ¶ added in v0.2.0
func BuildItemControlNext(enabled bool) ItemControl
BuildItemControlNext builds a command next control with the provided state.
func BuildItemControlPrevious ¶ added in v0.2.0
func BuildItemControlPrevious(enabled bool) ItemControl
BuildItemControlPrevious builds a command previous control with the provided state.
type ItemControlName ¶ added in v0.2.0
type ItemControlName string
const ItemControlNameNext ItemControlName = "NEXT"
const ItemControlNamePrevious ItemControlName = "PREVIOUS"
const ItemControlNameSeekPosition ItemControlName = "SEEK_POSITION"
type ItemControlType ¶ added in v0.2.0
type ItemControlType string
const ItemControlTypeAdjust ItemControlType = "ADJUST"
const ItemControlTypeCommand ItemControlType = "COMMAND"
type ItemReference ¶
type ItemReference struct {
Id string `json:"id"`
QueueId string `json:"queueId"`
ContentId string `json:"contentId"`
}
ItemReference identifies a specific Item.
type ItemRules ¶
type ItemRules struct {
FeedbackEnabled bool `json:"feedbackEnabled"`
}
ItemRules describes rules for what the user can do with an item.
One example of a rule is whether the user can provide feedback about an audio item.
Note that item level rules will override queue level rules.
https://developer.amazon.com/en-US/docs/alexa/music-skills/api-components-reference.html#itemrules
type JumpToItem ¶ added in v0.1.2
type JumpToItem struct {
// Context information about the request.
RequestContext *RequestContext `json:"requestContext"`
// The currently playing item.
CurrentItemReference *ItemReference `json:"currentItemReference"`
// The identifier of the item to jump to.
TargetItemId string `json:"targetItemId"`
}
JumpToItem request is sent to the skill when audio content is playing from a music skill, and the user views the active queue of music (resulting from a GetView response) in the Alexa app then clicks on a track in the list to play. https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-audio-playqueue.html#jumptoitem-directive
type JumpToItemResponse ¶ added in v0.1.2
type JumpToItemResponse struct {
// The requested item in the play queue.
Item *Item `json:"item"`
}
JumpToItemResponse is returned when the requested item is valid and the jump is allowed. https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-audio-playqueue.html#jumptoitem-response-event
type Location ¶
type Location struct {
OriginatingLocale string `json:"originatingLocale,omitempty"`
CountryCode string `json:"countryCode,omitempty"`
}
Location describes the location of a request. Use this information to enforce geographical restrictions on content or decide which language version of metadata to return to Alexa for media items.
https://developer.amazon.com/en-US/docs/alexa/music-skills/api-components-reference.html#location
type MediaMetadata ¶
type MediaMetadata struct {
Type types.EntityType `json:"type"`
Name MetadataName `json:"name"`
Art Art `json:"art"`
Authors []EntityMetadata `json:"authors,omitempty"`
Album EntityMetadata `json:"albums,omitempty"`
Artists []EntityMetadata `json:"artists,omitempty"`
}
MediaMetadata contains metadata (for example, album name, author name, title, "type", etc.) for a media item (i.e., Content or Item). MediaMetadata extends BaseMetadata, and supports the following metadata types:
ALBUM - for an album (Music only) ARTIST - for an artist (Music only) GENRE - for a genre (Music only) PLAYLIST - for a playlist PROGRAM - for a program (episode) or program series (Podcast only) STATION - for a station (Radio only) TRACK - for a track/song (Music only)
type MediaReference ¶
type MediaReference struct {
Namespace string `json:"namespace"`
Name string `json:"name"`
Value ItemReference `json:"value"`
}
MediaReference is a polymorphic used to identify a specific media item (Item) to be used in cases where a media item must be identified in a domain-agnostic manner.
type MetadataName ¶
type MetadataName struct {
Speech SpeechInfo `json:"speech"`
Display string `json:"display"`
}
MetadataName is used for voice prompt or display use cases of entity (artist, song, etc.) names.
func BuildMetadataName ¶ added in v0.2.0
func BuildMetadataName(text, display string) MetadataName
BuildMetadataName is shorthand for:
return MetadataName{
Speech: SpeechInfo{
Type: SpeechInfoTypePlainText,
Text: text,
},
Display: display,
}
type MetadataNameProperty ¶
type MetadataNameProperty struct {
Speech SpeechInfo `json:"speech"`
Display string `json:"display"`
}
MetadataNameProperty is used for voice prompt or display use cases of entity (artist, song, etc.) names.
type PlaybackInfo ¶
type PlaybackInfo struct {
// The type of playback info. The field can have one of the following values:
//
// DEFAULT - describes an item that is neither a sample nor an ad
// SAMPLE - describes an item whose stream is a shorter version of a full track
// AD - describes an item whose stream is an advertisement
// (Note: Ads aren't supported for podcasts.)
Type PlaybackInfoType `json:"type"`
}
PlaybackInfo describes which business rules Alexa should run when playing an item.
More specifically for advertisements, Alexa will follow these rules:
No skipping or seeking allowed No mention of the advertisement in prompts (or display use cases) for what's playing next Alexa may want to inform users (in the app's Now Playing screen) that an advertisement is currently playing Some potential differences in metadata for an advertisement versus a default track
For samples, Alexa will render different prompts (mentioning that an item is a sample and not the full track), and it may potentially augment the item's metadata.
type PlaybackInfoType ¶ added in v0.2.0
type PlaybackInfoType string
const PlaybackInfoTypeAd PlaybackInfoType = "AD"
const PlaybackInfoTypeDefault PlaybackInfoType = "DEFAULT"
const PlaybackInfoTypeSample PlaybackInfoType = "SAMPLE"
type PlaybackMethod ¶
type PlaybackMethod struct {
// The type of the playback method. The only allowed value is ALEXA_AUDIO_PLAYER_QUEUE.
Type string `json:"type"`
// The identifier for this play queue that is opaque to Alexa. If the skill wants to enforce concurrency limits,
// then the queue ID should be unique for each user. Note that all Music Skill API requests after a queue is
// created will report this queue ID back to the skill in all requests.
Id string `json:"id"`
// List of QueueControl objects used by Alexa to determine which controls should be clickable in the Alexa app.
// Note that some queue-level controls might be overridden at the item-level.
// See the QueueControl object for more information.
Controls []QueueControl `json:"controls,omitempty"`
// Identifies rules that apply to all audio items in the play queue.
// Note that some queue-level rules may be overridden at the item-level.
Rules QueueRules `json:"rules,omitempty"`
// The first item from this queue that Alexa should play for the user.
// See the Item object for more information.
FirstItem Item `json:"firstItem"`
}
PlaybackMethod is a realization of Content.
When Alexa has a reference to some content as a result of GetPlayableContent, and wants to start playback for the user, it invokes the skill with the content reference so the skill can realize the content into a PlaybackMethod.
type PlaybackModes ¶
PlaybackModes represent the playback modes requested by the user. If the user doesn't request a looped or shuffled queue, this attribute defaults to false for all supported playback modes.
type QueueControl ¶
type QueueControl struct {
// The type of the control. This can be one of the following:
// ADJUST - for controls such as seeking
// COMMAND - for controls such as skipping
//
// QueueControl supports the following types in addition to the base types:
// TOGGLE - for controls such as shuffle
Type string `json:"type"`
// The name of the control.
//
// For type ADJUST, the value for name can be one of the following:
// SEEK_POSITION - enables user to seek forward and back within a currently playing track
//
// For type COMMAND, the value for name can be one of the following:
// NEXT - for skipping to the next item
// PREVIOUS - for skipping to the previous item
//
// For QueueControl type TOGGLE, the value can be one of the following:
// SHUFFLE - for toggling shuffle mode for the queue
// LOOP - for toggling loop mode for the queue
//
// Note the following controls are overridable at the item level:
// SEEK_POSITION, NEXT, PREVIOUS
Name string `json:"name"`
// Informs Alexa whether the control is enabled.
//
// For some control types, this determines whether the button for the control should be
// clickable: set the value to true when the control should be clickable by the user in the Alexa app.
Enabled bool `json:"enabled"`
// Indicates that a control should render in a selected state.
// For example, if a user has turned on loop mode in the provider's app, when the queue is cast to an Alexa device,
// the loop control will have a selected value of true. Defaults to false.
Selected bool `json:"selected,omitempty"`
}
QueueControl describes a control that the user could apply to a queue or the items in the queue.
Examples are shuffle and loop. Note that some queue controls can be overridden at the item level. Note that if the enablement status of a control isn't specified, Alexa assumes the control is disabled.
type QueueFeedbackRule ¶
type QueueFeedbackRule struct {
// The type of feedback.
// The only supported value is PREFERENCE.
Type string `json:"type"`
// Whether feedback should be enabled.
//
// If false, Alexa will render error prompts (VUI) or show error messages (GUI) when the user tries to provide
// feedback. Note that this flag can be overridden on an item-by-item basis.
Enabled bool `json:"enabled"`
}
QueueFeedbackRule describes whether feedback of a specific type is allowed at the queue level.
type QueueRules ¶
type QueueRules struct {
Feedback QueueFeedbackRule `json:"feedback"`
}
QueueRules identifies rules that apply to all items in the play queue.
https://developer.amazon.com/en-US/docs/alexa/music-skills/api-components-reference.html#queuerules
type Request ¶
type Request struct {
Header *header.Header `json:"header"`
Payload *json.RawMessage `json:"payload,omitempty"`
BoundPayload any `json:"bound_payload,omitempty"`
}
type RequestContext ¶
type RequestContext struct {
User User `json:"user"`
Location Location `json:"location,omitempty"`
}
RequestContext describes the context of an Alexa Music Skill API request. If the music service provider supports premium audio in their skill, requests for GetItem, GetNextItem, GetPreviousItem, and JumpToItem contain an Endpoint object in the RequestContext containing information about what types of audio quality streams are supported on the target device.
type ResolvedSelectionCriteria ¶
type ResolvedSelectionCriteria struct {
Attributes []ResolvedSelectionCriteriaAttribute `json:"attributes"`
}
ResolvedSelectionCriteria is content selection criteria in resolved form. A ResolvedSelectionCriteria object identifies attributes that can be resolved (by searching) to a Content object.
type ResolvedSelectionCriteriaAttribute ¶
type ResolvedSelectionCriteriaAttribute struct {
Type types.EntityType `json:"type"`
EntityId string `json:"entityId,omitempty"`
Value string `json:"value,omitempty"`
}
ResolvedSelectionCriteriaAttribute is a single attribute within a resolved content selection criteria.
A ResolvedSelectionCriteriaAttribute object conveys a single aspect of a user's request in refined or processed form, such as the song name "Thrift Shop" (with skill-provided entitytype ID) in Alexa, play the song Thrift Shop.
type SpeechInfo ¶
type SpeechInfo struct {
Type SpeechInfoType `json:"type"`
Text string `json:"text"`
}
SpeechInfo captures the details of how Alexa should render text in voice prompts to the user.
https://developer.amazon.com/en-US/docs/alexa/music-skills/api-components-reference.html#speechinfo
type SpeechInfoType ¶ added in v0.2.0
type SpeechInfoType string
const SpeechInfoTypePlainText SpeechInfoType = "PLAIN_TEXT"
type Stream ¶
type Stream struct {
// A unique opaque (to Alexa) identifier for the stream.
//
// Note that the same stream (with the same identifier) can be re-used across User and Queue instances.
Id string `json:"id"`
// URI of the stream (file or audio-chunk playlist).
//
// This URI is sent to the Alexa device media player to play the content.
//
// URIs must be HTTPS.
Uri string `json:"uri"`
// Offset, in milliseconds, at which to start playback of the stream.
//
// Defaults to 0.
OffsetInMilliseconds int `json:"offsetInMilliseconds,omitempty"`
// Offset, in milliseconds, at which to stop playback.
//
// If endOffsetInMilliseconds is greater than the actual track length, it's ignored, and the
// stream plays to the end. Must be greater than or equal to offsetInMilliseconds.
//
// If endOffsetInMilliseconds is less than offsetInMilliseconds, a validation exception is raised.
EndOffsetInMilliseconds int `json:"endOffsetInMilliseconds,omitempty"`
// https://en.wikipedia.org/wiki/ISO_8601 representation of when the stream URI expires.
//
// Use the ISO 8601 extended format with UTC offset, for example 2019-01-29TT07:00:00.000Z.
ValidUntil time.Time `json:"validUntil,omitempty"`
}
Stream contains the stream URI that Alexa sends to devices as part of an AudioPlayer play directive, along with other stream-related information such as the playback offset in milliseconds, the expiration time of the URI, and an identifier for the stream.
https://developer.amazon.com/en-US/docs/alexa/music-skills/api-components-reference.html#stream
type User ¶
User describes information about the user who initiated a request to the music skill.
https://developer.amazon.com/en-US/docs/alexa/music-skills/api-components-reference.html#user