對話動作已於 2023 年 6 月 13 日淘汰。詳情請參閱「
對話動作已淘汰」。
Actions API
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Actions API 提供端點,可協助建構、管理及測試動作。
用戶端程式庫 (Node.js)
儘管您可向伺服器直接發出 HTTP 要求,藉此使用 Actions API 符合 REST 樣式的服務,我們仍提供用戶端程式庫,讓您更輕鬆地從 Node.js 存取端點。Actions API 用戶端程式庫可讓您透過各種端點管理及測試動作。
舉例來說,以下程式碼會呼叫 writePreview
端點,根據提供的模型更新使用者的專案預覽畫面:
import {ActionsSdkClient} from '@assistant/actions';
import { promisify } from 'util';
import * as stream from 'stream';
const PROJECT_ID = '<PROJECT_ID>';
const VERSION = 123;
const projectPath = `projects/${PROJECT_ID}`;
const versionPath = `projects/${PROJECT_ID}/versions/${VERSION}`;
async function publishPreview(projectPath, versionPath) {
const request = {
parent: projectPath,
previewSettings: {sandbox: {value: true}},
submittedVersion: {version: versionPath}
};
const client = new ActionsSdkClient();
const stream = client.writePreview(()=>{});
stream.write(request);
stream.end();
const finished = promisify(stream.finished);
await finished(stream);
}
如需 Actions API Node.js 用戶端程式庫的安裝操作說明和參考資料,請參閱程式庫和 Actions API REST 參考資料文件。
需求條件
下列規定適用於對 Actions API 發出的要求。
要求酬載大小
對 Actions API 發出的要求不得超過 10 MB。這包括
用戶端串流端點,串流中的每個要求都必須是 10 MB
以下。
如果酬載超過 10 MB,動作應會收到 400
錯誤
SDK 伺服器
最佳做法
強烈建議採用以下最佳做法的情況下
或是使用 Actions API
為使用者建立工具或應用程式時,您也許會希望
帳單及配額,而非用戶端專案。
如要指定計費和配額用途的專案,請設定
x-goog-user-project
要求標頭。
有效值 |
現有專案 ID
Google Cloud 專案 |
範例 |
x-goog-user-project: my-project |
詳細資料 |
標頭中指定的專案會用於配額限制及計費
收取與要求相關的費用
|
使用 user-agent
要求標頭設定適當的使用者代理程式。這個
有助於 API 判斷請求是否來自合作夥伴。
已知限制
本節說明 Actions API 的已知限制。
用戶端串流端點逾時
這項限制僅適用於您向用戶端串流發出的 HTTP 要求
端點。使用用戶端程式庫提出的要求並非
會受此限制影響
如果您使用 HTTP 要求呼叫 WritePreview
、CreateVersion
或 WriteDraft
,
建議您設定逾時,以處理不屬於
成功。
如果您收到的回應標頭指定 200
以外的狀態碼,
程式碼應在一段時間過後終止串流本期
只會影響用戶端串流端點。例如 gactions
工具
使用 Actions API 則有 5 秒的逾時時間
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003eThe Actions API offers endpoints for building, managing, and testing Actions.\u003c/p\u003e\n"],["\u003cp\u003eA Node.js client library simplifies interactions with the API, offering easier access to endpoints for managing and testing your Action.\u003c/p\u003e\n"],["\u003cp\u003eRequests to the Actions API must be 10 MB or less, including those made to client streaming endpoints.\u003c/p\u003e\n"],["\u003cp\u003eSetting the \u003ccode\u003ex-goog-user-project\u003c/code\u003e request header enables billing and quota management for user projects.\u003c/p\u003e\n"],["\u003cp\u003eWhen using HTTP requests with client streaming endpoints like \u003ccode\u003eWritePreview\u003c/code\u003e, it's recommended to implement a timeout to handle potential unsuccessful requests.\u003c/p\u003e\n"]]],["The Actions API facilitates Action development, management, and testing. A Node.js client library simplifies interaction with API endpoints. For instance, `writePreview` updates a project preview. Requests must be under 10MB, with the `x-goog-user-project` header recommended for billing and quota purposes. The `user-agent` header is advised for partner identification. Direct HTTP calls to streaming endpoints like `WritePreview` have timeout considerations, though the client library mitigates this.\n"],null,["The Actions API provides endpoints to help build, manage, and test your Action.\n\nClient Library (Node.js)\n\nWhile you can use the Actions API RESTful service by making direct HTTP requests to the server, we provide a client library that makes it easier to access the endpoints from Node.js. The [Actions API client library](https://github.com/actions-on-google/assistant-actions-nodejs) allows you to manage and test your Action using a variety of endpoints.\n\nFor example, the code below makes a call to the [`writePreview`](/assistant/actions/api/reference/rest/v2/projects.preview/write) endpoint to update a user's project preview based on the provided model: \n\n import {ActionsSdkClient} from '@assistant/actions';\n import { promisify } from 'util';\n import * as stream from 'stream';\n\n const PROJECT_ID = '\u003cPROJECT_ID\u003e';\n const VERSION = 123;\n\n const projectPath = `projects/${PROJECT_ID}`;\n const versionPath = `projects/${PROJECT_ID}/versions/${VERSION}`;\n\n async function publishPreview(projectPath, versionPath) {\n const request = {\n parent: projectPath,\n previewSettings: {sandbox: {value: true}},\n submittedVersion: {version: versionPath}\n };\n\n const client = new ActionsSdkClient();\n const stream = client.writePreview(()=\u003e{});\n stream.write(request);\n stream.end();\n const finished = promisify(stream.finished);\n await finished(stream);\n }\n\nFor installation instructions and reference material for the Actions API Node.js client library, see the [library](/assistant/actions/api/(https:/github.com/actions-on-google/assistant-actions-nodejs)) and [Actions API REST reference](/assistant/actions/api/reference/rest) documentation.\n\nRequirements\n\nThe following requirements apply to requests made to the Actions API.\n\nRequest payload size\n\nRequests made to the Actions API must be 10 MB or less. This includes\nclient streaming endpoints, where each request in the stream must be 10 MB\nor less.\n\nIf your payload exceeds 10 MB, you should receive a `400` error from the Actions\nSDK server.\n\nBest practices\n\nThe following best practices are strongly recommended when\nyou use the Actions API.\n\nSet the x-goog-user-project request header\n\nWhen building a tool or application for your users, you may want a user's\nproject to be billed and used for quota limits, rather than your client project.\nTo specify a project for billing and quota purposes, set the\n`x-goog-user-project` request header.\n\n|--------------|------------------------------------------------------------------------------------------------------------------|\n| Valid Values | The [Project ID](/docs/overview#projects) for an existing Google Cloud project |\n| Example | `x-goog-user-project: my-project` |\n| Details | The project specified in the header is used for quota limits and billed for charges associated with the request. |\n\nSet the user-agent request header\n\nSet an appropriate user agent using the `user-agent` request header. This\nhelps the API determine if requests originate from partners.\n\nKnown limitations\n\nThis section describes known limitations of the Actions API.\n\nTimeout for client streaming endpoints\n\nThis limitation only applies to HTTP requests you make to client streaming\nendpoints. Requests made using the [client library](#client-library) are not\naffected by this limitation.\n\nIf you are using HTTP requests to call `WritePreview`, `CreateVersion`, or `WriteDraft`, we\nrecommend that you implement a timeout to handle requests that are not\nsuccessful.\n\nIf you receive a response header that specifies a status code other than `200`,\nyour code should terminate the stream after a certain period of time. This issue\nonly affects client streaming endpoints. For example, the `gactions` tool,\nwhich uses the Actions API, has a 5-second timeout."]]