【问题标题】:Respone.say not working in Promise for Alexa SkillResponse.say 不能在 Promise 中为 Alexa Skill 工作
【发布时间】:2017-06-28 08:07:26
【问题描述】:

我正在使用 nodejs 开发 Alexa Skill。 当我想得到回应时,我在尝试使用 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
    });
});

任何想法如何让它工作?我正在处理节点异步的承诺,以便及时获取我的请求。

【问题讨论】:

    标签: alexa alexa-app


    【解决方案1】:

    您应该使用同步调用来获取请求。这是一个醒目的例子:

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-07-20
        • 1970-01-01
        • 2018-06-23
        • 1970-01-01
        • 2018-01-13
        • 1970-01-01
        • 2022-11-18
        相关资源
        最近更新 更多