添加培训短语时Dialogflow v2 Node.js客户端库UpdateIntent

安东尼奥·库奇涅洛

我正在尝试使用updateIntentNode.js的Dialogflow v2客户端库中的功能。我尝试使用它的原因是为了能够向意图添加训练短语。

我似乎无法通过这个。这是我正在使用的代码!:

我的GetIntent函数:

async function getIntent(intentId) {
  try {
    let responses = await intentsClient.getIntent({name: intentId, intentView: 'INTENT_VIEW_FULL'})
    const response = responses[0]
          // console.log(response)

    return new Promise((resolve, reject) => {
      resolve(response)
    })
  } catch (err) {
    return new Promise((resolve, reject) => {
      reject(err)
    })
  }
}

我的UpdateIntent函数:

async function updateIntent(intent) {
  const request = {
    intent: intent,
    languageCode: 'en-US',
    updateMask: {
       paths: ['trainingPhrases']
    },
    intentView: 'INTENT_VIEW_FULL'
  }
  try {
    let responses = await intentsClient.updateIntent(request)
    return new Promise((resolve, reject) => {
      resolve(response)
    })
  } catch (err) {
    console.log(err)
    return new Promise((resolve, reject) => {
      reject(err)
    })
  } 
}

调用它的函数:

async function testUpdateTraining () {
  try {
    let intent = await getIntent('projects/small-talk-1-406ae/agent/intents/ac7f0b68-de5c-4b6f-9393-358dd2b0c1bd')

    let trainingPhrase = { parts: [{ text: 'How should I behave on the trails?'}],
      type: 'EXAMPLE'}
    intent.trainingPhrases.push(trainingPhrase)
    try {
      let updatedIntent = await updateIntent(intent)
    } catch (e) {
      console.log(e)
      console.log('failed to update the intent')
    }
  } catch (err) {
    console.log('failed to get intent')
  }
}

现在奇怪的是-我从客户端库调用中收到200条响应。Api文档指出,成功响应后,您将获得一个意图对象。我收到一个带有训练短语的意图对象...

    [![{ inputContextNames: \[\],
  events: \[\],
  trainingPhrases:
   \[ { parts: \[Array\],
       name: 'ad0d1f6a-78cf-4e0b-84ca-ec62a45c75dc',
       type: 'EXAMPLE',
       timesAddedCount: 0 },
     { parts: \[Array\],
       name: 'e33cce4b-96ee-4e35-a151-5b09ff603817',
       type: 'EXAMPLE',
       timesAddedCount: 0 },
     { parts: \[Array\],
       name: '7d9b7c56-5fa8-4791-986f-e57b9f90d431',
       type: 'EXAMPLE',
       timesAddedCount: 0 } \],
  outputContexts: \[\],
  parameters: \[\],
  messages:
   \[ { platform: 'PLATFORM_UNSPECIFIED',
       text: \[Object\],
       message: 'text' } \],
  defaultResponsePlatforms: \[\],
  followupIntentInfo: \[\],
  name: 'projects/small-talk-1-406ae/agent/intents/ac7f0b68-de5c-4b6f-9393-358dd2b0c1bd',
  displayName: 'faq.offroad.card1answer',
  priority: 500000,
  isFallback: false,
  webhookState: 'WEBHOOK_STATE_UNSPECIFIED',
  action: 'faq.offroad.card1answer',
  resetContexts: false,
  rootFollowupIntentName: '',
  parentFollowupIntentName: '',
  mlDisabled: true }][1]][1] 

这就是dialogflow所具有的。这里只有两个训练短语,我以编程方式添加的训练短语没有出现。在此处输入图片说明所以我的问题是,如何格式化请求,以便我可以毫无问题地更新训练短语?有没有我可以逃脱的例子?

阿克沙伊

经过大量尝试后,了解到我的代码可以正常工作,因为我删除了更新掩码。还有languageCode,因为它给了我一个错误。代码如下,并且工作正常。检查它。

这是getIntent函数:

    async function getIntent(intentId) {
    try {
        let responses = await intentsClient.getIntent({
            name: intentId,
            intentView: 'INTENT_VIEW_FULL'
        })
        const response = responses[0];
        console.log(util.inspect(response, false, null, true /* enable colors */ ));

        return new Promise((resolve, reject) => {
            resolve(response)
        })
    } catch (err) {
        return new Promise((resolve, reject) => {
            reject(err)
        })
    }
}

调用它的函数:

async function testUpdateTraining () {
    try {
        let intent = await getIntent('<your_ID>')

        let trainingPhrase = {
            parts: [{
                text: 'let me call you?'
            }],
            type: 'EXAMPLE'
        }
        intent.trainingPhrases.push(trainingPhrase)
        try {
            let updatedIntent = await updateIntent(intent)
        } catch (e) {
            console.log(e)
            console.log('failed to update the intent')
        }
    } catch (err) {
        console.log('failed to get intent')
    }
 }

UpdateIntent函数:

 async function updateIntent(intent) {
    const request = {
        intent: intent,
        intentView: 'INTENT_VIEW_FULL'
    }
    try {
        let responses = await intentsClient.updateIntent(request)
        return new Promise((resolve, reject) => {
            resolve(responses)
        })
    } catch (err) {
        console.log(err)
        return new Promise((resolve, reject) => {
            reject(err)
        })
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用Java的Google Translate v2 API客户端库提出翻译请求?

ReCaptcha v2客户端事件

将Node.js Web客户端连接到Java gRPC服务器时出错

使用Spring Boot的Dialogflow v2 Java客户端库detectIntent:未为项目找到DesignTimeAgent

获取在客户端创建的PayPal v2订单的详细信息时出错

尝试从远程客户端访问新的Podman v2 API时,连接被拒绝

Node.js中的OneM2M Coap客户端

无法使用Google的node.js客户端库生成JWT客户端

在Google Actions-on-Google Node.js v2中构建列表

如何使用客户端库从Node JS将文件夹上传到GCS

如何在Nuxt中添加客户端js库>

在本地使用Node.js时客户端和服务器的时间不同

使用TypeScript时,扩展Node.js客户端库中的“ conv”实例以在Google v2上执行操作

Google Dialogflow V2的C#库

Dialogflow v2客户端库不起作用| 错误:无法加载默认凭据

使用Node StackDriver客户端库时如何登录到不同级别?

在Node.js客户端/服务器中通过TCP发送查询结果时出现问题

建立安全TLS连接之前客户端网络套接字已断开连接Node.js v13.0.1

当minVersion设置为1.3并使用1.3与客户端连接时,Node.js表示正在使用tls1.2

安装了AWS CLI V2的AWS CodeBuild Node.js映像

使用Chrome和Node.js时,客户端和服务器上是否已编译javascript?

使用node.js中的soap模块在客户端中添加soap标头

Node.js服务器的哪个Websocket库最适合iOS客户端?

客户端发送无效数据包时 Node.js 崩溃

如何在没有 Firebase 的情况下使用 DialogFlow、node.js v2 库

使用来自 node-json-rpc 库的客户端时使用正确的 SSL 协议

列出 VM - Google Compute Engine Node.js 客户端库

如何将 vue.js 客户端添加到现有的 node.js api?

使用 node.js 和 socket.io 向客户端发送信息时出现延迟