Cloud Functions Deployment error dialogflow - node.js

I was trying to deploy function in dialogflow but it shows an error.
Code:-
'use strict';
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?`);
}
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
// intentMap.set('your intent name here', yourFunctionHandler);
// intentMap.set('your intent name here', googleAssistantHandler);
agent.handleRequest(intentMap);
});
Error:- Error happened during Cloud Functions Deployment
Can you please tell me how to solve this problem.

I think there is trouble with creating Cloud Functions Environment.
Cloud you please follow these steps below?
Enable Cloud Build API
Go to your project connected your Dialogflow ES in Google Cloud.
( The way is here. Select gear mark next to agent name in Dialogflow console. At "General" tab you can see "GOOGLE PROJECT". Click the Project ID link then you can move to Google Cloud.)
Search "Cloud Build API" at the search bar. Move to Cloud Build API page. "Enable" Cloud Build API.
If the page shows "API Enabled", then this finished.
Redeploy the Cloud Functions.
At Dialogflow Console, redeploy the source.
I hope this works for you.

Related

Dialogflow - a very basic question about fulfilment intent not showing using NodeJS

I have spent one hour searching so I gave up. This question is a little silly.
My intent is to have a specific reply based on parameter received. For example, if a user says “I’m angry because of my boss” then the reply will be “boss is the worst” but if it’s about “wife” then it will say “remember that you promise to love her forever, your mistake”
Anyway, based on my reading I should be using app.intent but I’m not sure how to use it yet
My current question is, this fulfilment is returning empty
const functions = require('firebase-functions');
const {
dialogflow
} = require('actions-on-google');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const app = dialogflow();
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 angerEmotionCapture(agent) {
let conv = agent.conv();
conv.ask('Hello from the Actions on Google client library!');
agent.add(conv);
}
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
intentMap.set('angerEmotionCapture', angerEmotionCapture);
// intentMap.set('your intent name here', googleAssistantHandler);
agent.handleRequest(intentMap);
});

How to get the current location of a user in Dialogflow chatbot?

I am trying to get the user location in Dialogflow, but so far I am not able to get it.
I have found information showing how to get the location in Dialogflow using Google assistance like this article. The thing is that I just want to do it with a chatbot and get the response there. I have tried as well the code below but still not working:
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const {Permission} = require('actions-on-google');
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 requestPermission(agent) {
agent.requestSource = agent.ACTIONS_ON_GOOGLE;
let conv = agent.conv();
console.log('conv '+conv);
conv.ask(new Permission({
context: 'to locate you',
permissions: 'DEVICE_PRECISE_LOCATION',
}));
agent.add(conv); // Please add this
}
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?`);
}
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
intentMap.set('request_permission', requestPermission);
agent.handleRequest(intentMap);
});
I added an intent call "request_permission". I will appreciate any help or recomendation.
There is no general solution in Dialogflow to get the location. Not all systems that work with Dialogflow have a way to transmit location automatically, and others use different means via messages.
The solution for Actions on Google just works with the Google Assistant.

DialogFlow context is always empty in google assistant

I've made a simple chatbot on dialogflow by referencing the dialogflow documentation which is based on Dialogflow's fulfillment library. The bot works good on integration with Google Assistant.
However when I started using context (getting and setting context) in the node.js code, the bot doesn't work on google assistant.
This line agent.context.get('iotcontext'); is null in google assistant but works good in dialogflow test console.
Following is my code:
'use strict';
var https = require ('https');
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 myIntentHandler(agent) {
console.log("Function myIntentHandler Run");
const codeContext=agent.context.get("iotcontext");
agent.add("Date spoken by user: "+codeContext.parameters["date.original"]);
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
// intentMap.set('your intent name here', yourFunctionHandler);
intentMap.set('IoTIntent', myIntentHandler);
agent.handleRequest(intentMap);
});

Google Action Webhook Implementation

so I just started working on a project. I came across two different implementation of webhook for Google action agent. Can someone please explain, what is the difference between both?
Also which one is more extensible.
First one uses actions-on-google library,
'use strict';
// Imports
// =================================================================================================
const { dialogflow } = require('actions-on-google');
const functions = require('firebase-functions');
// Constants
// =================================================================================================
// Instantiate the Dialogflow client with debug logging enabled.
const app = dialogflow({ debug: true });
// Intents
// =================================================================================================
app.intent('welcome.intent', (conv) => {
conv.ask('Hello from webhook');
});
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
and second one uses dialogflow-fulfillment,
`'use strict'`;
const functions = require('firebase-functions');
const { WebhookClient } = 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(`Hello from webhook agent`);
}
let intentMap = new Map();
intentMap.set('welcome.intent', welcome);
agent.handleRequest(intentMap);
});
Both libraries are valid and supported by Google. Which one you use depends on what your goals are.
The actions-on-google library is best if your goal is only to develop Actions. It has support for some of the more advanced functions supported by the AoG platform, but does not support the other platforms that Dialogflow supports.
The dialogflow-fulfillment library is best if you want to support multiple bot platforms using Dialogflow (possibly including the Actions on Google platform).

how to call intent in index js

How to call below intent in js, how to call "Default Welcome Intent" in the index.js file or in any other js files
const functions = require('firebase-functions');
const { dialogflow } = require('actions-on-google');
const app = dialogflow();
app.intent('Default Welcome Intent', conv => {
conv.ask('How are you?');
});
exports.factsAboutGoogle = functions.https.onRequest(app);
Yes, you need to make sure "Enable webhook call for this intent" is turned on for each Intent that you want to process through your webhook fulfillment.

Resources