我正在尝试使用“ const dialogflow = require('dialogflow');”导入对话框流。并且不断在heroku服务器上引发错误。
我尝试了不同版本的dialogflow,当我不导入该文件时,它没有出现任何问题。
const fetch = require('node-fetch');
const projectId = 'projectid';
const sessionId = '123456';
const languageCode = 'en-US';
const config2 = require('config');
const dialogflow = require('dialogflow');
const config = {
credentials: {
private_key: process.env.DIALOGFLOW_PRIVATE_KEY,
client_email: process.env.DIALOGFLOW_CLIENT_EMAIL
}
};
const sessionClient = new dialogflow.SessionsClient(config);
const sessionPath = sessionClient.sessionPath(projectId, sessionId);
const FACEBOOK_ACCESS_TOKEN = config2.get('appSecret');
const sendTextMessage = (userId, text) => {
return fetch(
`https://graph.facebook.com/v2.6/me/messages?access_token=${FACEBOOK_ACCESS_TOKEN}`,
{
headers: {
'Content-Type': 'application/json',
},
method: 'POST',
body: JSON.stringify({
messaging_type: 'RESPONSE',
recipient: {
id: userId,
},
message: {
text,
},
}),
}
);
}
module.exports = (event) => {
const userId = event.sender.id;
const message = event.message.text;
const request = {
session: sessionPath,
queryInput: {
text: {
text: message,
languageCode: languageCode,
},
},
};
sessionClient
.detectIntent(request)
.then(responses => {
const result = responses[0].queryResult;
return sendTextMessage(userId, result.fulfillmentText);
})
.catch(err => {
console.error('ERROR:', err);
});
}
预期的结果只是向我的信使返回一条消息。
它给出的错误如下:
2019-05-21T11:09:08.270374+00:00 heroku[web.1]: Starting process with command `npm start`
2019-05-21T11:09:11.202189+00:00 app[web.1]:
2019-05-21T11:09:11.202212+00:00 app[web.1]: > messenger-get-started@1.0.0 start /app
2019-05-21T11:09:11.202214+00:00 app[web.1]: > node app.js
2019-05-21T11:09:11.202215+00:00 app[web.1]:
2019-05-21T11:09:11.508683+00:00 app[web.1]: WARNING: NODE_ENV value of 'production' did not match any deployment config file names.
2019-05-21T11:09:11.508730+00:00 app[web.1]: WARNING: See https://github.com/lorenwest/node-config/wiki/Strict-Mode
2019-05-21T11:09:12.088930+00:00 app[web.1]: /app/node_modules/google-gax/build/src/grpc.js:71
2019-05-21T11:09:12.088943+00:00 app[web.1]: INCLUDE_DIRS.push(...COMMON_PROTO_DIRS);
2019-05-21T11:09:12.088945+00:00 app[web.1]: ^^^
2019-05-21T11:09:12.088947+00:00 app[web.1]:
2019-05-21T11:09:12.088949+00:00 app[web.1]: SyntaxError: Unexpected token ...
2019-05-21T11:09:12.088951+00:00 app[web.1]: at exports.runInThisContext (vm.js:53:16)
2019-05-21T11:09:12.088952+00:00 app[web.1]: at Module._compile (module.js:373:25)
2019-05-21T11:09:12.088954+00:00 app[web.1]: at Object.Module._extensions..js (module.js:416:10)
2019-05-21T11:09:12.088955+00:00 app[web.1]: at Module.load (module.js:343:32)
2019-05-21T11:09:12.088957+00:00 app[web.1]: at Function.Module._load (module.js:300:12)
2019-05-21T11:09:12.088959+00:00 app[web.1]: at Module.require (module.js:353:17)
2019-05-21T11:09:12.088960+00:00 app[web.1]: at require (internal/module.js:12:17)
2019-05-21T11:09:12.088962+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/google-gax/build/src/index.js:33:16)
2019-05-21T11:09:12.088963+00:00 app[web.1]: at Module._compile (module.js:409:26)
2019-05-21T11:09:12.088965+00:00 app[web.1]: at Object.Module._extensions..js (module.js:416:10)
2019-05-21T11:09:12.104059+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-05-21T11:09:12.105090+00:00 app[web.1]: npm ERR! errno 1
2019-05-21T11:09:12.109582+00:00 app[web.1]: npm ERR! messenger-get-started@1.0.0 start: `node app.js`
2019-05-21T11:09:12.110168+00:00 app[web.1]: npm ERR! Exit status 1
2019-05-21T11:09:12.111525+00:00 app[web.1]: npm ERR!
2019-05-21T11:09:12.112198+00:00 app[web.1]: npm ERR! Failed at the messenger-get-started@1.0.0 start script.
2019-05-21T11:09:12.113336+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-05-21T11:09:12.136036+00:00 app[web.1]:
2019-05-21T11:09:12.140705+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-05-21T11:09:12.141995+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-05-21T11_09_12_125Z-debug.log
2019-05-21T11:09:12.257945+00:00 heroku[web.1]: State changed from starting to crashed
2019-05-21T11:09:12.248251+00:00 heroku[web.1]: Process exited with status 1
2019-05-21T11:09:51.009060+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/webhook" host= request_id= fwd="" dyno= connect= service= status=503 bytes= protocol=https
2019-05-21T11:11:11.776503+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/webhook" host= request_id= fwd="" dyno= connect= service= status=503 bytes= protocol=https