Dialogflow履行的NodeJS没有火力
我想建立使用和的NodeJS不使用火力点我的网络挂接。我发现了一个资源,建立了我的index.js文件是这样的:
const express = require('express');
const bodyParser = require('body-parser');
const {
dialogflow
} = require('actions-on-google');
const PORT = process.env.PORT || 5000;
const app = dialogflow({
debug: true
});
const server = express()
.use(bodyParser.urlencoded({
extended: true
}))
.use(bodyParser.json(), app)
.listen(PORT, () => console.log(`Listening on ${ PORT }`));
// Handle the Dialogflow intent named 'Default Welcome Intent'.
app.intent('Default Welcome Intent', (conv) => {
const name = conv.user.storage.userName;
if (!name) {
// Asks the user's permission to know their name, for personalization.
conv.ask(new Permission({
context: 'Hi there, to get to know you better',
permissions: 'NAME',
}));
} else {
conv.ask(`Hi again, ${name}. What are you looking for?`);
}
});
// Handle the Dialogflow intent named 'actions_intent_PERMISSION'. If user
// agreed to PERMISSION prompt, then boolean value 'permissionGranted' is true.
app.intent('actions_intent_PERMISSION', (conv, params, permissionGranted) => {
if (!permissionGranted) {
// If the user denied our request, go ahead with the conversation.
conv.ask(`OK, no worries. What are you looking for?`);
conv.ask(new Suggestions('Blue', 'Red', 'Green'));
} else {
// If the user accepted our request, store their name in
// the 'conv.user.storage' object for future conversations.
conv.user.storage.userName = conv.user.name.display;
conv.ask(`Thanks, ${conv.user.storage.userName}. ` +
`What are you looking for?`);
conv.ask(new Suggestions('Blue', 'Red', 'Green'));
}
});
// Handle the Dialogflow NO_INPUT intent.
// Triggered when the user doesn't provide input to the Action
app.intent('actions_intent_NO_INPUT', (conv) => {
// Use the number of reprompts to vary response
const repromptCount = parseInt(conv.arguments.get('REPROMPT_COUNT'));
if (repromptCount === 0) {
conv.ask('Which color would you like to hear about?');
} else if (repromptCount === 1) {
conv.ask(`Please say the name of a color.`);
} else if (conv.arguments.get('IS_FINAL_REPROMPT')) {
conv.close(`Sorry we're having trouble. Let's ` +
`try this again later. Goodbye.`);
}
});
module.exports = server;
我的应用程序的NodeJS只是由index.js和的package.json的。我做了一个npm install
,然后将两个文件,node_modules通过FTP到我的蔚蓝的Web应用程序。当我测试了我的谷歌应用程序的行动,它得到一个网络挂接错误,因为它无法沟通。
谁能告诉我什么,我需要做的就是它的工作?
PS:这是我的package.json:
{
"name": "pyb-actions",
"description": "Actions on Google for PYB",
"author": "r3plica",
"private": true,
"scripts": {
"lint": "eslint .",
"start": "npm run shell"
},
"dependencies": {
"actions-on-google": "^2.0.0",
"express": "^4.16.4",
"i18n": "^0.8.3"
},
"devDependencies": {
"eslint": "^4.19.0",
"eslint-config-google": "^0.9.1"
}
}
回答如下:
尝试创建一个简单的GET路由,以测试该问题是否与您的服务器安装或您初始化应用程序的方式。
app.get('/', function(request,response) {
response.json({
"response": "The server is runnning"
});
});
或者,尝试通过ngrok转发本地主机和使用,作为临时履行网络挂接。
这里是我的index.js灵感:
const express = require('express');
const bodyParser = require('body-parser')
const { dialogflow } = require('actions-on-google')
const intents = require('./intents')
const expressApp = express().use(bodyParser.json())
const app = dialogflow()
app.intent('Welcome', intents.welcome)
expressApp.post('/fulfill', (req, resp) => app)
expressApp.listen(process.env.PORT || 3000, '0.0.0.0', () => {
console.log("server starting " + (process.env.PORT || 3000));
})
希望能帮助到你
Dialogflow履行的NodeJS没有火力
我想建立使用和的NodeJS不使用火力点我的网络挂接。我发现了一个资源,建立了我的index.js文件是这样的:
const express = require('express');
const bodyParser = require('body-parser');
const {
dialogflow
} = require('actions-on-google');
const PORT = process.env.PORT || 5000;
const app = dialogflow({
debug: true
});
const server = express()
.use(bodyParser.urlencoded({
extended: true
}))
.use(bodyParser.json(), app)
.listen(PORT, () => console.log(`Listening on ${ PORT }`));
// Handle the Dialogflow intent named 'Default Welcome Intent'.
app.intent('Default Welcome Intent', (conv) => {
const name = conv.user.storage.userName;
if (!name) {
// Asks the user's permission to know their name, for personalization.
conv.ask(new Permission({
context: 'Hi there, to get to know you better',
permissions: 'NAME',
}));
} else {
conv.ask(`Hi again, ${name}. What are you looking for?`);
}
});
// Handle the Dialogflow intent named 'actions_intent_PERMISSION'. If user
// agreed to PERMISSION prompt, then boolean value 'permissionGranted' is true.
app.intent('actions_intent_PERMISSION', (conv, params, permissionGranted) => {
if (!permissionGranted) {
// If the user denied our request, go ahead with the conversation.
conv.ask(`OK, no worries. What are you looking for?`);
conv.ask(new Suggestions('Blue', 'Red', 'Green'));
} else {
// If the user accepted our request, store their name in
// the 'conv.user.storage' object for future conversations.
conv.user.storage.userName = conv.user.name.display;
conv.ask(`Thanks, ${conv.user.storage.userName}. ` +
`What are you looking for?`);
conv.ask(new Suggestions('Blue', 'Red', 'Green'));
}
});
// Handle the Dialogflow NO_INPUT intent.
// Triggered when the user doesn't provide input to the Action
app.intent('actions_intent_NO_INPUT', (conv) => {
// Use the number of reprompts to vary response
const repromptCount = parseInt(conv.arguments.get('REPROMPT_COUNT'));
if (repromptCount === 0) {
conv.ask('Which color would you like to hear about?');
} else if (repromptCount === 1) {
conv.ask(`Please say the name of a color.`);
} else if (conv.arguments.get('IS_FINAL_REPROMPT')) {
conv.close(`Sorry we're having trouble. Let's ` +
`try this again later. Goodbye.`);
}
});
module.exports = server;
我的应用程序的NodeJS只是由index.js和的package.json的。我做了一个npm install
,然后将两个文件,node_modules通过FTP到我的蔚蓝的Web应用程序。当我测试了我的谷歌应用程序的行动,它得到一个网络挂接错误,因为它无法沟通。
谁能告诉我什么,我需要做的就是它的工作?
PS:这是我的package.json:
{
"name": "pyb-actions",
"description": "Actions on Google for PYB",
"author": "r3plica",
"private": true,
"scripts": {
"lint": "eslint .",
"start": "npm run shell"
},
"dependencies": {
"actions-on-google": "^2.0.0",
"express": "^4.16.4",
"i18n": "^0.8.3"
},
"devDependencies": {
"eslint": "^4.19.0",
"eslint-config-google": "^0.9.1"
}
}
回答如下:
尝试创建一个简单的GET路由,以测试该问题是否与您的服务器安装或您初始化应用程序的方式。
app.get('/', function(request,response) {
response.json({
"response": "The server is runnning"
});
});
或者,尝试通过ngrok转发本地主机和使用,作为临时履行网络挂接。
这里是我的index.js灵感:
const express = require('express');
const bodyParser = require('body-parser')
const { dialogflow } = require('actions-on-google')
const intents = require('./intents')
const expressApp = express().use(bodyParser.json())
const app = dialogflow()
app.intent('Welcome', intents.welcome)
expressApp.post('/fulfill', (req, resp) => app)
expressApp.listen(process.env.PORT || 3000, '0.0.0.0', () => {
console.log("server starting " + (process.env.PORT || 3000));
})
希望能帮助到你