通常,您可以使用控制台创建和删除代理。但是,在某些高级场景中,您可能会发现使用 API 更为简单。
创建代理
以下示例展示了如何为 Agent
类型调用 Create
方法。
为代理参考选择协议和版本:
协议 | V3 | V3beta1 |
---|---|---|
REST | 代理资源 | 代理资源 |
RPC | 代理界面 | 代理界面 |
C++ | AgentsClient | 不可用 |
C# | AgentsClient | 不可用 |
Go | AgentsClient | 不可用 |
Java | AgentsClient | AgentsClient |
Node.js | AgentsClient | AgentsClient |
PHP | 不可用 | 不可用 |
Python | AgentsClient | AgentsClient |
Ruby | 不可用 | 不可用 |
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:您的 Google Cloud 项目 ID
- REGION_ID:您的区域 ID
HTTP 方法和网址:
POST https://REGION_ID -dialogflow.googleapis.com/v3/projects/PROJECT_ID /locations/REGION_ID /agents
请求 JSON 正文:
{ "displayName": "My display name", "defaultLanguageCode": "en", "timeZone": "America/New_York" }
如需发送您的请求,请展开以下选项之一:
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"
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" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{ "name": "projects/PROJECT_ID /locations/REGION_ID /agents/AGENT_ID ", "displayName": "My display name", "defaultLanguageCode": "en", "timeZone": "America/New_York", "startFlow": "projects/PROJECT_ID /locations/REGION_ID /agents/AGENT_ID /flows/00000000-0000-0000-0000-000000000000", "advancedSettings": { "loggingSettings": {} } }
如需向 Dialogflow 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证。
如需向 Dialogflow 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证。
如需向 Dialogflow 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证。
删除代理
以下示例展示了如何为 Agent
类型调用 Delete
方法。
为代理参考选择协议和版本:
协议 | V3 | V3beta1 |
---|---|---|
REST | 代理资源 | 代理资源 |
RPC | 代理界面 | 代理界面 |
C++ | AgentsClient | 不可用 |
C# | AgentsClient | 不可用 |
Go | AgentsClient | 不可用 |
Java | AgentsClient | AgentsClient |
Node.js | AgentsClient | AgentsClient |
PHP | 不可用 | 不可用 |
Python | AgentsClient | AgentsClient |
Ruby | 不可用 | 不可用 |
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:您的 Google Cloud 项目 ID
- REGION_ID:您的区域 ID
- AGENT_ID:您的客服人员 ID,可在客服人员创建响应中找到
HTTP 方法和网址:
DELETE https://REGION_ID -dialogflow.googleapis.com/v3/projects/PROJECT_ID /locations/REGION_ID /agents/AGENT_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 "
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 " | Select-Object -Expand Content
您应该会收到一个成功的状态代码 (2xx) 和一个空响应。