Dialogflow fulfillment is not working with Mongoose to connect to MongoDB
See original GitHub issueI wrote a basic function that connects to MongoDB using Mongoose, reads documents, and deployed the code in Cloud Functions. It responded correctly with the documents from MongoDB.
Code:
var mongoose = require('mongoose');
var mongoDB = "mongodb://IP:port/db";
mongoose.connect(mongoDB, {
useNewUrlParser: true
});
var db = mongoose.connection;
var Schema = mongoose.Schema;
var myCollection = new Schema({name: String,PO: String},{collections: 'myCollection'});
var myCollectionModel = mongoose.model('myCollection', myCollection, 'myCollection');
exports.helloWorld = (req, res) => {
db.on('error', console.error.bind(console, 'connection error:'));
myCollectionModel.find({name : "Jeeva"}, function(error, PO) {
res.send(PO[0]);
});
};
I wrote the code to accommodate in Dialogflow fulfillment in the following directions: When the intent is called, fetch the data, return it to the user.
Code:
'use strict';
const admin = require('firebase-admin');
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
var mongoose = require('mongoose');
var mongoDB = "mongodb://IP:Port/db";
mongoose.connect(mongoDB, {useNewUrlParser: true});
var db = mongoose.connection;
var db = mongoose.connection;
var Schema = mongoose.Schema;
var myCollection = new Schema({name: String,PO: String},{collections: 'myCollection'});
var myCollectionModel = mongoose.model('myCollection', myCollection, 'myCollection');
process.env.DEBUG = 'dialogflow:debug';
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 getData(name){
var PO_number;
myCollectionModel.find({name : "Jeeva"}, function(error, PO) {
PO_number = PO[0].PO;
});
return PO_number;
}
function pending(agent){
var name = agent.parameters.person;
try{
var PO_number = getData(name);
agent.add(PO_number);
}catch(error){
agent.add(error.toString()); // Error: Unknown response type: "undefined"
}
}
let intentMap = new Map();
intentMap.set('pending-PO',pending);
agent.handleRequest(intentMap);
});
It is not working. Does Dialogflow Fulfillment only support Firestore?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
Dialogflow fulfillment is not working with Mongoose to connect ...
I wrote a basic function that connects to MongoDB using Mongoose, and reads documents. I deployed the code in Cloud Functions. It responded ......
Read more >[Solved]-Mongoose.connect not working-mongodb
Your mongoose.connect call is working fine. If it wasn't then you would definitely have received a PromiseRejection for connection failure and a deprecated ......
Read more >How to make a Webhook for Dialogflow Fulfillment - Medium
We would use Mongo as DB, and for creating the same, go to mLab and sign up for free. After logging in, click...
Read more >Build fulfillment with the Actions on Google Node.js client ...
You can use the client library in conjunction with the Dialogflow ... For example, if you are using Cloud Functions for Firebase, ...
Read more >Integrate the MongoDB API with the Google Dialogflow API
Setup the MongoDB API trigger to run a workflow which integrates with the Google Dialogflow API. Pipedream's integration platform allows you to integrate ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thank you for the information.
Information I have gathered why it did not work and what changes has to be made in code:
I already did this buy i don’t know how proof if it is connected or not