アクセスいただきありがとうございます。こちらのページは現在英語のみのご用意となっております。順次日本語化を進めてまいりますので、ご理解のほどよろしくお願いいたします。

Sample Lambda Function (VSK MM)

In Step 1: Create Your Video Skill and Lambda Function, you integrated some basic code as a sample Lambda function to get started. For convenience and easy reference, this function is also added below. See Step 3: Understand the Alexa Directives and Expected Responses for a detailed explanation of the logic of this sample Lambda code.

Copied to clipboard.

/**
 * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Amazon Software License (the "License"). You may not use
 * this file except in compliance with the License. A copy of the License is
 * located at http://aws.amazon.com/asl/ or in the "license" file accompanying
 * this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
 * OR CONDITIONS OF ANY KIND, express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 **/

// This is a sample lambda for use with video skills on multimodal devices.
// This is sample code only, and does not come with any guarantees.
var AWS = require('aws-sdk');

exports.handler = (event, context, callback) => {
    console.log("Interaction starts");
    hardCodedResponse(event, context);
};

function hardCodedResponse(event, context) {
    var name = event.directive.header.name;
    console.log("Alexa Request: ", name, JSON.stringify(event));
    var DiscoverResultResponse = {
        "event": {
            "header": {
                "namespace": "Alexa.Discovery",
                "name": "Discover.Response",
                "payloadVersion": "3",
                "messageId": "ff746d98-ab02-4c9e-9d0d-b44711658414"
            },
            "payload": {
                "endpoints": [{
                    "endpointId": "ALEXA_VOICE_SERVICE_EXTERNAL_MEDIA_PLAYER_VIDEO_PROVIDER",
                    "endpointTypeId": "TEST_VSK_MM",
                    "manufacturerName": "TEST_VSK_MM",
                    "friendlyName": "TEST_VSK_MM",
                    "description": "TEST_VSK_MM",
                    "displayCategories": ["APPLICATION"],
                    "cookie": {},
                    "capabilities": [{
                            "type": "AlexaInterface",
                            "interface": "Alexa.RemoteVideoPlayer",
                            "version": "1.0"
                        }, {
                            "type": "AlexaInterface",
                            "interface": "Alexa.PlaybackController",
                            "version": "1.0"
                        }, {
                            "type": "AlexaInterface",
                            "interface": "Alexa.SeekController",
                            "version": "1.0"
                        }, {
                            "type": "AlexaInterface",
                            "interface": "Alexa.ChannelController",
                            "version": "1.0"
                        },
                        {
                            "type": "AlexaInterface",
                            "interface": "Alexa.MultiModalLandingPage",
                            "version": "1.0"
                        }
                    ]
                }]
            }
        }
    };

    var GetPlayableItemsResponse = {
        "event": {
            "header": {
                "correlationToken": "dFMb0z+PgpgdDmluhJ1LddFvSqZ/jCc8ptlAKulUj90jSqg==",
                "messageId": "5f0a0546-caad-416f-a617-80cf083a05cd",
                "name": "GetPlayableItemsResponse",
                "namespace": "Alexa.VideoContentProvider",
                "payloadVersion": "3"
            },
            "payload": {
                "nextToken": "fvkjbr20dvjbkwOpqStr",
                "mediaItems": [{
                    "mediaIdentifier": {
                        "id": "tt1254207"
                    }
                }]
            }
        }
    };

    var GetPlayableItemsMetadataResponse = {
        "event": {
            "header": {
                "correlationToken": "dFMb0z+PgpgdDmluhJ1LddFvSqZ/jCc8ptlAKulUj90jSqg==",
                "messageId": "38ce5b22-eeff-40b8-a84f-979446f9b27e",
                "name": "GetPlayableItemsMetadataResponse",
                "namespace": "Alexa.VideoContentProvider",
                "payloadVersion": "3"
            },
            "payload": {
                "searchResults": [{
                    "name": "Big Buck Bunny",
                    "contentType": "ON_DEMAND",
                    "series": {
                        "seasonNumber": "1",
                        "episodeNumber": "1",
                        "seriesName": "Blender Foundation Videos",
                        "episodeName": "Pilot"
                    },
                    "playbackContextToken": "{\"streamUrl\": \"http:\/\/commondatastorage.googleapis.com\/gtv-videos-bucket\/sample\/BigBuckBunny.mp4\", \"title\": \"Big Buck Bunny\"}",
                    "parentalControl": {
                        "pinControl": "REQUIRED"
                    },
                    "absoluteViewingPositionMilliseconds": 1232340
                }]
            }
        }
    };

    var GetDisplayableItemsResponse = {
        "event": {
            "header": {
                "correlationToken": "dFMb0z+PgpgdDmluhJ1LddFvSqZ/jCc8ptlAKulUj90jSqg==",
                "messageId": "5f0a0546-caad-416f-a617-80cf083a05cd",
                "name": "GetDisplayableItemsResponse",
                "namespace": "Alexa.VideoContentProvider",
                "payloadVersion": "3"
            },
            "payload": {
                "nextToken": "fvkjbr20dvjbkwOpqStr",
                "mediaItems": [{
                        "mediaIdentifier": {
                            "id": "tt1254207"
                        }
                    },
                    {
                        "mediaIdentifier": {
                            "id": "tt0807840"
                        }
                    },
                    {
                        "mediaIdentifier": {
                            "id": "tt7993892"
                        }
                    },
                    {
                        "mediaIdentifier": {
                            "id": "tt4957236"
                        }
                    },
                    {
                        "mediaIdentifier": {
                            "id": "tt2285752"
                        }
                    }
                ]
            }
        }
    };

    var GetNextPageResponse = {
        "event": {
            "header": {
                "correlationToken": "dFMb0z+PgpgdDmluhJ1LddFvSqZ/jCc8ptlAKulUj90jSqg==",
                "messageId": "9f4803ec-4c94-4fdf-89c2-d502d5e52bb4",
                "name": "GetNextPageResponse",
                "namespace": "Alexa.VideoContentProvider",
                "payloadVersion": "3"
            },
            "endpoint": {
                "scope": {
                    "type": "BearerToken",
                    "token": "Alexa-access-token"
                },
                "endpointId": "appliance-001"
            },
            "payload": {
                "nextToken": "qefjrfiugef74",
                "mediaItems": [{
                        "mediaIdentifier": {
                            "id": "tt0807840"
                        }
                    },
                    {
                        "mediaIdentifier": {
                            "id": "tt1254207"
                        }
                    },
                                        {
                        "mediaIdentifier": {
                            "id": "tt7993892"
                        }
                    },
                                        {
                        "mediaIdentifier": {
                            "id": "tt2285752"
                        }
                    },
                                        {
                        "mediaIdentifier": {
                            "id": "tt4957236"
                        }
                    }
                ]
            }
        }
    }

    var GetDisplayableItemsMetadataResponse = {
        "event": {
            "header": {
                "correlationToken": "dFMb0z+PgpgdDmluhJ1LddFvSqZ/jCc8ptlAKulUj90jSqg==",
                "messageId": "38ce5b22-eeff-40b8-a84f-979446f9b27e",
                "name": "GetDisplayableItemsMetadataResponse",
                "namespace": "Alexa.VideoContentProvider",
                "payloadVersion": "3"
            },
            "payload": {
                "resultsTitle": "SearchResults",
                "searchResults": [{
                        "name": "Big Buck Bunny",
                        "contentType": "ON_DEMAND",
                        "itemType": "VIDEO",
                        "releaseYear": "2014",
                        "selectionAction": "PLAY",
                        "thumbnailImage": {
                            "contentDescription": "Big Buck Bunny image",
                            "sources": [{
                                "url": "https:\/\/devportal-reference-docs.s3-us-west-1.amazonaws.com\/video-skills-kit\/bigbuckbunnythumb.png",
                                "size": "X_LARGE",
                                "widthPixels": 1920,
                                "heightPixels": 1280
                            }]
                        },
                        "runtime": {
                            "runTimeInMilliseconds": 540000,
                            "displayString": "9m"
                        },
                        "closedCaption": {
                            "status": "AVAILABLE",
                            "displayString": "CC"
                        },
                        "absoluteViewingPositionMilliseconds": 0,
                        "parentalControl": {
                            "pinControl": "REQUIRED"
                        },
                        "viewingDisplayString": "PurchaseOptions",
                        "reviews": [{
                            "totalReviewCount": 1897,
                            "type": "FIVE_STAR",
                            "ratingDisplayString": "4.06"
                        }],
                        "rating": {
                            "category": "G"
                        },
                        "mediaIdentifier": {
                            "id": "tt1254207"
                        }
                        },
                        {
                        "name": "Cosmos Laundromat",
                        "contentType": "ON_DEMAND",
                        "itemType": "VIDEO",
                        "releaseYear": "2014",
                        "selectionAction": "PLAY",
                        "thumbnailImage": {
                            "contentDescription": "On a desolate island, suicidal sheep Franck meets his fate in a quirky salesman, who offers him the gift of a lifetime. Little does he know that he can only handle so much lifetime...",
                            "sources": [{
                                "url": "https:\/\/devportal-reference-docs.s3-us-west-1.amazonaws.com\/video-skills-kit\/cosmos_laundromat_thumb.png",
                                "size": "X_LARGE",
                                "widthPixels": 1920,
                                "heightPixels": 1280
                            }]
                        },
                        "runtime": {
                            "runTimeInMilliseconds": 720000,
                            "displayString": "2m30s"
                        },
                        "closedCaption": {
                            "status": "AVAILABLE",
                            "displayString": "CC"
                        },
                        "absoluteViewingPositionMilliseconds": 0,
                        "parentalControl": {
                            "pinControl": "REQUIRED"
                        },
                        "viewingDisplayString": "PurchaseOptions",
                        "reviews": [{
                            "totalReviewCount": 600,
                            "type": "FIVE_STAR",
                            "ratingDisplayString": "7.4"
                        }],
                        "rating": {
                            "category": "G"
                        },
                        "mediaIdentifier": {
                            "id": "tt7993892"
                        }
                    },
                                          {
                        "name": "Tears of Steel",
                        "contentType": "ON_DEMAND",
                        "itemType": "VIDEO",
                        "releaseYear": "2015",
                        "selectionAction": "PLAY",
                        "thumbnailImage": {
                            "contentDescription": "Watch the full Tears of Steel movie",
                            "sources": [{
                                "url": "https:\/\/devportal-reference-docs.s3-us-west-1.amazonaws.com\/video-skills-kit\/tears_of_steel_thumb.png",
                                "size": "X_LARGE",
                                "widthPixels": 1920,
                                "heightPixels": 1280
                            }]
                        },
                        "runtime": {
                            "runTimeInMilliseconds": 720000,
                            "displayString": "2m30s"
                        },
                        "closedCaption": {
                            "status": "AVAILABLE",
                            "displayString": "CC"
                        },
                        "absoluteViewingPositionMilliseconds": 0,
                        "parentalControl": {
                            "pinControl": "REQUIRED"
                        },
                        "viewingDisplayString": "PurchaseOptions",
                        "reviews": [{
                            "totalReviewCount": 987,
                            "type": "FIVE_STAR",
                            "ratingDisplayString": "7.1"
                        }],
                        "rating": {
                            "category": "G"
                        },
                        "mediaIdentifier": {
                            "id": "tt2285752"
                        }
                    }

                ]
            }
        }
    };

    if (name === 'Discover') {
        console.log("Lambda Response: DiscoverResultResponse", JSON.stringify(DiscoverResultResponse));
        context.succeed(DiscoverResultResponse);
    } else if (name === 'GetPlayableItems') {
        console.log("Lambda Response: GetPlayableItemsResponse", JSON.stringify(GetPlayableItemsResponse));
        context.succeed(GetPlayableItemsResponse);
    } else if (name === 'GetPlayableItemsMetadata') {
        console.log("Lambda Response: GetPlayableItemsMetadataResponse", JSON.stringify(GetPlayableItemsMetadataResponse));
        context.succeed(GetPlayableItemsMetadataResponse);
    } else if (name === 'GetDisplayableItems') {
        console.log("Lambda Response: GetDisplayableItemsResponse", JSON.stringify(GetDisplayableItemsResponse));
        context.succeed(GetDisplayableItemsResponse);
    } else if (name === 'GetDisplayableItemsMetadata') {
        console.log("Lambda Response: GetDisplayableItemsMetadataResponse", JSON.stringify(GetDisplayableItemsMetadataResponse));
        context.succeed(GetDisplayableItemsMetadataResponse);
    } else if (name === 'GetNextPage') {
        console.log("Lambda Response: GetNextPageResponse", JSON.stringify(GetNextPageResponse));
        context.succeed(GetNextPageResponse);
    }

};