Method: spaces.messages.update
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
更新消息。patch
方法和 update
方法之间存在差异。patch
方法使用 patch
请求,而 update
方法使用 put
请求。我们建议使用 patch
方法。如需查看示例,请参阅更新消息。
支持以下类型的身份验证:
使用授权范围进行应用身份验证:
https://www.googleapis.com/auth/chat.bot
使用以下授权范围之一进行用户身份验证:
https://www.googleapis.com/auth/chat.messages
https://www.googleapis.com/auth/chat.import
(仅限“导入模式聊天室”)
使用应用身份验证时,请求只能更新调用 Chat 应用创建的消息。
HTTP 请求
PUT https://chat.googleapis.com/v1/{message.name=spaces/*/messages/*}
网址采用 gRPC 转码语法。
路径参数
参数 |
message.name |
string
标识符。消息的资源名称。 格式:spaces/{space}/messages/{message} 其中,{space} 是发布消息的聊天室的 ID,{message} 是系统为消息分配的 ID。例如 spaces/AAAAAAAAAAA/messages/BBBBBBBBBBB.BBBBBBBBBBB 。 如果您在创建消息时设置了自定义 ID,则可以使用此 ID 在请求中指定消息,方法是将 {message} 替换为 clientAssignedMessageId 字段中的值。例如 spaces/AAAAAAAAAAA/messages/client-custom-name 。如需了解详情,请参阅为消息命名。
|
查询参数
参数 |
updateMask |
string (FieldMask format)
必需。要更新的字段路径。使用英文逗号分隔多个值,或使用 * 更新所有字段路径。 目前支持的字段路径:
|
allowMissing |
boolean
可选。如果找不到 true 和相应消息,系统会创建新消息并忽略 updateMask 。指定的 message ID 必须是由客户端分配的,否则请求会失败。
|
请求正文
请求正文包含一个 Message
实例。
响应正文
如果成功,则响应正文包含一个 Message
实例。
授权范围
需要以下 OAuth 范围之一:
https://www.googleapis.com/auth/chat.bot
https://www.googleapis.com/auth/chat.import
https://www.googleapis.com/auth/chat.messages
如需了解详情,请参阅授权指南。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-13。
[null,null,["最后更新时间 (UTC):2025-08-13。"],[[["\u003cp\u003eUpdates a Google Chat message using the \u003ccode\u003ePUT\u003c/code\u003e method, preferably with the \u003ccode\u003epatch\u003c/code\u003e approach for partial modifications.\u003c/p\u003e\n"],["\u003cp\u003eRequires providing the message's resource name in the URL path for identification.\u003c/p\u003e\n"],["\u003cp\u003eAllows specifying fields to update using \u003ccode\u003eupdateMask\u003c/code\u003e and supports creating a new message if the original is missing with \u003ccode\u003eallowMissing\u003c/code\u003e set to \u003ccode\u003etrue\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication can be done using app authentication or user authentication, with app authentication restricting updates to messages created by the calling Chat app.\u003c/p\u003e\n"],["\u003cp\u003eNeeds authorization with specific OAuth scopes like \u003ccode\u003echat.bot\u003c/code\u003e, \u003ccode\u003echat.import\u003c/code\u003e, or \u003ccode\u003echat.messages\u003c/code\u003e.\u003c/p\u003e\n"]]],["This describes updating messages in Google Chat using either `patch` or `put` requests, recommending `patch`. The `PUT` request uses the format `https://chat.googleapis.com/v1/{message.name=spaces/*/messages/*}`. Updating requires specifying the `message.name` path parameter and the `updateMask` query parameter to identify fields to modify. Optional `allowMissing` creates a new message if one is not found. The request and response body are `Message` instances. Authorization requires specific OAuth scopes. App authentication can update messages from the calling app only.\n"],null,["# Method: spaces.messages.update\n\n- [HTTP request](#body.HTTP_TEMPLATE)\n- [Path parameters](#body.PATH_PARAMETERS)\n- [Query parameters](#body.QUERY_PARAMETERS)\n- [Request body](#body.request_body)\n- [Response body](#body.response_body)\n- [Authorization scopes](#body.aspect)\n- [Try it!](#try-it)\n\nUpdates a message. There's a difference between the `patch` and `update` methods. The `patch` method uses a `patch` request while the `update` method uses a `put` request. We recommend using the `patch` method. For an example, see [Update a message](https://developers.google.com/workspace/chat/update-messages).\n\nSupports the following types of [authentication](https://developers.google.com/workspace/chat/authenticate-authorize):\n\n- [App authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-app) with the authorization scope:\n\n - `https://www.googleapis.com/auth/chat.bot`\n- [User authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user) with one of the following authorization scopes:\n\n - `https://www.googleapis.com/auth/chat.messages`\n - `https://www.googleapis.com/auth/chat.import` (import mode spaces only)\n\nWhen using app authentication, requests can only update messages created by the calling Chat app.\n\n### HTTP request\n\n`PUT https://chat.googleapis.com/v1/{message.name=spaces/*/messages/*}`\n\nThe URL uses [gRPC Transcoding](https://google.aip.dev/127) syntax.\n\n### Path parameters\n\n| Parameters ||\n|----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `message.name` | `string` Identifier. Resource name of the message. Format: `spaces/{space}/messages/{message}` Where `{space}` is the ID of the space where the message is posted and `{message}` is a system-assigned ID for the message. For example, `spaces/AAAAAAAAAAA/messages/BBBBBBBBBBB.BBBBBBBBBBB`. If you set a custom ID when you create a message, you can use this ID to specify the message in a request by replacing `{message}` with the value from the `clientAssignedMessageId` field. For example, `spaces/AAAAAAAAAAA/messages/client-custom-name`. For details, see [Name a message](https://developers.google.com/workspace/chat/create-messages#name_a_created_message). |\n\n### Query parameters\n\n| Parameters ||\n|----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `updateMask` | `string (`[FieldMask](https://protobuf.dev/reference/protobuf/google.protobuf/#field-mask)` format)` Required. The field paths to update. Separate multiple values with commas or use `*` to update all field paths. Currently supported field paths: - `text` - `attachment` - `cards` (Requires [app authentication](/chat/api/guides/auth/service-accounts).) - `cardsV2` (Requires [app authentication](/chat/api/guides/auth/service-accounts).) - `accessoryWidgets` (Requires [app authentication](/chat/api/guides/auth/service-accounts).) - `quotedMessageMetadata` (Only allows removal of the quoted message.) |\n| `allowMissing` | `boolean` Optional. If `true` and the message isn't found, a new message is created and `updateMask` is ignored. The specified message ID must be [client-assigned](https://developers.google.com/workspace/chat/create-messages#name_a_created_message) or the request fails. |\n\n### Request body\n\nThe request body contains an instance of [Message](/workspace/chat/api/reference/rest/v1/spaces.messages#Message).\n\n### Response body\n\nIf successful, the response body contains an instance of [Message](/workspace/chat/api/reference/rest/v1/spaces.messages#Message).\n\n### Authorization scopes\n\nRequires one of the following OAuth scopes:\n\n- `https://www.googleapis.com/auth/chat.bot`\n- `https://www.googleapis.com/auth/chat.import`\n- `https://www.googleapis.com/auth/chat.messages`\n\nFor more information, see the [Authorization guide](/workspace/chat/authenticate-authorize)."]]