2017-06-27 9 views
0

私はnodejsでAlexaスキルに取り組んでいます。 私はレスポンスを取得したいときに、response.say(value)でそれを取得しようとするときに何のメッセージも得られません。しかし、console.log(値)で試してみると、私は正しい応答を得ます。Respone.sayはAlexaスキルを約束していません

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 
    }); 
}); 

どのように動作させるにはどうすればよいですか?私は時間の中で私の要求を得るノードの非同期の原因を約束で働いています。

答えて

0

取得するには同期呼び出しを使用する必要があります。ここではウォーキングの例を示します。

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) 

    }); 


}) 
0

非同期呼び出しを使用して約束を返す必要があります。

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); 
     }); 
関連する問題