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

Can't initialise WebhookClient in AWS Lambda #60

Open drishit96 opened 6 years ago

drishit96 commented 6 years ago

According to the docs, the WebhookClient constructor needs Express HTTP request and response objects. However, in Lambda function, I receive only the event (the request). How do I create the Express request and response objects?

I have tried this so far:

const {WebhookClient} = require('dialogflow-fulfillment');

exports.dialogflowFulfillment = async (event) => {
  let response = {};
  const agent = new WebhookClient({ event, response });

  function sayNiceThings(agent) {
    agent.add(`Nice to meet you!`);
  }

  let intentMap = new Map();
  intentMap.set('Say Nice Things', sayNiceThings);
  agent.handleRequest(intentMap);
};
scolinas commented 6 years ago

Hi, I'm facing the same issue, do you plan to add a Constructor to use for example in aws Lambda?

michaelachmann commented 6 years ago

I used this tutorial to get an idea how to deploy a dialogflow-fulfillment on lambda: Developing for the Google Assistant using Typescript and Amazon Web Services.

The idea is to use the serverless framework for running express.js on lambda. The express.js request and response can then be passed to dialogflow-fulfillment

samko635 commented 6 years ago

I'm having the same problem. Has anybody find a good solid solution without having to use TypeScript?

biranchi2018 commented 5 years ago

Try https://www.jovo.tech/tutorials/host-google-action-on-lambda

LucasRaza commented 5 years ago

To 2nd Samkos question, has anybody found a good solution without using typescript? I know you have to run express.js on Lambda to get the req and res parameters in order to pass those into your dialogflow agent’s parameters. Is there any example of how this can be done?

LinhIThust commented 4 years ago

express().use(bodyParser.json(), app).listen(8000);