如何使用亚马逊回声显示技能显示图表



圣诞节我有一个回声秀。现在我想尝试一下如何自定义它。我创建了几个传感器,它们的度量存储在AWS DynamoDB中。现在我想知道我有什么可能性来显示由这些数据创建的图表。是否可以直接使用Alexa演示语言(APL(显示图表?是否可以将iframes包括在APL中?我没有找到太多关于这个话题的信息。也许你可以给我指一个正确的方向。

提前感谢

不确定这是否是您想要的,但您可以生成SVG图形并使用APL VectorGraphic基元渲染这些图形。

您必须构建一种自定义技能,当调用该技能时,可以提取度量的数据,并生成APL来渲染图形。

或者,如果对于可以光栅化的度量有不同的服务器端渲染API,则可以生成PNG并在"回声秀"上渲染。

为了参考,我将向代码展示一个nodejs函数,它可以导航到URL:

const MetricsChoiceIntentHandler = {
canHandle(handlerInput) {
return Alexa.getIntentName(handlerInput.requestEnvelope) === 'MetricsChoiceIntent';
},
handle(handlerInput) {
const choice = handlerInput.requestEnvelope.request.intent.slots.choice.value;
const speakOutput = `Alles klar. Auf zu ${choice}`;
console.log("Deine Wahl: "+choice);

if (Alexa.getSupportedInterfaces(handlerInput.requestEnvelope)['Alexa.Presentation.APL']) {
handlerInput.responseBuilder.addDirective({
type: 'Alexa.Presentation.APL.RenderDocument',
document: launchDocument,
token: 'jip'
});

var urlToGo="";
switch(choice){
case "gaswarner":
urlToGo="https://www.url1.com";
break;
case "temperatur":
urlToGo="https://www.url2.com"
break;
}

handlerInput.responseBuilder.addDirective({
type: "Alexa.Presentation.APL.ExecuteCommands",
token: 'jip',
commands: [{
type: "OpenURL",
source: urlToGo
}]
});
}  
return handlerInput.responseBuilder
.speak(speakOutput)
.getResponse();
}
};

有两件重要的事情需要提及:

  1. 您必须使用文档进行响应才能导航到URL。这也可以是空白的伪APL文档
  2. 如果你想导航到一个URL,你必须在文档和命令指令上设置令牌(可以是你喜欢的任何东西(

最新更新