dialogflow / dialogflow-fulfillment-nodejs

Dialogflow agent fulfillment library supporting v1&v2, 8 platforms, and text, card, image, suggestion, custom responses
Apache License 2.0
597 stars 282 forks source link

Error: No responses defined for platform: DIALOGFLOW_CONSOLE #322

Open DMani009 opened 3 years ago

DMani009 commented 3 years ago

Hi All,

I am trying to read data from an API in Dialogflow. Below is the code but I am getting the following error and it looks like I have defined my responses in agent.add but still getting the following error. I am not a java expert but trying to learn and maybe I am doing some syntax error. I am not sure but I would appreciate your time and help. Following are errors i am getting:

Error: No responses defined for platform: DIALOGFLOW_CONSOLE
at WebhookClient.send_ (/workspace/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:488:13)
    at promise.then (/workspace/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:306:38)
    at process._tickCallback (internal/process/next_tick.js:68:7)

textPayload: "Error: No responses defined for platform: DIALOGFLOW_CONSOLE
    at WebhookClient.send_ (/workspace/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:488:13)
    at promise.then (/workspace/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:306:38)
    at process._tickCallback (internal/process/next_tick.js:68:7)"
insertId: "000000-1fd08a04-56f8-4c82-b000-360724f95c3a"
resource: {2}
timestamp: "2020-10-21T19:07:49.495Z"
severity: "ERROR"
labels: {1}
logName: "projects/testbigquery-edjv/logs/cloudfunctions.googleapis.com%2Fcloud-functions"
trace: "projects/testbigquery-edjv/traces/e8c0d32bfe9e582267667f01e30c1141"
receiveTimestamp: "2020-10-21T19:07:49.683046180Z"

Function execution took 1294 ms, finished with status: 'crash'
textPayload: "Function execution took 1294 ms, finished with status: 'crash'"
insertId: "000000-0840e9bd-0a4b-4ee3-bf4d-9a1e451a2c0f"
resource: {2}
timestamp: "2020-10-21T19:07:49.497111804Z"
severity: "DEBUG"
labels: {1}
logName: "projects/testbigquery-edjv/logs/cloudfunctions.googleapis.com%2Fcloud-functions"
trace: "projects/testbigquery-edjv/traces/e8c0d32bfe9e582267667f01e30c1141"
receiveTimestamp: "2020-10-21T19:07:49.683046180Z"

My code is below: // 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 {WebhookClient} = require('dialogflow-fulfillment'); const {Card, Suggestion} = require('dialogflow-fulfillment'); const axios = require('axios');

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 getSpreadsheetData(){ return axios.get('https://sheetdb.io/api/v1/y79vpk8pj29cv'); }

function welcome(agent) { const city =agent.parameters.city; return getSpreadsheetData().then(res => { res.data.map(person => { if(person.City === city) agent.add(Here are the details for ${"city"}.CollectionC: ${person.CollectionC}, Address: ${person.Address}, Phone: ${person.Phone}); }); });
}

function fallback(agent) { agent.add(I didn't understand); agent.add(I'm sorry, can you try again?); }

// // Uncomment and edit to make your own intent handler // // uncomment intentMap.set('your intent name here', yourFunctionHandler); // // below to get this function to be run when a Dialogflow intent is matched // function yourFunctionHandler(agent) { // agent.add(This message is from Dialogflow's Cloud Functions for Firebase editor!); // agent.add(new Card({ // title: Title: this is a card title, // imageUrl: 'https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png', // text: This is the body text of a card. You can even use line\n breaks and emoji! 💁, // buttonText: 'This is a button', // buttonUrl: 'https://assistant.google.com/' // }) // ); // agent.add(new Suggestion(Quick Reply)); // agent.add(new Suggestion(Suggestion)); // agent.setContext({ name: 'weather', lifespan: 2, parameters: { city: 'Rome' }}); // }

// // Uncomment and edit to make your own Google Assistant intent handler // // uncomment intentMap.set('your intent name here', googleAssistantHandler); // // below to get this function to be run when a Dialogflow intent is matched // function googleAssistantHandler(agent) { // let conv = agent.conv(); // Get Actions on Google library conv instance // conv.ask('Hello from the Actions on Google client library!') // Use Actions on Google library // agent.add(conv); // Add Actions on Google library responses to your agent's response // } // // See https://github.com/dialogflow/fulfillment-actions-library-nodejs // // for a complete Dialogflow fulfillment library Actions on Google client library v2 integration sample

