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)
- Fulfillment
- Intent that calls webhook
- Result when Apache webserver is running
- Result when JS webhook is running
My JS server never receives a post.