Method: spaces.messages.create
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Erstellt eine Nachricht in einem Google Chat-Gruppenbereich. Ein Beispiel finden Sie unter Nachricht senden.
Unterstützt die folgenden Authentifizierungstypen:
- App-Authentifizierung mit dem Autorisierungsbereich:
https://www.googleapis.com/auth/chat.bot
- Nutzerauthentifizierung mit einem der folgenden Autorisierungsbereiche:
https://www.googleapis.com/auth/chat.messages.create
https://www.googleapis.com/auth/chat.messages
https://www.googleapis.com/auth/chat.import
(nur Gruppenbereiche im Importmodus)
In Google Chat wird der Absender der Nachricht je nach Art der Authentifizierung, die Sie in Ihrer Anfrage verwenden, unterschiedlich zugeordnet.
Auf dem folgenden Bild ist zu sehen, wie eine Nachricht in Google Chat zugeordnet wird, wenn Sie die App-Authentifizierung verwenden. In Google Chat wird die Chat-App als Absender der Nachricht angezeigt. Der Inhalt der Nachricht kann Text (text
), Karten (cardsV2
) und Zubehör-Widgets (accessoryWidgets
) enthalten.

Das folgende Bild zeigt, wie Chat eine Nachricht zuordnet, wenn Sie die Nutzerauthentifizierung verwenden. In Google Chat wird der Nutzer als Absender der Nachricht angezeigt und die Chat-App wird der Nachricht durch Angabe ihres Namens zugeordnet. Der Inhalt der Nachricht darf nur Text (text
) enthalten.