// 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('your intent name here', googleAssistantHandler); agent.handleRequest(intentMap); });

oneict commented 3 years ago

In my case I had to return an agent. if(person.City === city) return agent.add(Here are the details for ${"city"}.CollectionC: ${person.CollectionC}, Address: ${person.Address}, Phone: ${person.Phone});

Also make sure your Google Development account is activated with billing information. In trial mode remote call's are not allowed. You can check the result in the Diagnostic info.

"webhookStatus": { "message": "Webhook execution successful" }

If an error is shown chances are your account is not acitvated. This took me a couple of days myself, billing information was defined but account was still in trial model, once activated the error No responses defined for platform: DIALOGFLOW_CONSOLE was gone!

gjvanouwendorp commented 2 years ago

I was struggling with this error for hours, only to find out I needed to change these 2 little things:

jandersonclemente commented 1 year ago

I was struggling with this error for hours, only to find out I needed to change these 2 little things:

  • in package.json, change the version of "dialogflow-fulfillment" to "0.6.1" (instead of 0.5.0)
  • make sure your intent has at least 1 default response in the bottom section of the intent configuration screen (Dialogflow ES)

Thanks A LOT!

abuelgasimsaadeldin commented 1 year ago

Hi guys! I'm new to nodejs and dialogflow and am getting this exact same error when trying to integrate my GPT-J from banana with Dialogflow, below is my codes and I would really appreciate any help 🙏🙏

const express = require("express");
require("actions-on-google")
require('dotenv').config();
const axios = require('axios');
const { WebhookClient } = require("dialogflow-fulfillment");
const app = express();
const fetch = require('node-fetch');
const banana = require('@banana-dev/banana-dev');

app.get('/', (req,res) => {
    res.send('Welcome to Dialogflow-GPTJ2 Application!!');
  })

app.post("/dialogflow", express.json(), (req, res) => {
const agent = new WebhookClient({ request: req, response: res });
let intentMap = new Map();
intentMap.set("Default Welcome Intent", welcome);
intentMap.set("Default Fallback Intent", defaultFallback);
agent.handleRequest(intentMap);

function welcome(agent) {
    agent.add('Hi, I am Debra! I am your virtual personal assistant from Orient Telecoms. How are you doing today?');
}

async function defaultFallback(agent) {
    let query = agent.query;
    console.log('querytext: ', query)
    var modelKey = "gptj"

    const modelParameters = {
        "text":query,
        "length":50,
        "temperature":0.9,
        "batchSize": 1
    }

    try {
        let run = async (modelParameters) => {
            var botResponse = await banana.run(process.env.apiKey, modelKey, modelParameters)

            console.log('botResponse: ', botResponse)
            agent.add(botResponse)
        }
    } catch (err) {
        console.log('This is error:', err);
        agent.add('Sorry. Something went wrong. Can you say that again?');
    }
}
});

const port = 3000;
app.listen(port, () => console.log(`App listening on port ${port}!`))
clin366 commented 1 year ago

When I tried to use Dialogflow to update google Sheets using Axios. I met the same error, but an expert helps me fix the issue via the following code: `'use strict';

const functions = require('firebase-functions'); const {WebhookClient} = require('dialogflow-fulfillment'); const {Card, Suggestion} = require('dialogflow-fulfillment'); const axios = require('axios'); // const qs = require('qs');

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); }

function fallback(agent) { agent.add(I didn't understand); agent.add(I'm sorry, can you try again?); }

function bookkeepingHandler(agent) { axios.post(https://sheetdb.io/api/v1/htvjf0t8az3f8?sheet=Entries, {"data": { "EntryType":agent.parameters.entrytype, "Date":agent.parameters.date, "Amount":agent.parameters.amount } }); agent.add(Thank you! Check the google sheet for the data recorded.); } //data,{header: {'x-api-key': 'eRjwrg6ya88d1i@z#91cb01rz%u$6cxU5FOf#3LG#P%8$#JZwlj9aawgHhabpYGT'}} // 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('bookkeepEntry', bookkeepingHandler); //intentMap.set('bookNow', bookkeepingHandler); // intentMap.set('your intent name here', googleAssistantHandler); agent.handleRequest(intentMap); });`

clin366 commented 1 year ago

Pay attention to the code here (` symbol is very important): axios.post(https://sheetdb.io/api/v1/htvjf0t8az3f8?sheet=Entries`, {"data": { "EntryType":agent.parameters.entrytype, "Date":agent.parameters.date, "Amount":agent.parameters.amount } });