gpt4 book ai didi

node.js - 如何通过代码在 DialogFlow Fulfillment 中创建意图?

转载 作者:搜寻专家 更新时间:2023-11-01 00:27:55 25 4
gpt4 key购买 nike

我已经开始学习 DialogFlow,我想知道如何通过代码在 Fulfillment 中创建一个 Intent,而不是通过 GUI 创建它。

这是我现有的 Fulfillment 代码:

'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);
});

最佳答案

您不能创建“in Fulfillment”的 Intent,因为 fulfillment webhook 旨在回答您的代理中当前设置的任何意图,而不是操纵它们。

但是,您可以使用 Dialogflow API 以编程方式操作代理,这是一个普通的 Google Cloud API,在 many different programming languages 中具有客户端库.要创建意图,您需要查看 projects.agent.intents.create方法。

关于node.js - 如何通过代码在 DialogFlow Fulfillment 中创建意图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51647763/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com