通过 API 更新 DialogFlow 代理的实体条目列表 [英] Updating List of Entity Entries of DialogFlow Agent via API

查看:42
本文介绍了通过 API 更新 DialogFlow 代理的实体条目列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一直在寻找一种方法,通过 DialogFlow API 以编程方式更新我们的代理的实体条目,用于特定的实体类型.目的是按计划自动更新我们的实体条目(因为我们的条目每天都在变化).

遇到这个

解决方案

您需要考虑几件事情.

网址应如下所示:https://dialogflow.googleapis.com/v2/projects/julia-development-2/agent/entityTypes/actual_id/entities:batchUpdate

  • 您在 URL 中使用的父级"只是路径参数的名称
  • 确保julia-development-2"是您的 GCP 项目的 ID 而不仅仅是名称(提示:在谷歌云控制台点击下拉选择某个GCP项目时,项目名称和ID都会出现在列表中)
  • 将actual_id"替换为实体类型 id

与身份验证相关:

  • 您需要在 Authorization 标头中有一个不记名令牌
  • 要获取此令牌,您首先需要从您的项目服务帐户下载一个 JSON 密钥,并将 GOOGLE_APPLICATION_CREDENTIALS 环境变量设置为指向您的 JSON 文件.有关设置服务帐户和下载 JSON 密钥的更多详细信息,您可以在此处找到:https://cloud.google.com/dialogflow/docs/setup
  • 要从命令行获取令牌,您可以使用

    gcloud auth 应用程序-默认打印访问令牌

Have been looking for a way to programmatically update our agent's entity entries for a certain entity type through the DialogFlow API. The purpose is to automate the updating of our entity entries on a scheduled basis (as our entries will be changing daily).

Came across this documentation page by Google on batch updating entity entries but have not been able to get anything better than a 404 when testing.

Have tried sending POST's via Postman using the supplied path and inserting my project name in URL but I believe I may be making naive mistakes as I am new to this area (specifically REST-stuff)

Below is an example of the current 404 response & path used.

We are just looking to get past the 404 error, once we have the contact setup, should be able to figure out auth & the rest.

解决方案

There are several things you need to take into account.

The URL should look like this: https://dialogflow.googleapis.com/v2/projects/julia-development-2/agent/entityTypes/actual_id/entities:batchUpdate

  • the "parent" you used in the URL is just the name of the path param
  • make sure "julia-development-2" is the id of your GCP project and not just the name (Hint: when you click the drop-down for selecting a certain GCP project in the google cloud console, both the name and the ID of the project will be visibile in the list)
  • replace "actual_id" with the entity type id

Related to auth:

  • you need a bearer token in the Authorization header
  • to get this token you first need to download a JSON key from your projects service account and set the GOOGLE_APPLICATION_CREDENTIALS environment variable to point to your JSON file. More details about setting up the service account and downloading the JSON key, you can find here: https://cloud.google.com/dialogflow/docs/setup
  • to get the token from the command line you can use

    gcloud auth application-default print-access-token

这篇关于通过 API 更新 DialogFlow 代理的实体条目列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