回答说没有为Alexa Skill承诺工作

回答说没有为Alexa Skill承诺工作,alexa,alexa-app,Alexa,Alexa App,我正在与nodejs一起学习Alexa技能。 当我想要得到一个响应时,当我试图用response.say(value)获得它时,我不会得到任何消息。但是当尝试使用console.log(value)时,我得到了正确的响应 alexaApp.intent("Plot", { "slots": { "Titel": "String"}, "utterances": ["Wovon handelt {Titel}"] }, function(request, res

我正在与nodejs一起学习Alexa技能。 当我想要得到一个响应时,当我试图用response.say(value)获得它时,我不会得到任何消息。但是当尝试使用console.log(value)时,我得到了正确的响应

alexaApp.intent("Plot", {
    "slots": { "Titel": "String"},
    "utterances": ["Wovon handelt {Titel}"]
},          
function(request, response) {
    var titel = request.slot("Titel");
    geturl(titel,1).then((speech) => {
        console.log(speech); //right string
        response.say(speech); //nothing
    });
});

有什么办法让它工作吗?由于节点异步,我正在使用promises来及时获取请求。

您应该使用同步调用来获取请求。下面是一个令人惊叹的例子:

   var http = require('bluebird').promisifyAll(require('request'), { multiArgs: true });

   app.intent('search', {
    "utterances": [
        "search ",
    ]

  },
  function(request, response) {

    return http.getAsync({ url: url, json: true}).spread(function(statusCodesError, result) {

     console.log(result)

    });


})

您应该使用同步调用来获取请求。下面是一个令人惊叹的例子:

   var http = require('bluebird').promisifyAll(require('request'), { multiArgs: true });

   app.intent('search', {
    "utterances": [
        "search ",
    ]

  },
  function(request, response) {

    return http.getAsync({ url: url, json: true}).spread(function(statusCodesError, result) {

     console.log(result)

    });


})

您确实需要使用异步调用并返回承诺

var http = require('bluebird').promisifyAll(require('request')
   alexaApp.intent("Plot", {
    "slots": { "Titel": "String"},
    "utterances": ["Wovon handelt {Titel}"]
},          
function(request, response) {
    var titel = request.slot("Titel");
    return http.getAsync(titel,1)
         .then((speech) => {
              return response.say(speech); 
         }).catch(function(err){
             return response.say(err);
         });

您确实需要使用异步调用并返回承诺

var http = require('bluebird').promisifyAll(require('request')
   alexaApp.intent("Plot", {
    "slots": { "Titel": "String"},
    "utterances": ["Wovon handelt {Titel}"]
},          
function(request, response) {
    var titel = request.slot("Titel");
    return http.getAsync(titel,1)
         .then((speech) => {
              return response.say(speech); 
         }).catch(function(err){
             return response.say(err);
         });