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 trò chuyện giúp bạn mở rộng Trợ lý Google qua giao diện trò chuyện của riêng bạn để người dùng có thể truy cập vào các sản phẩm và dịch vụ của bạn. Các hành động sẽ tận dụng công cụ hiểu ngôn ngữ tự nhiên (NLU) mạnh mẽ của Trợ lý để xử lý và hiểu ngôn ngữ tự nhiên đầu vào, cũng như thực hiện các nhiệm vụ dựa trên thông tin đầu vào đó.
Tổng quan
Hành động trò chuyện là một đối tượng đơn giản xác định một điểm truy cập (gọi là lệnh gọi) vào một cuộc trò chuyện:
Lời gọi xác định cách người dùng cho Trợ lý biết rằng họ muốn bắt đầu cuộc trò chuyện bằng một trong các Hành động của bạn. Lệnh gọi của Hành động được xác định bằng một ý định được so khớp khi người dùng yêu cầu Hành động đó.
Cuộc trò chuyện xác định cách người dùng tương tác với một Hành động sau khi Hành động đó được gọi. Bạn xây dựng các cuộc trò chuyện có ý định, loại, cảnh và lời nhắc.
Ngoài ra, Hành động của bạn có thể uỷ quyền làm thêm công việc cho phương thức thực hiện, là các dịch vụ web giao tiếp với Hành động của bạn thông qua webhook. Điều này cho phép bạn xác thực dữ liệu, gọi các dịch vụ web khác, thực hiện logic nghiệp vụ và nhiều tác vụ khác.
Bạn gói một hoặc nhiều Hành động lại với nhau (dựa trên các trường hợp sử dụng quan trọng đối với người dùng) vào một vùng chứa logic được gọi là dự án Actions (Hành động).
Dự án Hành động của bạn chứa toàn bộ mô hình gọi (tập hợp tất cả các lệnh gọi), cho phép người dùng bắt đầu tại các vị trí hợp lý trong mô hình cuộc trò chuyện (tất cả những điều người dùng có thể nói và tất cả các cách bạn có thể phản hồi lại cho người dùng).
Hình 1. Một tập hợp các Hành động đóng vai trò là điểm truy cập vào một mô hình cuộc trò chuyện. Những ý định đủ điều kiện để gọi được coi là ý định chung.
Lời gọi
Lệnh gọi được liên kết với tên hiển thị đại diện cho thương hiệu, tên hoặc cá tính mà cho phép người dùng yêu cầu Trợ lý gọi Hành động của bạn.
Người dùng có thể sử dụng tên hiển thị này (gọi là lệnh gọi chính) hoặc sử dụng kết hợp với các cụm từ liên kết sâu (không bắt buộc) để gọi Hành động của bạn.
Ví dụ: người dùng có thể nói những cụm từ sau để gọi 3 Hành động riêng biệt trong một dự án có tên hiển thị là "Thông tin về Google":
"Ok Google, trao đổi với Thông tin về Google"
"Ok Google, hãy trao đổi với Thông tin về Google để biết thông tin thực tế về công ty"
"Ok Google, hãy trao đổi với Thông tin về Google để biết thông tin lịch sử"
Lệnh gọi đầu tiên trong ví dụ này là lệnh gọi chính. Lệnh gọi này liên kết với một ý định đặc biệt của hệ thống có tên là actions.intent.MAIN. Lệnh gọi thứ hai và thứ ba là các lệnh gọi liên kết sâu cho phép bạn chỉ định các cụm từ bổ sung cho phép người dùng yêu cầu chức năng cụ thể. Các lệnh gọi này tương ứng với ý định của người dùng mà bạn chỉ định là toàn cầu. Mỗi lệnh gọi trong ví dụ này cung cấp một điểm truy cập vào một cuộc trò chuyện và tương ứng với một Hành động duy nhất.
Hình 2. Ví dụ về lệnh gọi chính
Hình 2 mô tả một quy trình gọi chính điển hình:
Khi người dùng yêu cầu một Hành động, họ thường yêu cầu Trợ lý bằng tên hiển thị của bạn.
Trợ lý so khớp yêu cầu của người dùng với ý định tương ứng khớp với yêu cầu. Trong trường hợp này, giá trị sẽ là actions.intent.MAIN.
Hành động sẽ được thông báo về ý định trùng khớp và phản hồi bằng lời nhắc tương ứng để bắt đầu cuộc trò chuyện với người dùng.
Giao lưu và trò chuyện
Cuộc trò chuyện xác định cách người dùng tương tác với một Hành động sau khi Hành động đó được gọi. Bạn sẽ tạo các hoạt động tương tác này bằng cách xác định dữ liệu đầu vào hợp lệ của người dùng cho cuộc trò chuyện, logic để xử lý dữ liệu đầu vào đó và các lời nhắc tương ứng để trả lời người dùng. Hình minh hoạ và nội dung giải thích sau đây cho bạn biết cách hoạt động của một lượt trò chuyện điển hình với các thành phần cấp thấp của cuộc trò chuyện: ý định, loại, cảnh và lời nhắc.
Hình 3. Ví dụ về cuộc trò chuyện
Hình 3 mô tả một lượt trò chuyện điển hình:
Khi người dùng nói điều gì đó, NLU của Trợ lý sẽ so khớp dữ liệu đầu vào với một ý định phù hợp. Một ý định sẽ được so khớp nếu mô hình ngôn ngữ cho ý định đó có thể khớp gần đúng hoặc chính xác với hoạt động đầu vào của người dùng. Bạn xác định mô hình ngôn ngữ bằng cách chỉ định cụm từ đào tạo hoặc ví dụ về những điều mà người dùng có thể muốn nói. Trợ lý sẽ nhận các cụm từ huấn luyện này và mở rộng các cụm từ đó để tạo mô hình ngôn ngữ của ý định.
Khi NLU khớp với một ý định, Trợ lý có thể trích xuất các tham số mà bạn cần từ dữ liệu đầu vào. Các tham số này có loại liên kết, chẳng hạn như ngày hoặc số. Bạn chú thích các phần cụ thể trong các cụm từ huấn luyện của một ý định để chỉ định những tham số bạn muốn trích xuất.
Sau đó, một cảnh sẽ xử lý ý định trùng khớp. Bạn có thể coi cảnh là đơn vị thực thi logic của một Hành động, thực hiện phần việc khó khăn và thực hiện logic cần thiết để thúc đẩy cuộc trò chuyện. Các cảnh chạy trong một vòng lặp, mang đến vòng đời thực thi linh hoạt cho phép bạn làm những việc như xác thực tham số ý định, lấp đầy vị trí, gửi lời nhắc lại cho người dùng và làm nhiều việc khác.
Khi thực thi xong, cảnh thường sẽ gửi lại lời nhắc cho người dùng để tiếp tục cuộc trò chuyện hoặc có thể kết thúc cuộc trò chuyện nếu thích hợp.
Quy trình thực hiện đơn hàng
Trong khi gọi hoặc một cuộc trò chuyện, Hành động của bạn có thể kích hoạt một webhook thông báo cho dịch vụ thực hiện một số thao tác.
Hình 4. Ví dụ về cuộc trò chuyện
Hình 4 mô tả cách bạn có thể sử dụng phương thức thực hiện để tạo câu lệnh. Đây là một cách phổ biến để sử dụng phương thức thực hiện:
Tại các thời điểm cụ thể trong quá trình thực thi Hành động của bạn, hành động đó có thể kích hoạt một webhook gửi yêu cầu đến một trình xử lý webhook đã đăng ký (dịch vụ thực hiện của bạn) với tải trọng JSON.
Phương thức thực hiện của bạn sẽ xử lý yêu cầu, chẳng hạn như gọi API REST để tra cứu dữ liệu hoặc xác thực một số dữ liệu trong tải trọng JSON. Một cách rất phổ biến để sử dụng phương thức thực hiện là tạo lời nhắc động trong thời gian chạy để các cuộc trò chuyện của bạn phù hợp hơn với người dùng hiện tại.
Phương thức thực hiện sẽ trả về phản hồi cho Hành động có chứa tải trọng JSON. Mô-đun này có thể sử dụng dữ liệu từ tải trọng để tiếp tục thực thi và phản hồi lại người dùng.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[[["\u003cp\u003eConversational Actions extend Google Assistant, letting you create conversational interfaces for your services using natural language understanding.\u003c/p\u003e\n"],["\u003cp\u003eActions are invoked by users through specific phrases, triggering a conversation flow defined by intents, types, scenes, and prompts.\u003c/p\u003e\n"],["\u003cp\u003eFulfillment webhooks can be used to enhance Actions by validating data, calling external services, and generating dynamic prompts during conversations.\u003c/p\u003e\n"],["\u003cp\u003eActions are grouped within an Actions project which manages the invocation model and overall conversation flow.\u003c/p\u003e\n"]]],["Conversational Actions enable interactions with Google Assistant via natural language. Users initiate these interactions through **invocations**, using a display name or deep links. **Conversations** follow, where Assistant's NLU matches user input to **intents**, extracting **parameters**. **Scenes** then process these intents, executing logic and sending **prompts**. **Fulfillment** services handle tasks like data validation or dynamic prompt generation through webhooks, allowing actions to interact with web services and tailor responses. An **Actions project** bundles actions together.\n"],null,["# Conversational Actions let you extend Google Assistant with your own\nconversational interfaces that give users access to your products and\nservices. Actions leverage Assistant's powerful natural language\nunderstanding (NLU) engine to process and understand natural language input\nand carry out tasks based on that input.\n\nOverview\n--------\n\nA Conversational Action is a simple object that defines an\nentry point (referred to as invocation) into a conversation:\n\n- An **invocation** defines how users tell Assistant they want to start a conversation with one of your Actions. An Action's invocation is defined by a single [intent](/assistant/conversational/intents) that gets matched when users request the Action.\n- A **conversation** defines how users interact with an Action after it's invoked. You build conversations with [intents](/assistant/conversational/intents), [types](/assistant/conversational/types), [scenes](/assistant/conversational/scenes), and [prompts](/assistant/conversational/prompts).\n- In addition, your Actions can delegate extra work to **fulfillment**, which are web services that communicate with your Actions via webhooks. This lets you do data validation, call other web services, carry out business logic, and more.\n\nYou bundle one or many Actions together, based on the use cases that are\nimportant for your users, into a logical container called an Actions project.\nYour Actions project contains your entire invocation model (the collection of\nall your invocations), which lets users start at logical places in your\nconversation model (all the possible things users can say and all the possible\nways you respond back to users).\n**Figure 1** . A collection of Actions that serve as entry points into a conversation model. Intents that are eligible for invocation are considered to be *global*.\n\nInvocation\n----------\n\nInvocation is associated with a **display name** that represents a brand,\nname, or persona that lets users ask Assistant to invoke your Actions.\nUsers can use this display name on its own (called the main invocation) or in\ncombination with optional, **deep link** phrases to invoke your Actions.\n\nFor example, users can say the following phrases to invoke three separate\nActions in an project with a display name of \"Facts about Google\":\n\n- *\"Ok Google, talk to Facts about Google\"*\n- *\"Ok Google, talk to Facts about Google to get company facts\"*\n- *\"Ok Google, talk to Facts about Google to get history facts\"*\n\nThe first invocation in the example is the **main invocation** . This\ninvocation is associated with a special system intent named\n`actions.intent.MAIN`. The second and third invocations are deep link\ninvocations that let you specify additional phrases that let users ask for\nspecific functionality. These invocations correspond to user intents that you\ndesignated as global. Each invocation in this example provides an entry point\ninto a conversation and corresponds to a single Action.\n**Figure 2**. Example of main invocation\n\nFigure 2 describes a typical main invocation flow:\n\n1. When users request an Action, they typically ask Assistant for it by your display name.\n2. Assistant matches the user's request with the corresponding intent that matches the request. In this case, it would be `actions.intent.MAIN`.\n3. The Action is notified of the intent match and responds with the corresponding prompt to start a conversation with the user.\n\nConversation\n------------\n\nConversation defines how users interact with an Action after it's invoked. You\nbuild these interactions by defining the valid user input for your\nconversation, the logic to process that input, and the corresponding prompts\nto respond back to the user with. The following figure and explanation shows\nyou how a typical conversation turn works with a conversation's low level\ncomponents: [intents](/assistant/conversational/intents), [types](/assistant/conversational/types), [scenes](/assistant/conversational/scenes), and\n[prompts](/assistant/conversational/prompts).\n**Figure 3**. Example of a conversation\n\nFigure 3 describes a typical conversation turn:\n\n1. When users say something, the Assistant NLU matches the input to an appropriate intent. An intent is matched if the *language model* for that intent can closely or exactly match the user input. You define the language model by specifying *training phrases*, or examples of things users might want to say. Assistant takes these training phrases and expands upon them to create the intent's language model.\n2. When the Assistant NLU matches an intent, it can extract *parameters* that you need from the input. These parameters have *types* associated with them, such as a date or number. You annotate specific parts of an intent's training phrases to specify what parameters you want to extract.\n3. A *scene* then processes the matched intent. You can think of scenes as the logic executors of an Action, doing the heavy lifting and carrying out logic necessary to drive a conversation forward. Scenes run in a loop, providing a flexible execution lifecycle that lets you do things like validate intent parameters, do slot filling, send prompts back to the user, and more.\n4. When a scene is done executing, it typically sends a prompt back to users to continue the conversation or can end the conversation if appropriate.\n\nFulfillment\n-----------\n\nDuring invocation or a conversation, your Action can trigger a webhook that\nnotifies a fulfillment service to carry out some tasks.\n**Figure 4**. Example of a conversation\n\nFigure 4 describes how you can use fulfillment to generate prompts, a common\nway to use fulfillment:\n\n1. At specific points of your Action's execution, it can trigger a webhook that sends a request to a registered webhook handler (your fulfillment service) with a JSON payload.\n2. Your fulfillment processes the request, such as calling a REST API to do some data lookup or validating some data from the JSON payload. A very common way to use fulfillment is to generate a dynamic prompt at runtime so your conversations are more tailored to the current user.\n3. Your fulfillment returns a response back to your Action containing a JSON payload. It can use the data from the payload to continue it's execution and respond back to the user."]]