[英]How to update existing Intent in Dialogflow(V2) using nodejs SDK?
I am using Dialogflow nodejs SDK(V2) to Integrate Dialogflow in my nodjs application for that I am using dialogflow npm node library. 我正在使用Dialogflow nodejs SDK(V2)在我的nodjs应用程序中集成Dialogflow,因为我正在使用dialogflow npm节点库。 I'm able to create the Intent and get the list of Intents and I'm able to query as well. 我可以创建Intent并获取Intent列表,也可以查询。 But I can't find any method for updating the existing Intent and getting Intent details based on the Intent ID. 但是我找不到任何方法来更新现有的Intent并根据Intent ID获取Intent详细信息。
can you please help me or guide me how to resolve this issue? 您能帮我还是指导我解决这个问题?
Thanks. 谢谢。
To update an intent, first, you need to get the intent details. 要更新意图,首先,您需要获取意图详细信息。 If you have the intent name or ID, then you can simply make a request to list intent API and find the intent details with matching intent name. 如果您具有意图名称或ID,则只需提出一个列出意图API的请求,并找到具有匹配意图名称的意图详细信息。
Once you have the intent details you wish to update( here referred as existingIntent
), you can use the below code to update it. 一旦有了要更新的意图详细信息(在此称为existingIntent
),就可以使用以下代码对其进行更新。
async function updateIntent(newTrainingPhrases) {
// Imports the Dialogflow library
const dialogflow = require("dialogflow");
// Instantiates clients
const intentsClient = new dialogflow.IntentsClient();
const intent = existingIntent; //intent that needs to be updated
const trainingPhrases = [];
let previousTrainingPhrases =
existingIntent.trainingPhrases.length > 0
? existingIntent.trainingPhrases
: [];
previousTrainingPhrases.forEach(textdata => {
newTrainingPhrases.push(textdata.parts[0].text);
});
newTrainingPhrases.forEach(phrase => {
const part = {
text: phrase
};
// Here we create a new training phrase for each provided part.
const trainingPhrase = {
type: "EXAMPLE",
parts: [part]
};
trainingPhrases.push(trainingPhrase);
});
intent.trainingPhrases = trainingPhrases;
const updateIntentRequest = {
intent,
languageCode: "en-US"
};
// Send the request for update the intent.
const result = await intentsClient.updateIntent(updateIntentRequest);
return result;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.