【问题标题】:Alexa giving me [Object Products] whenever I am trying to get quote of the day每当我试图获得当天的报价时,Alexa都会给我[对象产品]
【发布时间】:2018-03-19 11:25:37
【问题描述】:

每当我尝试使用 kote-api 获取当天的报价时,Alexa 都会给我 [Object Products]。有没有办法解决这个问题?

这是我的代码:

'use strict';
const Alexa = require('alexa-sdk');
const APP_ID = undefined;
const skill_name = "Quote of the Day";
const kote = require('kote-api');

exports.handler = function(event, context, callback) {
   var alexa = Alexa.handler(event, context);
   alexa.appId = APP_ID;
   alexa.registerHandlers(handlers);
   alexa.execute();
}; 

var handlers =
{
 'LaunchRequest': function ()
{
  this.emit('QuoteOfDay');
},
'QuoteOfDay': function ()
{
 var quoteDay = kote.goodReads().then(quote => {
 this.emit(quote);
});
 this.emit(':tellWithCard', quoteDay);
  }
};

这是我的日志输出:

{
 "version": "1.0",
 "response": {
 "shouldEndSession": true,
 "outputSpeech": {
   "type": "SSML",
  "ssml": "<speak> [object Promise] </speak>"
 }
},
"sessionAttributes": {}
}

【问题讨论】:

    标签: node.js lambda aws-lambda alexa-skills-kit


    【解决方案1】:

    您应该在将对象发送回之前将其解析为 JSON,如下所示,

    this.emit(JSON.parse(quote));
    

    【讨论】:

    • 您是否在所有意图中都添加了 JSON.parse?
    • 我所有的意图是什么意思,“QuoteOfDay”是我唯一的意图
    • 好的。我以为你只分享了部分代码。只是为了确保这是延迟执行的问题,您能否从“QuoteOfDay”意图发出硬编码?我的意思是,this.emit("Hello Quote");
    猜你喜欢
    • 2022-09-28
    • 1970-01-01
    • 2021-09-15
    • 2018-06-15
    • 2022-07-20
    • 2021-12-29
    • 1970-01-01
    • 2014-02-25
    • 2021-10-17
    相关资源
    最近更新 更多