Я пытаюсь создать чат-бота с помощью Dialogflow, который может выполнять поиск в Google и возвращает 5 самых популярных запросов, но у меня возникли проблемы с частью выполнения, поскольку я могу определить, где хранится ссылка для запросов.
Это мой index.js
код:
// See https://github.com/dialogflow/dialogflow-fulfillment-nodejs
// for Dialogflow fulfillment library docs, samples, and to report issues
'use strict';
const axios = require('axios');
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
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));
function welcome(agent) {
agent.add(`Welcome to my agent!`);
}
function fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
function SearchHandler(agent){
const query = agent.parameters.query;
axios.get(`https://www.googleapis.com/customsearch/v1?key=***MY_API_KEY_HERE***&cx=***SEARCH_ENGINE_ID***&q=${query}`)
.then((result) => {
console.log(result.data);
});
agent.add('Intent Called ' + query);
}
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
intentMap.set('search1', SearchHandler);
agent.handleRequest(intentMap);
});
И это мой пакет. 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.13.1",
"firebase-functions": "^2.0.2",
"dialogflow": "^0.6.0",
"dialogflow-fulfillment": "^0.5.0",
"axios": "0.19.2"
}
}
Может кто-нибудь дать мне представление о том, что делать дальше и как извлечь необходимые данные