我从dialogflow demo那里获得了参考。我收到
错误在方法';'预期。
sendTextMessageToDialogFlow
中。我该如何解决这个问题?
这是我的代码
router.post('/dialogflow', function(req, res) {
const projectId = "xxxxxxxxx";
const LANGUAGE_CODE = 'en-US';
let credentials = {
private_key: xxxxxxxxx,
client_email: "xxxxxxx",
}
let sessionClient = new dialogflow.SessionsClient(credentials);
async sendTextMessageToDialogFlow(req.body.query, req.body.id) {
const sessionPath = this.sessionClient.sessionPath(projectId, req.body.id);
const request = {
session: sessionPath,
queryInput: {
text: {
text: req.body.query,
languageCode: LANGUAGE_CODE
}
}
}
try {
let responses = await this.sessionClient.detectIntent(request)
console.log('DialogFlow.sendTextMessageToDialogFlow: Detected intent');
res.json(responses);
} catch (err) {
console.error('DialogFlow.sendTextMessageToDialogFlow ERROR:', err);
cosole.log(err);
}
}
})
答案 0 :(得分:0)
您似乎缺少了function一词,并且function params中包含句点 应该更像:
let sessionClient = new dialogflow.SessionsClient(credentials);
async function sendTextMessageToDialogFlow(reqBodyQuery, reqBodyId) {
const sessionPath = this.sessionClient.sessionPath(projectId, reqBodyId);
const request = {
session: sessionPath,
queryInput: {
text: {
text: reqBodyQuery,
languageCode: LANGUAGE_CODE
}
}
}
try {
let responses = await this.sessionClient.detectIntent(request)
console.log('DialogFlow.sendTextMessageToDialogFlow: Detected intent');
res.json(responses);
}
catch(err) {
console.error('DialogFlow.sendTextMessageToDialogFlow ERROR:', err);
cosole.log(err);
}
}
})
答案 1 :(得分:0)
不能将对象属性用于函数的参数。首先声明“ query”和“ id”变量,然后可以在函数中使用它们,因为它们在同一范围内。另外,您也缺少function关键字。
router.post('/dialogflow', function(req, res) {
const projectId = "xxxxxxxxx";
const LANGUAGE_CODE = 'en-US';
let credentials = {
private_key: xxxxxxxxx,
client_email: "xxxxxxx",
}
let sessionClient = new dialogflow.SessionsClient(credentials);
let query = req.body.query;
let id = req.body.id;
async function sendTextMessageToDialogFlow() {
const sessionPath = this.sessionClient.sessionPath(projectId, id);
const request = {
session: sessionPath,
queryInput: {
text: {
text: query,
languageCode: LANGUAGE_CODE
}
}
}
try {
let responses = await this.sessionClient.detectIntent(request)
console.log('DialogFlow.sendTextMessageToDialogFlow: Detected intent');
res.json(responses);
} catch (err) {
console.error('DialogFlow.sendTextMessageToDialogFlow ERROR:', err);
cosole.log(err);
}
}
});