Kể từ ngày 13 tháng 6 năm 2023, Hành động trò chuyện không còn được dùng nữa. Để biết thêm thông tin, hãy xem phần Hành động trò chuyện ngừng hoạt động.
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Hành động là các điểm truy cập vào ứng dụng, giúp xác định lời mời và khám phá
cho ứng dụng của mình. Bạn khai báo Hành động trong tệp JSON được gọi là Gói hành động,
mà sau này bạn tải lên dự án dành cho nhà phát triển khi bạn muốn thử nghiệm hoặc
gửi dự án Actions để phê duyệt. Gói Hành động là một tệp JSON
xác định các Actions trong dự án Actions của bạn.
Để xác định Hành động trong gói Hành động, bạn cần tạo một ý định xác định cách
Hành động được gọi và điểm cuối thực hiện tương ứng khi
ý định được kích hoạt. Bạn có thể tạo các loại Thao tác sau:
Hành động mặc định: Mọi dự án Hành động phải có ý định chào mừng hành động
làm điểm truy cập để người dùng bắt đầu cuộc trò chuyện. Mục đích chào mừng là
được kích hoạt khi người dùng gọi ra một Hành động một cách rõ ràng bằng cách nói tên hành động đó (cho
ví dụ: "Ok Google, hãy nói chuyện với ExampleAction"). Ý định chào mừng này được xác định bằng
tên ý định actions.intent.MAIN.
Hành động bổ sung cho đường liên kết sâu: Bạn có thể tạo thêm Hành động trong
gói Hành động của bạn với ý định mà bạn tự xác định. Điều này cho phép người dùng
để gọi chức năng cụ thể bằng cách nói tên Hành động cùng với ý định
(ví dụ: "Ok Google, hãy nói chuyện với ExampleAction để tìm một số đôi giày").
Vui lòng xem bài viết Ý định và lệnh gọi để biết thêm thông tin về cách
các mô hình gọi này hoạt động.
Xác định Hành động mặc định
Mỗi gói Hành động phải có một và chỉ một ý định xử lý
Ý định actions.intent.MAIN. Ý định này được kích hoạt khi người dùng gọi
Hành động theo tên (ví dụ: "Ok Google, hãy nói chuyện với ExampleAction").
Để tạo tệp gói Hành động nguyên mẫu có tên action.json, hãy lấy phương thức
các bước sau:
Bạn có thể cung cấp các Hành động khác đóng vai trò là điểm truy cập. Nhờ đó, người dùng
phân biệt rõ ý định của họ bằng cách cho phép họ chỉ rõ thêm chi tiết về những gì họ
muốn thực hiện (ví dụ: "Ok Google, hãy nói với ExampleAction để tìm cho tôi một số
giày.").
Cách xác định các Thao tác khác:
Trong mảng actions, hãy chỉ định một Hành động cho mọi điểm truy cập.
Ví dụ: mã sau đây hiển thị thêm một nút "mua" Hành động xác định:
Tên ý định của com.example.ExampleAction.BUY
parameters để phân tích cú pháp từ hoạt động đầu vào của người dùng khi ý định này được kích hoạt.
Điều này sẽ hữu ích nếu bạn cần dữ liệu cụ thể từ cụm từ Hành động khi
người dùng gọi Hành động.
queryPatterns xác định những gì người dùng cần nói để kích hoạt ý định.
Mẫu truy vấn có thể bao gồm các loại Schema.org
xác định các tham số cần phân tích cú pháp.
{"description":"Direct access","name":"BUY","fulfillment":{"conversationName":"ExampleAction"},"intent":{"name":"com.example.ExampleAction.BUY","parameters":[{"name":"color","type":"org.schema.type.Color"}],"trigger":{"queryPatterns":["find some $org.schema.type.Color:color sneakers","buy some blue suede shoes","get running shoes"]}}}
Chỉ định phương thức thực hiện ý định này bằng cách chỉ định conversationName
tương ứng với một mục trong đối tượng conversations.
{"actions":[{"description":"Default welcome intent","name":"MAIN","fulfillment":{"conversationName":"ExampleAction"},"intent":{"name":"actions.intent.MAIN","trigger":{"queryPatterns":["talk to ExampleAction"]}}},{"description":"Direct access","name":"BUY","fulfillment":{"conversationName":"ExampleAction"},"intent":{"name":"com.example.ExampleAction.BUY","parameters":[{"name":"color","type":"org.schema.type.Color"}],"trigger":{"queryPatterns":["find some $org.schema.type.Color:color sneakers","buy some blue suede shoes","get running shoes"]}}}],"conversations":{"ExampleAction":{"name":"ExampleAction","url":"https://www.example.com/ExampleAction"}},"locale":"en"}
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[[["\u003cp\u003eActions define how users invoke your app and are declared in a JSON file called the Action package.\u003c/p\u003e\n"],["\u003cp\u003eEvery Action package requires a default Action triggered by the \u003ccode\u003eactions.intent.MAIN\u003c/code\u003e intent, serving as the primary entry point.\u003c/p\u003e\n"],["\u003cp\u003eYou can define additional Actions for deep linking, enabling users to access specific app functionalities directly.\u003c/p\u003e\n"],["\u003cp\u003eActions utilize intents, query patterns, and fulfillment endpoints to process user requests and deliver responses.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egactions\u003c/code\u003e CLI helps generate and manage the Action package file for your Actions project.\u003c/p\u003e\n"]]],[],null,["# Define Actions (Dialogflow)\n\nActions are entry points into your app that define the [invocation and discovery](/assistant/df-asdk/discovery)\nmodel for your app. You declare Actions in a JSON file known as the [Action package](/assistant/df-asdk/reference/action-package/rest/Shared.Types/ActionPackage),\nwhich you later upload to your developer project when you want to test or\nsubmit your Actions project for approval. An Action package is a JSON file that\ndefines the Actions in your Actions project.\n\nTo define Actions in your Action package, you create an intent that defines how\nthe Action is invoked and the corresponding fulfillment endpoint for when the\nintent is triggered. You can create the following types of Actions:\n\n- **Default Action:** Every Actions project must have a welcome intent that acts as an entry point for users to start conversations. The welcome intent is triggered when users explicitly invoke an Action by uttering its name (for example, *\"Hey Google, talk to ExampleAction\"* ). This welcome intent is identified with the `actions.intent.MAIN` intent name.\n- **Additional Actions for deep-linking:** You can create additional Actions in your Action package with intents that you define yourself. This allows users to invoke specific functionality by saying an Action name along with an intent (for example: *\"Hey Google, talk to ExampleAction to find some shoes\"*).\n\nSee [Intents and invocation](/assistant/df-asdk/discovery) for more information on how\nthese invocation models work.\n\nDefine a default Action\n-----------------------\n\nEvery Action package must have one and only one intent that handles the\n`actions.intent.MAIN` intent. This intent is triggered when users invoke your\nAction by name (for example, *\"Hey Google, talk to ExampleAction\"*).\n| **Note:** You specify your Action name in the project, when you submit your Action package for approval. During testing, you invoke your Action by saying *\"talk\n| to my test app\"*.\n\nTo generate a boilerplate Action package file named `action.json`, take the\nfollowing steps:\n\n1. Download the [`gactions` CLI](/assistant/df-asdk/actions-sdk/gactions-cli).\n2. Create a local directory for your Action project's source files.\n3. Run the following commands in the terminal:\n\n ```bash\n $ cd PROJECT_DIRECTORY\n $ gactions init\n ```\n\nOnce the Action package file is generated, replace placeholder content with your\nvalues. Here's an example of `action.json` with changes for `ExampleAction`: \n\n```text\n{\n \"actions\": [\n {\n \"description\": \"Default welcome intent\",\n \"name\": \"MAIN\",\n \"fulfillment\": {\n \"conversationName\": \"ExampleAction\"\n },\n \"intent\": {\n \"name\": \"actions.intent.MAIN\",\n \"trigger\": {\n \"queryPatterns\": [\n \"talk to ExampleAction\"\n ]\n }\n }\n }\n ],\n \"conversations\": {\n \"ExampleAction\": {\n \"name\": \"ExampleAction\",\n \"url\": \"https://www.example.com/ExampleAction\"\n }\n },\n \"locale\": \"en\"\n}\n```\n\nDefine additional Actions\n-------------------------\n\nYou can provide additional Actions that act as entry points. This lets users\ndisambiguate their intent by letting them specify more details about what they\nwant to do (for example, *\"Hey Google, talk to ExampleAction to find me some\nshoes.\"*).\n\nTo define additional Actions:\n\n1. In the `actions` array, specify an Action for every entry point.\n\n For example, the following code shows an additional \"buy\" Action that defines:\n - An intent name of `com.example.ExampleAction.BUY`\n - `parameters` to parse from the user input when this intent is triggered. This is useful if you need specific data from the Action phrase when users invoke the Action.\n - `queryPatterns` that define what users need to say to trigger the intent. [Query patterns](/assistant/df-asdk/reference/action-package/QueryPatterns) can include Schema.org types that define parameters to parse.\n\n ```carbon\n {\n \"description\": \"Direct access\",\n \"name\": \"BUY\",\n \"fulfillment\": {\n \"conversationName\": \"ExampleAction\"\n },\n \"intent\": {\n \"name\": \"com.example.ExampleAction.BUY\",\n \"parameters\": [\n {\n \"name\": \"color\",\n \"type\": \"org.schema.type.Color\"\n }\n ],\n \"trigger\": {\n \"queryPatterns\": [\n \"find some $org.schema.type.Color:color sneakers\",\n \"buy some blue suede shoes\",\n \"get running shoes\"\n ]\n }\n }\n }\n \n ```\n| Note: We recommend around 10 `queryPatterns` phrases for each intent. These query patterns are used by Google for Action ranking and discovery. They should be representative of your Action's capabilities and indicate how users might want to invoke your Actions.\n2. Specify the fulfillment for this intent by specifying a `conversationName`\n that corresponds to an item in the `conversations` object.\n\n ```text\n {\n \"conversations\": {\n \"ExampleAction\": {\n \"name\": \"ExampleAction\",\n \"url\": \"https://www.example.com/ExampleAction\"\n }\n }\n }\n \n ```\n| Note: You typically will only need one fulfillment endpoint, but Action packages support many.\n\nHere's an example of a full Action package: \n\n```carbon\n{\n \"actions\": [\n {\n \"description\": \"Default welcome intent\",\n \"name\": \"MAIN\",\n \"fulfillment\": {\n \"conversationName\": \"ExampleAction\"\n },\n \"intent\": {\n \"name\": \"actions.intent.MAIN\",\n \"trigger\": {\n \"queryPatterns\": [\n \"talk to ExampleAction\"\n ]\n }\n }\n },\n {\n \"description\": \"Direct access\",\n \"name\": \"BUY\",\n \"fulfillment\": {\n \"conversationName\": \"ExampleAction\"\n },\n \"intent\": {\n \"name\": \"com.example.ExampleAction.BUY\",\n \"parameters\": [\n {\n \"name\": \"color\",\n \"type\": \"org.schema.type.Color\"\n }\n ],\n \"trigger\": {\n \"queryPatterns\": [\n \"find some $org.schema.type.Color:color sneakers\",\n \"buy some blue suede shoes\",\n \"get running shoes\"\n ]\n }\n }\n }\n ],\n \"conversations\": {\n \"ExampleAction\": {\n \"name\": \"ExampleAction\",\n \"url\": \"https://www.example.com/ExampleAction\"\n }\n },\n \"locale\": \"en\"\n}\n```"]]