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



我使用Lambda函数为我的Alexa技能。对于我的发射意图,我查询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();

但是我被困在如何将QRCode发送回responseBuilder中的Alexa设备上。

我使用的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.

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

在这种情况下,将动态生成的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();
}

就像@kopaka建议的那样,这就是我们要走的路。没有别的办法。

根据文档

这是你需要记住的几件事。

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

在存储选择上,您需要确保能够通过Https提供这些图像,并使用受amazon信任的有效ssl证书。

最新更新