Я пытался настроить локальное тестовое окружение для моих функций Dialogflow Firebase для локального тестирования, и у меня возникли некоторые проблемы. Я запускаю скрипт npm start
, который запускает:
"scripts": {
"start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
"deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
},
Я запускаю Почтальон и нажимаю на ссылку localhost, которую мне дали в терминале: POST http://localhost:5000/visa-requirements/us-central1/dialogflowFirebaseFulfillment
с полезной нагрузкой в виде:
{
"responseId": "2f9811cd-7b7f-4bc9-9b79-b17d1fda8552-b4ef8d5f",
"queryResult": {
"queryText": "india",
"action": "searchVisas",
"parameters": {
"passport-country": [
"Australia"
],
"visa-country": [
"India"
]
},
"allRequiredParamsPresent": true,
"outputContexts": [
{
"name": "projects/visa-requirements/agent/sessions/56afbb1a-dd84-ca0a-b3b8-249915ddc144/contexts/__system_counters__",
"parameters": {
"no-input": 0,
"no-match": 0,
"passport-country": [
"Australia"
],
"passport-country.original": [
"australian"
],
"visa-country": [
"India"
],
"visa-country.original": [
"india"
]
}
}
],
"intent": {
"name": "projects/visa-requirements/agent/intents/adedfeb3-c729-4aed-8525-3fea7ee344c9",
"displayName": "Visa Search Request",
"endInteraction": true
},
"intentDetectionConfidence": 1,
"languageCode": "en"
},
"originalDetectIntentRequest": {
"payload": {}
},
"session": "projects/visa-requirements/agent/sessions/56afbb1a-dd84-ca0a-b3b8-249915ddc144"
}
Мой код:
// See https://github.com/dialogflow/dialogflow-fulfillment-nodejs
// for Dialogflow fulfillment library docs, samples, and to report issues
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const serviceAccount = require("./config/sdjfkhjkghfjkdhgjkfhd.json");
process.env.DEBUG = 'dialogflow:*';
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://jfhjkfdhfjjfhkfdjg.firebaseio.com"
});
const db = admin.firestore();
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
function findVisa(agent) {
const requirements = db.collection('requirements').doc('india').get();
requirements.then(doc => {
let data = doc.data();
agent.add('Here are the visas for ' + data.name);
})
}
function fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('Visa Search Request', findVisa);
intentMap.set('Default Fallback Intent', fallback);
// intentMap.set('your intent name here', googleAssistantHandler);
agent.handleRequest(intentMap);
});
Из этого я получаю эту ошибку в Почтальоне:
Error: Invalid or unknown request type (not a Dialogflow v1 or v2 webhook request).
at new WebhookClient
(/Users/corymayfield/Sites/visaRequirementsFulfillment/firebase/functions/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:232:13)
at /Users/corymayfield/Sites/visaRequirementsFulfillment/firebase/functions/index.js:23:17
at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:621:20
at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:596:19
at Generator.next (<anonymous>)
at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:7:71
at new Promise (<anonymous>)
at __awaiter (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:3:12)
at runFunction (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:593:12)
at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:620:15