تم إيقاف إجراءات المحادثات نهائيًا في 13 حزيران (يونيو) 2023. لمزيد من المعلومات، يُرجى الاطّلاع على
إنهاء إجراءات المحادثة.
واجهة برمجة تطبيقات المهام
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
توفّر واجهة برمجة تطبيقات المهام نقاط نهاية للمساعدة في إنشاء الإجراء وإدارته واختباره.
مكتبة البرامج (Node.js)
على الرغم من أنّه يمكنك استخدام خدمة Action API RESTful من خلال تقديم طلبات HTTP مباشرة إلى الخادم، نوفّر مكتبة عملاء تسهِّل الوصول إلى نقاط النهاية من Node.js. تتيح لك مكتبة برامج واجهة برمجة التطبيقات للأنشطة التجارية إدارة الإجراء واختباره باستخدام مجموعة متنوعة من نقاط النهاية.
على سبيل المثال، يطلب الرمز أدناه من نقطة النهاية 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);
}
للحصول على تعليمات التثبيت والمواد المرجعية لمكتبة برامج Node.js في واجهة برمجة التطبيقات للإجراءات، يمكنك الاطّلاع على مستندات المكتبة ومرجع REST لواجهة برمجة تطبيقات الإجراءات.
المتطلبات
تنطبق المتطلبات التالية على الطلبات المقدَّمة إلى واجهة برمجة تطبيقات الإجراءات.
حجم حمولة الطلب
يجب ألا يزيد حجم الطلبات المقدّمة إلى واجهة برمجة تطبيقات المهام عن 10 ميغابايت. وتشمل هذه المعلومات ما يلي:
نقاط نهاية البث من العميل، حيث يجب أن يكون كل طلب في البث 10 ميغابايت
أو أقل.
إذا تجاوزت حمولة البيانات 10 ميغابايت، من المفترض أن يظهر لك خطأ 400
في قسم "الإجراءات".
خادم SDK.
أفضل الممارسات
يُنصح بشدة باتّباع أفضل الممارسات التالية عندما
تستخدم واجهة برمجة تطبيقات الإجراءات.
عند إنشاء أداة أو تطبيق للمستخدمين، قد تحتاج إلى موافقة المستخدِم
مشروع الفوترة واستخدام هذا المشروع لحدود الحصة، بدلاً من مشروع العميل.
لتحديد مشروع لأغراض الفوترة والحصة، يمكنك ضبط
عنوان طلب x-goog-user-project
.
القيم الصالحة |
رقم تعريف المشروع لمشروع حالي
مشروع Google Cloud |
مثال |
x-goog-user-project: my-project |
التفاصيل |
يُستخدَم المشروع المحدّد في العنوان لحدود الحصة ويتم إصدار الفواتير له
مقابل الرسوم المرتبطة بالطلب.
|
اضبط وكيل مستخدم مناسبًا باستخدام عنوان الطلب user-agent
. هذا النمط
يساعد واجهة برمجة التطبيقات على تحديد ما إذا كانت الطلبات مصدرها الشركاء.
القيود المعروفة
يوضِّح هذا القسم القيود المعروفة في واجهة برمجة تطبيقات الإجراءات.
مهلة نقاط نهاية بث العميل
لا ينطبق هذا القيد إلا على طلبات HTTP التي تجريها على بث العميل
والنقاط النهائية. الطلبات المقدَّمة باستخدام مكتبة العملاء غير متوفّرة.
المتضررين من هذا القيد.
إذا كنت تستخدم طلبات HTTP لاستدعاء WritePreview
أو CreateVersion
أو WriteDraft
، فلن
نوصيك بتنفيذ مهلة لمعالجة الطلبات التي لا
وناجح.
إذا تلقّيت عنوان استجابة يحدّد رمز حالة غير 200
،
يجب أن ينهي الرمز البث بعد فترة زمنية محددة. هذا الإصدار
تؤثر فقط في نقاط نهاية بث العميل. على سبيل المثال، أداة gactions
،
التي تستخدم واجهة برمجة تطبيقات الإجراءات، مهلتها تبلغ 5 ثوانٍ.
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 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,["# Actions API\n\nThe Actions API provides endpoints to help build, manage, and test your Action.\n\nClient Library (Node.js)\n------------------------\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------------\n\nThe following requirements apply to requests made to the Actions API.\n\n### Request 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--------------\n\nThe following best practices are strongly recommended when\nyou use the Actions API.\n\n### Set 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\n### Set 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-----------------\n\nThis section describes known limitations of the Actions API.\n\n### Timeout 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."]]