node.js - 我如何使用 node.js 从商店 firebase 显示图像
问题描述
我尝试通过在 Dialogflow 上使用 Fulfillment(使用 Node.js 的代码)开发聊天机器人并与 Firebase 连接。
我在 Firestore 中存储了一张图片。我想展示那张图片,但我是 Node.js、Firebase 的新手,我不知道。
我已经从 Firestore 阅读了关于上传/下载 URL 的文档,但我仍然不明白它的概念。
你能向我解释一下如何搜索或搜索的措辞吗?
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment =
functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
var httpsReference = storage.refFromURL('https://firebasestorage.googleapis.com/v0/b/jenniebot2-94120.appspot.com/o/images%2FPicture5.jpg?alt=media&token=c853681b-2a72-45e4-ac7a-016f62396fa8');
function bodyMassIndex(agent) {
let weight = 80;
let height = 170/100;
let bmi = (weight / (height * height)).toFixed(2);
let result = "none";
if (bmi < 18.5) {
result = "xs";
} else if (bmi >= 18.5 && bmi <= 22.9) {
result = "s";
} else if (bmi >= 23 && bmi <= 24.9) {
result = "m";
} else if (bmi >= 25 && bmi <= 29.9) {
result = "l";
} else if (bmi > 30) {
result = "xl";
}
return admin.firestore().collection('bmi').doc(result).get()
.then(doc => {agent.add(doc.data().description);});
}
function welcome(agent) {
agent.add(`Welcome to my agent!`);
}
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Bmi', bodyMassIndex);
agent.handleRequest(intentMap);
});
解决方案
这个问题很简单。我只是把它比它应该的更难。只需使用 Firebase Storage 的 URL 并将其放入 LINE API(.JSON) 中。然后使用 dialogflow 进行响应。
{
"type": "image",
"originalContentUrl": "/URL",
"previewImageUrl": "/URL",
"animated": false
}
推荐阅读
- angular - 角 8 | 模板中的动态 keydown 绑定
- c - 如何拆分字符串并将每个字符存储到数组中
- vb.net - 如何防止用户输入小于 vb.net 文本框中的最大长度
- regex - 句子的正则表达式,但忽略了网站
- tensorflow - 为什么我们需要 tf.convert_to_tensor?
- xcode - 在 OS X mojave 上安装 Haskell 时出现“macOS_SDK_headers_for_macOS_10.14.pkg 与此版本的 macOS 不兼容”
- python-3.x - 我可以在没有安装的情况下使用 python 包吗?
- laravel - 渲染与使用紧凑的刀片中的急切加载数据有很多关系会出错
- javascript - 如何检查设备时间是否设置正确?
- python-3.x - 如何在 Python 3 中重新采样 Datafame 后对卷的值求和