What do i want?
Directly insert data from dialogflows fulfillment into firebase database (requires userId)
i only want to know: Use parameters within triggered intents (e.g. the name of the user). Example: User writes "Hello" (in the app) and chatbot answers "Hello John" like in Googles description
What i've so far:
I've a kind of chat app where the user could chat with other users and/or a chatbot (using dialogflow).
Within firebase cloud functions the app sends a request to dialogflow incl. context with parameter:
function sendToDialogflow(uid) {
const sessionId = '<SESSION_ID>';
const sessionClient = new dialogflow.SessionsClient();
const projectId = '<PROJECT_ID>';
const sessionPath = sessionClient.sessionPath(projectId, sessionId);
const request = {
session: sessionPath,
queryParams: {
contexts: [{
name: `projects/${projectId}/agent/sessions/${sessionId}/contexts/userId`,
lifespanCount: 2,
parameters: {
uid: uid,
}
}]
},
queryInput: {
text: {
text: text,
languageCode: 'en-US',
},
},
};
sessionClient.detectIntent(request).then((response) => {
const result = response[0].queryResult.fulfillmentText;
});
}
The given context does work.
My current solution to insert data into firebase by using promise (in firebase cloud functions) but it seems to be very slow (waiting up to 20 sec for response):
sessionClient.detectIntent(request).then((response) => {
const result = response[0].queryResult.fulfillmentText;
return admin.database().ref('message').push({
fromUid: '<bots id>',
toUid: uid,
text: result
}).catch((error) => {
console.log(error);
});
});