- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在 Dialogflow 上构建一个机器人,并且正在使用 Dialogflow-fulfillment。但是,每当我部署时,我都会收到错误:
Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail
我正在尝试从代码访问外部 API。这是正确的做法吗?或者是由于其他原因导致的错误?
附注:我是 Dialogflow 的新手。
这是index.js 文件:
'use strict';
const functions = require('firebase-functions');
const request = require('request');
const admin = require('firebase-admin');
admin.initializeApp();
const {dialogflow} = require('actions-on-google');
const app =dialogflow();
function helper() {
var username = '<USER_NAME>',
password = '<PASSWORD>',
sugar_id = '<SUGAR_ID>',
from_date = '2019-06-10',
to_date = '2019-06-11',
url1 = '<SOME_URL_HERE>',
auth = "Basic " + new Buffer.from(username + ":" + password).toString("base64");
return new Promise((resolve, reject)=> {
request(
{
url : url1,
headers : {
"Authorization" : auth,
'x-api-key': '<API_KEY>',
'x-source': '<X_SOURCE>'
}
},
(error, response, body) => {
if(error) throw error;
console.log('success 1');
// console.log(JSON.parse(response.body));
var obj = JSON.parse(body);
if(obj.data!==null) {
// console.log(obj.data[0].booking_id);
var latest_booking_id = obj.data[0].booking_id;
var url2 = '<SOME_URL_HERE>';
request(
{
url: url2,
headers : {
"Authorization" : auth,
'x-api-key': '<API_KEY>',
'x-source': '<X_SOURCE>'
}
},
(error, response, body) => {
if(error) throw error;
console.log('success 2');
var obj = JSON.parse(body);
if(error) reject(error);
console.log(obj);
resolve(obj);
}
);
} else {
console.log('No booking found.');
}
}
);
});
}
app.intent('customer details', (conv) => {
helper().then((res)=> {
conv.ask(res);
}).catch((err)=> {
throw (err);
});
});
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
Package.json 文件
{
"name": "dialogflowFirebaseFulfillment",
"description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
"engines": {
"node": "8"
},
"scripts": {
"start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
"deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
},
"dependencies": {
"actions-on-google": "^2.2.0",
"firebase-admin": "^5.9.1",
"firebase-functions": "^2.0.2",
"request": "^2.88.0"
}
}
最佳答案
这个问题可能有帮助:Making an HTTP POST request from fulfillment in Dialogflow 。引用囚徒的回答:
The easiest way to use promises with network calls is to use a package such as request-promise-native. Using this, your code might look something like:
var options = {
uri: url,
method: 'POST',
json: true,
headers: { ... }
};
return rp(options)
.then( body => {
var val = body.someParameter;
var msg = `The value is ${val}`;
agent.add( msg );
});
我注意到您需要 actions-on-google
库。如果您正在为 Google Assistant 构建操作,请查看 Google's codelabs Actions on Google 客户端库可能会有所帮助。
关于dialogflow-es - 警告,根据 GCLOUD_PROJECT 估计 Firebase 配置。初始化 firebase-admin 可能会失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56575077/
java.lang.Throwable 的哪些子类可能被空语句抛出? 通过短语“空语句”,我指的是“无”、“分号”和“分号”: // .... A(); B(); C(); try { //
我是一名优秀的程序员,十分优秀!