dialogflow / dialogflow-fulfillment-nodejs

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

HandleRequest must contain a map of Dialogflow intent names to function handlers #335

Open Virusnest opened 3 years ago

Virusnest commented 3 years ago

0

I am trying to make a webhook for my chatbot I am working on. I am new to Dialogflow and it's API's This is just a learning project. I am sadly getting this error

(node:618) UnhandledPromiseRejectionWarning: Error: handleRequest must contain a map of Dialogflow intent names to function handlers
    at WebhookClient.handleRequest (/home/runner/thingy/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:307:30)
    at /home/runner/thingy/index.js:25:11
    at Layer.handle [as handle_request] (/home/runner/thingy/node_modules/express/lib/router/layer.js:95:5)
    at next (/home/runner/thingy/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/home/runner/thingy/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/home/runner/thingy/node_modules/express/lib/router/layer.js:95:5)
    at /home/runner/thingy/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/home/runner/thingy/node_modules/express/lib/router/index.js:335:12)
    at next (/home/runner/thingy/node_modules/express/lib/router/index.js:275:10)
    at /home/runner/thingy/node_modules/body-parser/lib/read.js:130:5
(node:618) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:618) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

My code is:

const express = require('express')
const bodyParser = require("body-parser")
const {WebhookClient} = require('dialogflow-fulfillment')
const app = express()
app.use(express.json())
app.get('/', (req, res) => {
    res.send("Server Is Working......")
})

/**
* on this route dialogflow send the webhook request
* For the dialogflow we need POST Route.
* */
app.post('/', (req, res) => {
    // get agent from request
    let agent = new WebhookClient({request: req, response: res})

    // create intentMap for handle intent
    let intentMap = new Map();
    entit

    // add intent map 2nd parameter pass function
    intentMap.set('webhook-demo',handleWebHookIntent)

    // now agent is handle request and pass intent map
    agent.handleRequest(intentMap)
})

function handleWebHookIntent(agent){
    agent.add("Hello I am Webhook demo How are you...")
}

/**
* now listing the server on port number 3000 :)
* */
app.listen(3000, () => {
    console.log("Server is Running on port 3000")
})

Note: Not all my code, just had one tweak Code Source: https://www.kommunicate.io/blog/integrate-dialogflow-nodejs/