我目前正在研究 Alexa Skill,以从 SAP 系统收集数据。由于我的函数中有一个用于收集数据的回调,因此 Alexa 在 talkOutput 变量更新之前会说话。
const LagerhueteIntent = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' &&
Alexa.getIntentName(handlerInput.requestEnvelope) === 'LagerhueteIntent';
},
handle(handlerInput) {
let speakOutput;
console.log("test");
findWarehouseKeepers(function(warehouseKeeper) {
console.log(warehouseKeeper);
speakOutput = "Die Lagerhüter sind die Produkte mit den Ids" + warehouseKeeper;
console.log(speakOutput);
});
return handlerInput.responseBuilder
.speak(speakOutput)
//.reprompt('add a reprompt if you want to keep the session open for the user to respond')
.getResponse();
}
};
用我的功能:
function findWarehouseKeepers(callback) {
var args = getArgs();
console.log(args);
var Client = require('node-rest-client').Client;
var client = new Client();
client.get("http://XXXXXXXX$format=json", args, function(data, response) {
let validValuesList = new List([]);
data.d.results.forEach(function(data) {
validValuesList.add(data.ProductId);
});
console.log(validValuesList);
let validValuesAsArray = validValuesList.toArray();
console.log(validValuesAsArray);
callback(validValuesAsArray);
});
}
如何使我的函数同步,以便在执行下一个代码之前更新 talkOutput 变量?提前致谢。
HUWWW
相关分类