1

I am attempting to get the silly name maker to work using a webhook hosted on my server. Using PTs-V2 I am able to see the JSON post from Dialogflow.

...{"color":"red","number":6}...

Using Hurl.it I am able to successfully send the post to my server and get the correct response.

{ "speech": "Alright, your silly name is red 6! I hope you like it. See you next time."...

But when I try to use my own server for Dialogflow it does not work. Not sure if there is something I'm missing.

Webhook on server

'use strict';

const https = require('https');
const fs = require('fs');

var privatekey = fs.readFileSync('...');
var certificate = fs.readFileSync('...');
var credentials = {key: privatekey, cert: certificate};

process.env.DEBUG = 'actions-on-google:*';
var DialogflowApp = require('actions-on-google').DialogflowApp;
const express = require('express');
const bodyParser = require('body-parser');

let app = express();
app.use(bodyParser.json({type: 'application/json'}));
var httpsServer = https.createServer(credentials, app);
httpsServer.listen(443);

const NAME_ACTION = 'make_name';
const COLOR_ARGUMENT = 'color';
const NUMBER_ARGUMENT = 'number';

app.get('/', function(req, resp) {
 resp.send("Hello!");
 console.log('app.get');
});

app.post('/', function (request, response){
 console.log('app.post');
 const app = new DialogflowApp({request: request, response: response});

  console.log('Request headers: ' + JSON.stringify(request.headers));
  console.log('Request body: ' + JSON.stringify(request.body));

  // Make a silly name
  function makeName (app) {
    let number = app.getArgument(NUMBER_ARGUMENT);
    let color = app.getArgument(COLOR_ARGUMENT);
    app.tell('Alright, your silly name is ' +
      color + ' ' + number +
      '! I hope you like it. See you next time.');
  }

  let actionMap = new Map();
  actionMap.set(NAME_ACTION, makeName);

  app.handleRequest(actionMap);
});

Thanks for any help.

Edit: Response from Dialogflow when I am running Apache server for website on port

"status": { "code": 206, "errorType": "partial_content", "errorDetails": "Webhook call failed. Error: Failed to parse webhook JSON response: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $.", "webhookTimedOut": false },

Response when the JS server is running on the port and not Apache

"status": { "code": 206, "errorType": "partial_content", "errorDetails": "Webhook call failed. Error: Webhook response was empty.", "webhookTimedOut": false },

Dialogflow Setup (screenshots)

My JS server never receives a post.

Dillon Wiggins
  • 193
  • 1
  • 9
  • By 'does not work' do you mean that no response is returned in the webhook? Does it crash? Are there logs? – Nick Felker Jan 24 '18 at 05:36
  • Looks like the title was edited. The problem is with Dialogflow not posting to my server. I ran my Apache web server on the same port and Dialogflow reports that the incorrect response was received, so I know the SSL is working, but when I run my js server Dialogflow reports that an empty response was received and it never posts to the server. But as mentioned above I checked my server with Hurl.it and everything on my server appears to be working correctly. – Dillon Wiggins Jan 24 '18 at 13:35
  • Are you sure it's configured correctly in the Dialogflow console? Is there any connection to your server? Did you check that, in your intents, you've checked the Use Webhook in the Fulfillment section? – Nick Felker Jan 24 '18 at 20:51
  • Yes, I am assuming it has something to do with the initial connection to my JS server. But I know Dialogflow is working correctly since i checked it with PTs-V2 and was able to see the JSON post. I also know the domain is working since it will give me the incorrect response if my html server is running. I just can't figure out why it is not able to post to my js server. – Dillon Wiggins Jan 24 '18 at 21:51
  • Is there something about your server configuration? Is it https? Is it publicly available? – Nick Felker Jan 24 '18 at 21:56
  • I'm not sure, I added the get to the JS so I can make sure its running using the browser. Right now I have the JS server running and will leave it running for a bit. It's https://dillonwiggins.com. If I post the JSON from Dialog flow into Hurl.it I get the correct response so I know my server is working. I'm just not sure what Dialogflow is doing to connect that is not allowing it to work. – Dillon Wiggins Jan 24 '18 at 22:20
  • Have you checked this box for your intent? **Use Fulfillment**? https://dialogflow.com/docs/getting-started/basic-fulfillment-conversation#enable_fulfillment_in_intent – Nick Felker Jan 24 '18 at 23:02
  • Yes, I am able to get Dialogflow to send the post to PTs-V2 successfully. When I change nothing but the webhook URL to my server it will not work, but I am able to use the same URL for my server to send a post from Hurl.it. – Dillon Wiggins Jan 25 '18 at 00:04
  • What kind of server is it? – Nick Felker Jan 25 '18 at 00:13
  • I am just running a nodejs server on a Beaglebone – Dillon Wiggins Jan 25 '18 at 00:18
  • Have you confirmed that your HTTPS certificate is valid? Dialogflow will not be able to POST to your endpoint if the cert is invalid. – Daniel Situnayake Jan 25 '18 at 22:58
  • Yes my cert is valid, shows up as secure if I use chrome for the get request. – Dillon Wiggins Jan 26 '18 at 00:37

0 Answers0