Я пытаюсь добавить In Skill Shopping к своему навыку Alexa со следующим кодом:
const LaunchRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === "LaunchRequest";
},
handle(handlerInput){
console.log("In LaunchRequest");
const locale = handlerInput.requestEnvelope.request.locale;
const ms = handlerInput.serviceClientFactory.getMonetizationServiceClient();
return ms.getInSkillProducts(locale).then(function(result) {
// Code to handle result.inSkillProducts goes here
const totalProducts = result.inSkillProducts.length;
const purchasableProducts = result.inSkillProducts.filter(record => record.purchasable == 'PURCHASABLE');
const entitledProducts = result.inSkillProducts.filter(record => record.entitled == 'ENTITLED');
return handlerInput.responseBuilder
.speak('Found total ' + result.inSkillProducts.length + ' products of which ' + purchasableProducts.length + ' are purchasable and ' + entitledProducts.length + ' are entitled.')
.getResponse();
});
},
};
Когда я запускаю код, я получаю следующее сообщение об ошибке:
Response:
{
"errorMessage": "Cannot read property 'getMonetizationServiceClient' of undefined",
"errorType": "TypeError",
"stackTrace": [
"Object.handle (/var/task/index.js:16:50)",
"GenericHandlerAdapter.<anonymous> (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/request/handler/GenericHandlerAdapter.js:63:47)",
"step (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/request/handler/GenericHandlerAdapter.js:44:23)",
"Object.next (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/request/handler/GenericHandlerAdapter.js:25:53)",
"/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/request/handler/GenericHandlerAdapter.js:19:71",
"new Promise (<anonymous>)",
"__awaiter (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/request/handler/GenericHandlerAdapter.js:15:12)",
"GenericHandlerAdapter.execute (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/request/handler/GenericHandlerAdapter.js:61:16)",
"GenericRequestDispatcher.<anonymous> (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/GenericRequestDispatcher.js:173:58)",
"step (/var/task/node_modules/ask-sdk-runtime/dist/dispatcher/GenericRequestDispatcher.js:44:23)"
]
}
Я использовал код с сайта Alexa SDK, который можно найти здесь: https://ask -sdk-for-nodejs.readthedocs.io / en / latest / Calling-Alexa-Service-APIs.html # getinskillproducts .Может кто-нибудь сказать мне, пожалуйста, что идет не так или как я могу это исправить?Заранее спасибо.