我正在尝试使用dialogflow放松构建内置的聊天机器人。我正在尝试使聊天机器人为用户执行松弛事件,例如重命名频道和存档频道。当用户想要重命名频道时,他可以告诉该机器人频道要重命名,并告诉该频道新名称并由机器人为他执行。我无法将这些事件添加或编码到我的机器人中。
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
process.env.DEBUG = 'dialogflow:debug';
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request,response) => {
const agent = new WebhookClient({ request, response });
//const agentPath = agent.entitiesClient.projectAgentPath("master-bot-53dee");
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 agent!`);
}
function fallback(agent) { }
function slack_rename(agent) {
const query = agent.query;
let channel = agent.parameters.channel;
let rename = agent.parameters.rename;
let rname = agent.parameters.any;
let a = query.split(" ");
let i = 0;
agent.add(`changing the name of the channel ${channel} to ${rname}`);
}
function slack_archive(agent){
let channel = agent.parameters.channel;
let archive = agent.parameters.archive;
agent.add(`so you want to ${archive} ${channel}`);
}
function slack_private(agent) {
let priv = agent.parameters.private;
let pub = agent.parameters.public;
let channel = agent.parameters.channel;
agent.add(`so you want to convert ${channel} from ${pub} to ${priv}`);
}
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
intentMap.set('slack-rename', slack_rename);
intentMap.set('slack-archive', slack_archive);
intentMap.set('slack_private', slack_private);
agent.handleRequest(intentMap);
});