actions-on-google / dialogflow-conversation-components-nodejs

Rich Responses sample (using Dialogflow) in Node.js
Apache License 2.0
66 stars 36 forks source link

In pure node + express without firebase #8

Closed maximedotair closed 5 years ago

maximedotair commented 6 years ago

Hello, It is possible to use this script without firebase ? In pure node / express js ?

Fleker commented 6 years ago

Yes it is, as shown in the migration guide:

// v2
const express = require('express');
const bodyParser = require('body-parser');
const { dialogflow } = require('actions-on-google');

const app = dialogflow();

// fulfillment code here

express().use(bodyParser.json(), app).listen(3000);
tagazok commented 6 years ago

What if I want to listen to a post request on a specifig url such as

const assistantApp = dialogflow();
const app = express().use(bodyParser.json(), assistantApp);

app.post('/webhook', (req, res) => this.handleRequest(req, res));

app.listen(5000);

I then want to be able to handle the request myself as I am using a different chatbot sdk. Then, all I want is the raw text to pass it to my own NLU an then send the result back to Dialogflow.

Is that possible?

Canain commented 6 years ago

So the app instance in this scenario is just a regular Express Request Handler.

If you want to host multiple endpoints on a single express server, then you can do something like

const assistantApp = dialogflow();
const app = express().use(bodyParser.json());

app.post('/dialogflow', assistantApp);
// this is the same as app.post('/dialogflow', (req, res) => assistantApp(req, res));

app.post('/webhook', (req, res) => this.handleRequest(req, res));

app.listen(5000);
timpron commented 6 years ago

Hi! Were you able to successfully implement this? I am trying to make an app without firebase as well, but I can't seem to make it work. Tim

basst85 commented 6 years ago

Hi! Were you able to successfully implement this? I am trying to make an app without firebase as well, but I can't seem to make it work. Tim

Yes, my test code:

const express = require('express');
const bodyParser = require('body-parser');
const {dialogflow} = require('actions-on-google');

const server = express();
const assistant = dialogflow();

server.set('port', process.env.PORT || 5000);
server.use(bodyParser.json({type: 'application/json'}));

assistant.intent('helloWorld', conv => {
    let name = conv.parameters.name;
    conv.ask('Hello, welcome ' + name);
});

server.post('/webhook', assistant);

server.listen(server.get('port'), function () {
    console.log('Express server started on port', server.get('port'));
});
ghost commented 6 years ago

Hi, do you know how to do it with Actions SDK? I'm trying but it doesn't work

taycaldwell commented 6 years ago

@rebeca-azevedo The approach would be the same. I've commented on your open issue.

aradwyr commented 5 years ago

Closing due to no direct issue with the sample itself. This is a general question and is better suited for Stack Overflow -- Github issues are for reporting bugs contained in Actions on Google samples or client libraries, thank you for understanding.

farhanroy commented 5 years ago

i ask too

vanpariyar commented 4 years ago

Hi! Were you able to successfully implement this? I am trying to make an app without firebase as well, but I can't seem to make it work. Tim

Yes, my test code:

const express = require('express');
const bodyParser = require('body-parser');
const {dialogflow} = require('actions-on-google');

const server = express();
const assistant = dialogflow();

server.set('port', process.env.PORT || 5000);
server.use(bodyParser.json({type: 'application/json'}));

assistant.intent('helloWorld', conv => {
  let name = conv.parameters.name;
  conv.ask('Hello, welcome ' + name);
});

server.post('/webhook', assistant);

server.listen(server.get('port'), function () {
  console.log('Express server started on port', server.get('port'));
});

Thanks i have implemented this on Glitch platform works fine.