Interactive Canvas 是一种基于 Google 助理构建的框架,可让开发者向对话型 Action 添加沉浸式视觉体验。
这种视觉体验是一种互动式 Web 应用,Google 助理在对话中将其作为回应发送给用户。与 Google 助理对话中内嵌的传统富响应不同,Interactive Canvas Web 应用会以全屏 Web 视图的形式呈现。
如果您想在 Action 中执行以下任何操作,则应使用 Interactive Canvas:
创建全屏视觉效果
创建自定义动画和过渡效果
进行数据可视化
创建自定义布局和 GUI
图 1. 使用 Interactive Canvas 构建的互动游戏。
支持的设备
Interactive Canvas 目前可在以下设备上使用:
智能显示屏
Google Nest Hub
Android 移动设备
运作方式
使用 Interactive Canvas 的 Action 与常规对话型 Action 的工作原理类似。用户仍然会与 Google 助理进行来回对话,以实现自己的目标;不过,Interactive Canvas Action 不会在对话中内嵌返回回答,而是向用户发送一个打开全屏 Web 应用的回答。用户会继续通过语音或触摸与 Web 应用互动,直到对话结束。
Actions on Google 平台会将用户的请求路由到 Dialogflow 以匹配 intent。
系统会运行匹配意图的 fulfillment,并向设备发送 HtmlResponse。如果尚未加载,设备会使用该网址加载 Web 应用。
当 Web 应用加载时,它会使用 interactiveCanvas API 注册回调。然后,data 对象的值会传递到 Web 应用的已注册 onUpdate 回调中。在我们的示例中,Fulfillment 会发送一个 HtmlResponse,其中包含一个 data,该 data 包含一个值为 blue 的变量。
Web 应用的自定义逻辑会读取 HtmlResponse 的 data 值,并进行定义的更改。在我们的示例中,这会将屏幕变为蓝色。
[null,null,["最后更新时间 (UTC):2025-07-24。"],[[["\u003cp\u003eInteractive Canvas lets you build visual, immersive experiences for Google Assistant using web apps rendered full-screen on supported devices.\u003c/p\u003e\n"],["\u003cp\u003eCurrently, Google primarily approves Interactive Canvas Actions designed as gaming experiences.\u003c/p\u003e\n"],["\u003cp\u003eActions using Interactive Canvas require a Dialogflow agent, fulfillment, and a web app that communicate through the Interactive Canvas API and HtmlResponse.\u003c/p\u003e\n"],["\u003cp\u003eBuilding with Interactive Canvas adds visual elements and interactions to your Action by sending a web app URL to the device, allowing two-way communication between your Action and the web app.\u003c/p\u003e\n"],["\u003cp\u003eExpect longer Google review times for Actions utilizing Interactive Canvas.\u003c/p\u003e\n"]]],[],null,["# Overview (Dialogflow)\n\n**Note:** Actions that use Interactive Canvas take slightly longer for Google's review team to test and approve. Allow extra time in your release process to account for this. \n\nInteractive Canvas is a framework built on the Google Assistant that allows\ndevelopers to add visual, immersive experiences to conversational Actions.\nThis visual experience is an interactive web app that the Assistant sends as a\nresponse to the user in conversation. Unlike traditional\n[rich responses](/assistant/df-asdk/rich-responses) that exist\nin-line in an Assistant conversation, the Interactive Canvas web app renders\nas a full-screen web view.\n\nYou should use Interactive Canvas if you want to do any of the following in\nyour Action:\n\n- Create full-screen visuals\n- Create custom animations and transitions\n- Do data visualization\n- Create custom layouts and GUIs\n\n**Figure 1.** An interactive game built using Interactive Canvas. **Note:** At this time, Google is only approving Actions that are gaming experiences.\n\nSupported devices\n-----------------\n\nInteractive Canvas is currently available on the following devices:\n\n- Smart Displays\n- Google Nest Hubs\n- Android mobile devices\n\n | **Note:** For Canvas to work on Android mobile devices, your AGSA (Android Google Search App) must be version 9.86 or above.\n\nHow it works\n------------\n\nAn Action that uses Interactive Canvas works similarly to a regular conversational\nAction. The user still has a back-and-forth conversation with the Assistant to\nfulfill their goal; however, instead of returning responses in-line in the\nconversation, an Interactive Canvas Action sends a response to the user that\nopens a full-screen web app. The user continues to interact with the web app\nthrough voice or touch until the conversation is over.\n\nThere are several components to an Action that uses Interactive Canvas:\n\n- **[Conversational Action](/assistant/df-asdk/overview):** An Action that uses a conversational interface to fulfill user requests. Interactive Canvas Actions use web views to render responses instead of rich cards or simple text and voice responses. Conversational Actions use the following components:\n - **[Dialogflow agent](https://cloud.google.com/dialogflow/docs/agents-overview)**: A project in Dialogflow that you customize to converse with your Action users.\n - **[Fulfillment](https://cloud.google.com/dialogflow/docs/fulfillment-overview)**: Code that is deployed as a webhook that implements the conversational logic for your Dialogflow agent and communicates with your web app.\n- **Web app:** A front-end web app with customized visuals that your Action sends as a response to users during a conversation. You build the web app with web standards like HTML, JavaScript, and CSS.\n\nThe conversational Action and web app communicate with each other using the\nfollowing:\n\n- **[Interactive Canvas API](/assistant/df-asdk/interactivecanvas/reference/interactivecanvas):** A JavaScript API that you include in the web app to enable communication between the web app and your conversational Action.\n- **[`HtmlResponse`](/assistant/conversational/reference/rest/Shared.Types/AppResponse#htmlresponse)** : A response that contains a URL of the web app and data to pass it. You can use the [Node.js](https://actions-on-google.github.io/actions-on-google-%20%20%20nodejs/2.10.0/classes/_service_actionssdk_conversation_response_html_.htmlresponse.html) or [Java](https://github.com/actions-on-google/actions-on-google-java) client libraries to return an `HtmlResponse`.\n\nTo illustrate how Interactive Canvas works, imagine a hypothetical Action\ncalled *Cool Colors* that changes the device screen color to a color the user\nspecifies. After the user invokes the Action, the flow looks like the following:\n\n1. The user says `Turn the screen blue` to the Assistant device.\n2. The Actions on Google platform routes the user's request to Dialogflow to match an intent.\n3. The fulfillment for the matched intent runs and an `HtmlResponse` is sent to the device. The device uses the URL to load the web app if it has not yet been loaded.\n4. When the web app loads, it registers callbacks with the `interactiveCanvas` API. The `data` object's value is then passed into the registered `onUpdate` callback of the web app. In our example, the fulfillment sends an `HtmlResponse` with a `data` that includes a variable with the value of `blue`.\n5. The custom logic for your web app reads the `data` value of the `HtmlResponse` and makes the defined changes. In our example, this turns the screen blue.\n6. `interactiveCanvas` sends the callback update to the device.\n\nNext steps\n----------\n\nTo learn how to build an Interactive Canvas Action,\nsee the [Build Overview](/assistant/df-asdk/interactivecanvas/build) page.\n\nTo see the code for a complete Interactive Canvas Action, see the\n[sample](https://github.com/actions-on-google/dialogflow-interactive-canvas-nodejs)."]]