简体   繁体   English

如何使用nodejs SDK更新Dialogflow(V2)中的现有Intent?

[英]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.

相关问题 如何使用 dialogflow-nodejs-client-v2 将 Dialogflow API v2 与 MS BotFramework 集成 - How to integrate Dialogflow API v2 with MS BotFramework using dialogflow-nodejs-client-v2 如何在dialogflow v2中调用事件:nodejs - how to call a event in the dialogflow v2 :nodejs 如何使用Node.js中的dialogflow模块创建Messenger bot(使用dialogflow v2 API) - How to use dialogflow module of in nodejs to create messenger bot (using dialogflow v2 API) 上传 Intent 函数 Dialogflow V2 - Upload Intent function Dialogflow V2 Dialogflow v2 NodeJS API ContextsClient - Dialogflow v2 NodeJS API ContextsClient 将参数发送到 dialogflow sdk v2 上的 webhook - Send parameters to webhook on dialogflow sdk v2 如何在 ASK-SDK v2 中使用 handlerInput 获取自定义意图槽值 - How to get custom intent slot values using handlerInput in ASK-SDK v2 无论对话框流v2中的用户输入是什么,如何强制检测特定意图 - How to force detecting specific intent regardless what is user input in dialogflow v2 无法在 dialogflow rest api v2 中获取意图详细信息 - Unable to get intent details in dialogflow rest api v2 设置输入或输出上下文 dialogflow nodejs v2 - set input or output context dialogflow nodejs v2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM