【发布时间】:2021-11-12 18:28:02
【问题描述】:
我正在为我的 Alexa Skill 使用 Lambda 函数。对于我的启动意图,我查询 DynamoDB 并返回我首先要转换为 QRCode 的字符串,然后我想将其作为 responseBuilder 中的图像返回到 Alexa 设备
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();
但我不知道如何将二维码发送回responseBuilder 中的 Alexa 设备。
我正在使用一个名为qrcode 的nodejs 库,它可以将字符串转换为二维码,然后转换为base64。
https://www.npmjs.com/package/qrcode
但根据发送"card" aka image 的 Alexa 文档,它必须是一个 url。
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();
}
【问题讨论】:
-
我什至可能不会将其转换为 base64,而是将其转换为
png,将此图像上传到开放权限的 S3 存储桶(这将使您能够为每个存储的对象)并使用此链接参考图片。请记住,这不是一个真正安全的解决方案,从技术上讲,您所有的二维码都暴露在公共互联网上!但是,根据我对引用文档的理解,图像只能通过 URL 有效,因此这可能是您的用例的一般问题。 -
由于您正在生成 QR 码,您可能会想要使用预签名的 url 来保护 QR 码的内容并防止任何人扫描您在打开 S3 存储桶。所以你的过程是生成二维码,将图像文件上传到 S3,生成预签名的 url,然后将预签名的 url 发送到 Alexa。预签名网址信息:boto3.amazonaws.com/v1/documentation/api/latest/guide/…
标签: node.js amazon-web-services aws-lambda alexa alexa-skill