通常,您可以使用控制台创建和删除 intent。但是,在某些高级场景中,您可能会发现使用 API 更为简单。
创建意图
以下示例展示了如何为 Intent
类型调用 Create
方法。
为意图参考选择协议和版本:
协议 | V3 | V3beta1 |
---|---|---|
REST | intent 资源 | intent 资源 |
RPC | Intent 接口 | Intent 接口 |
C++ | IntentsClient | 不可用 |
C# | IntentsClient | 不可用 |
Go | IntentsClient | 不可用 |
Java | IntentsClient | IntentsClient |
Node.js | IntentsClient | IntentsClient |
PHP | 不可用 | 不可用 |
Python | IntentsClient | IntentsClient |
Ruby | 不可用 | 不可用 |
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:您的 Google Cloud 项目 ID
- REGION_ID:您的区域 ID
- AGENT_ID:您的代理 ID
HTTP 方法和网址:
POST https://REGION_ID -dialogflow.googleapis.com/v3/projects/PROJECT_ID /locations/REGION_ID /agents/AGENT_ID /intents
请求 JSON 正文:
{ "displayName": "My intent display name" }
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project:PROJECT_ID " \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://REGION_ID -dialogflow.googleapis.com/v3/projects/PROJECT_ID /locations/REGION_ID /agents/AGENT_ID /intents"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_ID " }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://REGION_ID -dialogflow.googleapis.com/v3/projects/PROJECT_ID /locations/REGION_ID /agents/AGENT_ID /intents" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{ "name": "projects/PROJECT_ID /locations/REGION_ID /agents/AGENT_ID /intents/INTENT_ID ", "displayName": "My intent display name", "priority": 500000 }
更新 intent
字段掩码指南介绍了如何更新 intent 的各个字段。
删除意图
以下示例展示了如何为 Intent
类型调用 Delete
方法。
为意图参考选择协议和版本:
协议 | V3 | V3beta1 |
---|---|---|
REST | intent 资源 | intent 资源 |
RPC | Intent 接口 | Intent 接口 |
C++ | IntentsClient | 不可用 |
C# | IntentsClient | 不可用 |
Go | IntentsClient | 不可用 |
Java | IntentsClient | IntentsClient |
Node.js | IntentsClient | IntentsClient |
PHP | 不可用 | 不可用 |
Python | IntentsClient | IntentsClient |
Ruby | 不可用 | 不可用 |
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:您的 Google Cloud 项目 ID
- REGION_ID:您的区域 ID
- AGENT_ID:您的代理 ID
- INTENT_ID:您的 intent ID,在创建响应中找到
HTTP 方法和网址:
DELETE https://REGION_ID -dialogflow.googleapis.com/v3/projects/PROJECT_ID /locations/REGION_ID /agents/AGENT_ID /intents/INTENT_ID
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project:PROJECT_ID " \
"https://REGION_ID -dialogflow.googleapis.com/v3/projects/PROJECT_ID /locations/REGION_ID /agents/AGENT_ID /intents/INTENT_ID "
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_ID " }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://REGION_ID -dialogflow.googleapis.com/v3/projects/PROJECT_ID /locations/REGION_ID /agents/AGENT_ID /intents/INTENT_ID " | Select-Object -Expand Content
您应该会收到一个成功的状态代码 (2xx) 和一个空响应。