在典型的 Actions on Google 互动场景中,用户通过说出指令来调用 Action。为了提供响应,Actions on Google 会查找与用户调用的 Action 匹配的执行方式,并在其中发送请求。
一旦 Actions on Google 确定您的执行方式与用户调用的匹配情况合适,它就会向执行方式端点发送一个包含 JSON 载荷以及用户请求信息的 HTTP 请求,从而启动对话会话。您的执行方式会解析请求并返回包含 JSON 载荷的响应。然后,Actions on Google 会将该载荷转换为向用户呈现的语音和多媒体输出。
图 1. Actions on Google 通过 Actions SDK 调用您的执行方式。
如需详细了解 Actions on Google 通过 Actions SDK 调用执行方式时的 JSON 载荷格式,请参阅对话网络钩子格式。
Dialogflow 请求和响应
创建 Action 时,您可以选择使用 Dialogflow 来简化构建对话界面的任务。在这种情况下,Dialogflow 充当 Actions on Google 与您的 fulfillment 之间的代理。Actions on Google 会将 HTTP/JSON 请求发送到 Dialogflow,而不是将其直接发送到您的执行方式端点。
[null,null,["最后更新时间 (UTC):2023-12-02。"],[[["Actions on Google communicates with your fulfillment service through webhooks, sending JSON payloads that describe user requests."],["Your fulfillment service needs to process these requests, generate appropriate JSON responses, and send them back to the Assistant."],["There are two main webhook formats: Dialogflow webhook format and Conversation webhook format, depending on whether you use Dialogflow or Actions SDK."],["Webhooks can handle different request types like invocation requests, conversation requests, and helper results, each with specific JSON structures."],["Dialogflow can act as a proxy between Actions on Google and your fulfillment, handling the communication and format conversions."]]],["Actions on Google uses webhooks to communicate with fulfillment services, sending HTTP POST requests with JSON payloads. Fulfillment services must parse these requests and respond with appropriately formatted JSON. There are two main webhook formats: Dialogflow and Conversation, corresponding to whether Dialogflow acts as a proxy. Webhook requests can be invocations, conversation turns, or helper results. The fulfillment reads parameters from the request payload and sends a reply back to the Assistant.\n"]]