Alexa - 如何将图像发送给用户?

DIR*_*AVE 8 amazon-web-services node.js aws-lambda alexa-skills-kit

我正在为我的 Alexa Skill 使用 Lambda 函数。对于我的启动意图,我查询 DynamoDB 并返回一个字符串,我首先想要将其转换为 QRCode,然后我想将其作为图像内的图像返回到 Alexa 设备。responseBuilder

Alexa 可以很好地显示来自外部 url 的图像,例如

const rabbitImage = "https://i.imgur.com/U6eF0oH.jpeg";

return responseBuilder
        .speak(say)
        .withStandardCard("Welcome to Alexa", "description", rabbitImage, rabbitImage)
        .reprompt('try again, ' + say)
        .getResponse();
Run Code Online (Sandbox Code Playgroud)

但我陷入了如何将 QRCode 发送回 Alexa 设备的问题responseBuilder

我正在使用一个nodejs名为 的库qrcode,它可以将字符串转换为 QRCode,然后转换为base64.

https://www.npmjs.com/package/qrcode

但根据 Alexa 文档,"card" aka image向用户发送 , 时它必须是一个 url。

https://developer.amazon.com/en-US/docs/alexa/custom-skills/include-a-card-in-your-skills-response.html

The Alexa Skills Kit provides different types of cards:

A Standard card also displays plain text, but can include an image. You provide the text for the title and content, and the URL for the image to display.
Run Code Online (Sandbox Code Playgroud)

所以我不确定库base64生成的qrcode在这种情况下是否有效。

在这种情况下,将动态生成的 QRCode 作为响应发送回 Alexa 设备的最佳方式是什么?

const LaunchRequest_Handler = {
    canHandle(handlerInput) {
      const request = handlerInput.requestEnvelope.request;
      return request.type === 'LaunchRequest';
    },
    handle(handlerInput) {
      const responseBuilder = handlerInput.responseBuilder;


      //Perform query to DynamoDB

      var stringToCreateQRWith = "8306e21d-0c9e-4465-91e9-0cf86fca110d";

      //Generate qr code and send back to user here
      //???Unsure how to do and what format to send it in
      var qrImageToSendToUser = ???

      return responseBuilder
        .speak(say)
        .withStandardCard("Welcome to Alexa", "description", qrImageToSendToUser , qrImageToSendToUser )
        .reprompt('try again, ' + say)
        .getResponse();

    }

Run Code Online (Sandbox Code Playgroud)

Pau*_*ulo 0

正如@kopaka 提议的,这就是要走的路。没有其他办法了。

根据文档

它们是您需要牢记的一些事情。

在图像本身上,您需要使用720px x 480px和创建 2 个图像1200px x 800px创建 2 个图像。确保它们在多种屏幕尺寸上都能很好地显示。否则,他们不能保证为您的用户提供最佳体验,因为他们可能会放大/缩小图像以适应。

在存储选择上,您需要确保能够通过亚马逊Https信任的有效 ssl 证书来提供这些图像。