我正在使用npm使用dialogflow v2。我只想在dialogflow中调用welcome
事件。我该如何在nodejs中做到这一点。我很新。
这是我的代码
const projectId = "xxxxxx";
const LANGUAGE_CODE = 'en-US';
const sessionId = req.body.sessionId;
var query = req.body.query;
const sessionClient = new dialogflow.SessionsClient();
const sessionPath = sessionClient.sessionPath(projectId,sessionId);
const request = {
session: sessionPath,
queryInput: {
text: {
text: query,
languageCode: LANGUAGE_CODE,
},
},
};
sessionClient.detectIntent(request).then(response => {
console.log('intent detected');
const result = response[0].queryResult;
console.log(` Query: ${result.queryText}`);
console.log(` Response: ${result.fulfillmentText}`);
if(result.fulfillmentText) {
console.log(result.fulfillmentText);
return res.json({reply: result.fulfillmentText})
}
// if(result.intent) {
// console.log(` Intent: ${result.intent.displayName}`)
// }
else {
console.log('no intent found');
}
}).catch(err => {
console.log('error '+err);
})
当我打开聊天页面时,我只想发出欢迎消息。为了做到这一点,我读到我必须打电话给活动。我怎样才能做到这一点?我已经引用了here
最佳答案
请求正文应如下所示:
let eventName='WELCOME'; //name of the event
let request = {
session: sessionPath,
queryInput: {
event: {
name: eventName,
languageCode: 'en-US'
},
},
};
结帐-https://github.com/googleapis/nodejs-dialogflow/blob/master/samples/detect.js#L96
让我知道您是否有任何困难:)
关于node.js - 如何在dialogflow v2中调用事件:nodejs,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52779105/