以这种方式重新发送 MESSAGE 互动事件时,该事件应与原始事件完全相同;不过,在某些情况下,MESSAGE 互动事件可能会有所不同。例如,当某条消息同时提及 Chat 应用 A 和 Chat 应用 B 时,如果 Chat 应用 A 在通过 Chat 应用 B 进行身份验证之前回复了常规消息,则用户能够修改该消息。在这种情况下,聊天应用 B 会在用户完成身份验证和配置后收到修改后的消息文本。
在 Chat 之外对 Chat 用户进行身份验证
在某些情况下(例如为 API 请求 OAuth 授权),您的应用需要链接到 Chat 之外的网址,同时保持用户身份。在这些情况下,识别用户的最佳方式是使用 Google 登录保护目标应用。
使用登录期间签发的身份令牌获取用户 ID。sub 声明包含用户的唯一 ID,可与 Google Chat 中的用户 ID 相关联。
虽然这两个 ID 并不完全相同,但可以强制转换。如需将 sub 声明的值强制转换为 Google Chat users/{user},请在值前面添加 users/。例如,声明值 123 相当于发送给 Chat 应用的消息中的用户名 users/123。
[null,null,["最后更新时间 (UTC):2025-08-29。"],[[["\u003cp\u003eGoogle Chat apps can connect with external services for enhanced functionality, such as account linking and data access.\u003c/p\u003e\n"],["\u003cp\u003eTo enable external connections, Chat apps use a configuration URL that prompts users to complete setup outside of Chat.\u003c/p\u003e\n"],["\u003cp\u003eUpon successful configuration, the original message in Chat becomes public and is resent to the app for processing.\u003c/p\u003e\n"],["\u003cp\u003eGoogle Sign-in is recommended for authenticating Chat users in external systems by using the identity token's \u003ccode\u003esub\u003c/code\u003e claim.\u003c/p\u003e\n"],["\u003cp\u003eEnsure the identity token's integrity is validated before using the user ID for any operations.\u003c/p\u003e\n"]]],["To connect a Google Chat app with external services, use a configuration URL returned in a `REQUEST_CONFIG` response, prompting users for authentication or configuration. This URL should include the `configCompleteRedirectUrl` provided by Chat, redirecting users back upon completion. Successful redirection erases the prompt, makes the original message public, and resends the original message to the Chat app. To maintain user identity outside Chat, use Google Sign-in and validate the integrity of the `sub` token.\n"],null,["# Connect a Chat app with other services and tools\n\n| **Note:** This guide explains how to build an interactive Chat app\n| using *Chat API interaction events* . You can also build your\n| Chat app as a Google Workspace add-on. To learn about which framework\n| to use, see [Build an interactive\n| Google Chat app](/workspace/chat/interact-users-overview).\n\n\u003cbr /\u003e\n\nThis page describes how to connect a Google Chat app with a service\nor tool that is outside of Google Chat. While Chat apps are\npowerful on their own, they often work in concert with other systems and require\ncompanion applications to connect accounts, authorize data access, display\nadditional data, or configure user preferences.\n\nPrerequisites\n-------------\n\n\u003cbr /\u003e\n\nA Google Chat app that's configured to receive and respond to [interaction events](/workspace/chat/receive-respond-interactions). To create an interactive Chat app, complete one of the following quickstarts based on the [app architecture](/workspace/chat/structure) that you want to use:\n\n- [HTTP service](/workspace/chat/quickstart/gcf-app) with Google Cloud Functions\n- [Google Apps Script](/workspace/chat/quickstart/apps-script-app)\n- [Google Cloud Dialogflow CX](/workspace/chat/build-dialogflow-chat-app-natural-language)\n- [Google Cloud Pub/Sub](/workspace/chat/quickstart/pub-sub)\n\nRequest Chat app configuration from a user\n------------------------------------------\n\nIf completing a request requires additional configuration that can't be\ncompleted directly in the Chat app, return a\nconfiguration URL to the user as part of a normal reply, or present it privately,\nin the following form: \n\n```\n{\n \"actionResponse\": {\n \"type\": \"REQUEST_CONFIG\",\n \"url\": \"CONFIGURATION_URL\"\n }\n}\n```\n\nThis tells Google Chat to present the user with a private prompt, where\n\u003cvar translate=\"no\"\u003eCONFIGURATION_URL\u003c/var\u003e is a link\nfor the user to visit for additional authentication, authorization, or\nconfiguration. A `REQUEST_CONFIG` response is mutually exclusive with a regular\nresponse message. Any text, cards, or other attributes are ignored.\n\nComplete the configuration request\n----------------------------------\n\nEvery\n[`MESSAGE`, `ADDED_TO_SPACE`, and `APP_COMMAND` interaction event](/workspace/chat/api/reference/rest/v1/EventType)\nthat your Chat app receives also includes the field\n`configCompleteRedirectUrl`. You must encode this URL in your\nconfiguration URL to be used on completion of the process. Redirecting to this\nURL signals to Google Chat that the configuration request was fulfilled.\n\nWhen your Chat app starts, the flow depends on the\nspecific message received. In response to a message like `@app help`, a\nChat app should respond with a message without\nrequiring additional configuration.\n\nWhen a user is successfully redirected to the `configCompleteRedirectUrl`\nprovided in the original message, Google Chat performs the following steps:\n\n1. Erase the prompt that was displayed to the initiating user.\n2. Convert the original message to public, making it visible to other members of the space.\n3. Send the original message to the same Chat app a second time.\n\nVisiting a `configCompleteRedirectUrl` only affects a single user message.\nIf a user has tried to message a Chat app multiple\ntimes and as a result received multiple prompts, clicking through a particular\nprompt and completing the authentication and configuration process only affects\nthat particular message. Other messages aren't changed.\n\nWhen a `MESSAGE` interaction event is resent in this way, it should be identical\nto the original event; however, there are some situations where `MESSAGE`\ninteraction events can differ. For example, when a message mentions both\nChat app A and Chat app B,\nthe user is able to edit the message if Chat app A\nresponds with a regular message before authenticating with\nChat app B. In this case,\nChat app B receives the edited message text after the\nuser completes authentication and configuration.\n\nAuthenticate the Chat user outside of Chat\n------------------------------------------\n\nIn some cases, such as requesting OAuth authorization for an API, your app needs\nto link to a URL outside of Chat while maintaining the user\nidentity. The best way to identify the user in these cases is to guard the\ndestination app with [Google Sign-in](/identity).\n\nUse the\n[identity token](/identity/sign-in/web/backend-auth)\nissued during sign-in to get the user ID. The `sub` claim contains the user's\nunique ID and can be correlated with the user ID from Google Chat.\n| **Caution:** Always [validate the integrity](/identity/sign-in/web/backend-auth#verify-the-integrity-of-the-id-token) of the token before accepting the asserted user ID.\n\nWhile the two IDs aren't exactly identical, they can be coerced. To\ncoerce the value of the `sub` claim to a Google Chat `users/{user}`, prepend\nthe value with `users/`. For example, the claim value of `123` is equivalent\nto the username `users/123` in messages to your\nChat app.\n\nRelated topics\n--------------\n\n- [Receive and respond to user interaction](/workspace/chat/receive-respond-interactions#receive)\n- The [MyProfile app example](https://github.com/googleworkspace/google-chat-samples/tree/main/python/auth-app) uses the identity token from the Google Sign-in response to identify the user."]]