我已经开始学习 DialogFlow,我想知道如何通过代码创建 Intent in Fulfillment,而不是通过 GUI 创建它。
这是我现有的履行代码:
'use strict';
const functions = require('firebase-functions');
const { WebhookClient } = require('dialogflow-fulfillment');
const { Card, Suggestion } = require('dialogflow-fulfillment');
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
function welcome(agent) {
agent.add(`Welcome to my firstagent!`);
}
function fallback(agent) {
agent.add(`I didn't understand!`);
agent.add(`I'm sorry, can you try again??`);
agent.add(`Can you please tell me again??`);
agent.add(`Sorry, I don't understand`);
}
let intentMap = new Map();
//these are the intents that I've already created in dialog flow, But I want to create a new intent in code!
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
agent.handleRequest(intentMap);
});