[英]How can I account for when the user inputs nothing to Alexa after this.emit(“:ask”, speech)?
[英]Using the Alexa-SDK how can I get this.emit() method to return multiple objects in a JSON array?
我正在嘗試使用 emit() 方法從 JSON 數組中獲取多個帳戶 ID。 發射方法是從 Alexa-SDK 定義的。 問題是它只發出一個值而不是全部。 我怎樣才能讓emit()方法返回一個JSON數組中的兩個對象值?
這是我的代碼片段:
'use strict';
const Alexa = require('alexa-sdk');
const handlers = {
'LaunchRequest': function() {
this.emit(':tell', 'sure');
this.emit('getEmployeeInfoIntent');
},
'getEmployeeInfoIntent': function() {
var empinfoData = {
"employees": [{
"account_id": 8675309
},{
"account_id": 54321
}]
};
for (var i in empinfoData) {
var employeeInfo = empinfoData[i].account_id;
this.emit(':tell', 'The accounts available are id number' + employeeInfo);
//return only 8675309 but I want 8675309 and 54321
};
}
}; ///end of handler
exports.handler = (event, context) => {
const alexa = Alexa.handler(event, context);
alexa.APP_ID = APP_ID;
alexa.registerHandlers(handlers);
alexa.execute();
};
var objtwo = { "employees": [{ "account_id": 8675309 },{ "account_id": 54321 }] } // mythis variable is defined globally var mythis = this; function getJSONArray() { //var reqresponse = this.responseText; //var objtwo = JSON.parse(reqresponse); var empinfoData = objtwo.employees; var allIds = []; for (var i of empinfoData) { var employeeInfo = i["account_id"]; allIds.push(employeeInfo); }; return allIds; }; console.log(getJSONArray());
將 emploeeInfo 保存到一個數組中,並在循環后發出該數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.