Die maximale Nachrichtengröße, einschließlich des Nachrichteninhalts, beträgt 32.000 Byte.
Bei Webhook-Anfragen enthält die Antwort nicht die vollständige Nachricht. In der Antwort werden neben den Informationen in der Anfrage nur die Felder name
und thread.name
ausgefüllt.
HTTP-Anfrage
POST https://chat.googleapis.com/v1/{parent=spaces/*}/messages
Die URL verwendet die Syntax der gRPC-Transcodierung.
Pfadparameter
Parameter |
parent |
string
Erforderlich. Der Ressourcenname des Gruppenbereichs, in dem eine Nachricht erstellt werden soll. Format: spaces/{space}
|
Suchparameter
Parameter |
threadKey (deprecated) |
string
Optional. Verworfen. Verwenden Sie stattdessen thread.thread_key . ID für den Thread. Unterstützt bis zu 4.000 Zeichen. Wenn Sie einen Thread starten oder ihm eine Nachricht hinzufügen möchten, erstellen Sie eine Nachricht und geben Sie eine threadKey oder die thread.name an. Eine Beispielanwendung finden Sie unter Nachrichtenthreads starten oder beantworten.
|
requestId |
string
Optional. Eine eindeutige Anfrage-ID für diese Nachricht. Wenn Sie eine vorhandene Anfrage-ID angeben, wird die mit dieser ID erstellte Nachricht zurückgegeben, anstatt eine neue Nachricht zu erstellen.
|
messageReplyOption |
enum (MessageReplyOption )
Optional. Gibt an, ob eine Nachricht einen Thread startet oder auf einen antwortet. Nur in benannten Gruppenbereichen unterstützt. Wenn Sie auf Nutzerinteraktionen reagieren, wird dieses Feld ignoriert. Bei Interaktionen innerhalb eines Threads wird die Antwort im selben Thread erstellt. Andernfalls wird die Antwort als neuer Thread erstellt.
|
messageId |
string
Optional. Eine benutzerdefinierte ID für eine Nachricht. Ermöglicht es Chat-Apps, eine Nachricht abzurufen, zu aktualisieren oder zu löschen, ohne die vom System zugewiesene ID im Ressourcennamen der Nachricht (im Feld name der Nachricht) speichern zu müssen. Der Wert für dieses Feld muss die folgenden Anforderungen erfüllen:
- Beginnt mit
client- . Beispiel: client-custom-name ist eine gültige benutzerdefinierte ID, custom-name jedoch nicht.
- Enthält bis zu 63 Zeichen und nur Kleinbuchstaben, Ziffern und Bindestriche.
- Darf innerhalb eines Gruppenbereichs nur einmal vorkommen. Eine Chat-App kann nicht dieselbe benutzerdefinierte ID für unterschiedliche Nachrichten verwenden.
Weitere Informationen
|
Anfragetext
Der Anfragetext enthält eine Instanz von Message
.
Antworttext
Bei Erfolg enthält der Antworttext eine neu erstellte Instanz von Message
.
Autorisierungsbereiche
Erfordert einen der folgenden OAuth-Bereiche:
https://www.googleapis.com/auth/chat.bot
https://www.googleapis.com/auth/chat.import
https://www.googleapis.com/auth/chat.messages
https://www.googleapis.com/auth/chat.messages.create
Weitere Informationen finden Sie im Leitfaden zur Autorisierung.
MessageReplyOption
Gibt an, wie auf eine Nachricht geantwortet werden soll. Weitere Bundesländer werden möglicherweise in Zukunft hinzugefügt.
Enums |
MESSAGE_REPLY_OPTION_UNSPECIFIED |
Standard. Startet einen neuen Thread. Bei Verwendung dieser Option werden alle enthaltenen thread ID oder threadKey ignoriert. |
REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD |
Die Nachricht wird als Antwort auf den Thread erstellt, der durch thread ID oder threadKey angegeben wird. Andernfalls wird mit der Nachricht stattdessen ein neuer Thread gestartet. |
REPLY_MESSAGE_OR_FAIL |
Die Nachricht wird als Antwort auf den Thread erstellt, der durch thread ID oder threadKey angegeben wird. Wenn ein neuer threadKey verwendet wird, wird ein neuer Thread erstellt. Wenn die Nachrichtenerstellung fehlschlägt, wird stattdessen ein NOT_FOUND -Fehler zurückgegeben. |
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
Zuletzt aktualisiert: 2025-07-25 (UTC).
[null,null,["Zuletzt aktualisiert: 2025-07-25 (UTC)."],[[["\u003cp\u003eCreates a message in a Google Chat space, attributing it to the Chat app or user based on authentication.\u003c/p\u003e\n"],["\u003cp\u003eSupports sending text, cards, and widgets using app authentication, while user authentication only allows text.\u003c/p\u003e\n"],["\u003cp\u003eOffers different message reply options for starting new threads or replying within existing ones.\u003c/p\u003e\n"],["\u003cp\u003eRequires specific authorization scopes for the request, such as \u003ccode\u003echat.bot\u003c/code\u003e or \u003ccode\u003echat.messages\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eProvides a way to name a message with a custom ID for easy retrieval and management within a space.\u003c/p\u003e\n"]]],["This document outlines the process for creating messages in Google Chat spaces via the `create()` method, using either user or app authentication. Messages can include text, cards, and widgets, with a maximum size of 32,000 bytes. The process involves a POST request to a specified URL with path parameters for the space and query parameters like `threadKey`, `requestId`, `messageReplyOption` and `messageId`. The request body defines the message content, and the successful response returns the new message details. It also specifies the required OAuth scopes.\n"],null,["# Method: spaces.messages.create\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- [MessageReplyOption](#MessageReplyOption)\n- [Try it!](#try-it)\n\nCreates a message in a Google Chat space. For an example, see [Send a message](https://developers.google.com/workspace/chat/create-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 - `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 - `https://www.googleapis.com/auth/chat.messages.create`\n - `https://www.googleapis.com/auth/chat.messages`\n - `https://www.googleapis.com/auth/chat.import` (import mode spaces only)\n\nChat attributes the message sender differently depending on the type of authentication that you use in your request.\n\nThe following image shows how Chat attributes a message when you use app authentication. Chat displays the Chat app as the message sender. The content of the message can contain text (`text`), cards (`cardsV2`), and accessory widgets (`accessoryWidgets`).\n\nThe following image shows how Chat attributes a message when you use user authentication. Chat displays the user as the message sender and attributes the Chat app to the message by displaying its name. The content of message can only contain text (`text`).\n\nThe maximum message size, including the message contents, is 32,000 bytes.\n\nFor [webhook](https://developers.google.com/workspace/chat/quickstart/webhooks) requests, the response doesn't contain the full message. The response only populates the `name` and `thread.name` fields in addition to the information that was in the request.\n\n### HTTP request\n\n`POST https://chat.googleapis.com/v1/{parent=spaces/*}/messages`\n\nThe URL uses [gRPC Transcoding](https://google.aip.dev/127) syntax.\n\n### Path parameters\n\n| Parameters ||\n|----------|----------------------------------------------------------------------------------------------------------|\n| `parent` | `string` Required. The resource name of the space in which to create a message. Format: `spaces/{space}` |\n\n### Query parameters\n\n| Parameters ||\n|------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `threadKey` **(deprecated)** | `string` Optional. Deprecated: Use [thread.thread_key](/workspace/chat/api/reference/rest/v1/spaces.messages#Message.Thread.FIELDS.thread_key) instead. ID for the thread. Supports up to 4000 characters. To start or add to a thread, create a message and specify a `threadKey` or the [thread.name](/workspace/chat/api/reference/rest/v1/spaces.messages#Message.Thread.FIELDS.name). For example usage, see [Start or reply to a message thread](https://developers.google.com/workspace/chat/create-messages#create-message-thread). |\n| `requestId` | `string` Optional. A unique request ID for this message. Specifying an existing request ID returns the message created with that ID instead of creating a new message. |\n| `messageReplyOption` | `enum (`[MessageReplyOption](/workspace/chat/api/reference/rest/v1/spaces.messages/create#MessageReplyOption)`)` Optional. Specifies whether a message starts a thread or replies to one. Only supported in named spaces. When [responding to user interactions](https://developers.google.com/workspace/chat/receive-respond-interactions), this field is ignored. For interactions within a thread, the reply is created in the same thread. Otherwise, the reply is created as a new thread. |\n| `messageId` | `string` Optional. A custom ID for a message. Lets Chat apps get, update, or delete a message without needing to store the system-assigned ID in the message's resource name (represented in the message `name` field). The value for this field must meet the following requirements: - Begins with `client-`. For example, `client-custom-name` is a valid custom ID, but `custom-name` is not. - Contains up to 63 characters and only lowercase letters, numbers, and hyphens. - Is unique within a space. A Chat app can't use the same custom ID for different messages. For details, see [Name a message](https://developers.google.com/workspace/chat/create-messages#name_a_created_message). |\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 a newly created 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- `https://www.googleapis.com/auth/chat.messages.create`\n\nFor more information, see the [Authorization guide](/workspace/chat/authenticate-authorize).\n\nMessageReplyOption\n------------------\n\nSpecifies how to reply to a message. More states might be added in the future.\n\n| Enums ||\n|----------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `MESSAGE_REPLY_OPTION_UNSPECIFIED` | Default. Starts a new thread. Using this option ignores any [thread ID](/workspace/chat/api/reference/rest/v1/spaces.messages#Message.Thread.FIELDS.name) or [`threadKey`](/workspace/chat/api/reference/rest/v1/spaces.messages#Message.Thread.FIELDS.thread_key) that's included. |\n| `REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD` | Creates the message as a reply to the thread specified by [thread ID](/workspace/chat/api/reference/rest/v1/spaces.messages#Message.Thread.FIELDS.name) or [`threadKey`](/workspace/chat/api/reference/rest/v1/spaces.messages#Message.Thread.FIELDS.thread_key). If it fails, the message starts a new thread instead. |\n| `REPLY_MESSAGE_OR_FAIL` | Creates the message as a reply to the thread specified by [thread ID](/workspace/chat/api/reference/rest/v1/spaces.messages#Message.Thread.FIELDS.name) or [`threadKey`](/workspace/chat/api/reference/rest/v1/spaces.messages#Message.Thread.FIELDS.thread_key). If a new `threadKey` is used, a new thread is created. If the message creation fails, a `NOT_FOUND` error is returned instead. |"]]