Method: spaces.messages.create
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Crea un mensaje en un espacio de Google Chat. Para ver un ejemplo, consulta Cómo enviar un mensaje.
Admite los siguientes tipos de autenticación:
- Autenticación de la app con el alcance de autorización:
https://www.googleapis.com/auth/chat.bot
- Autenticación del usuario con uno de los siguientes permisos de autorización:
https://www.googleapis.com/auth/chat.messages.create
https://www.googleapis.com/auth/chat.messages
https://www.googleapis.com/auth/chat.import
(solo espacios del modo de importación)
Chat atribuye al remitente del mensaje de forma diferente según el tipo de autenticación que uses en tu solicitud.
En la siguiente imagen, se muestra cómo Chat atribuye un mensaje cuando usas la autenticación de apps. Chat muestra la app de Chat como el remitente del mensaje. El contenido del mensaje puede incluir texto (text
), tarjetas (cardsV2
) y widgets de accesorios (accessoryWidgets
).

En la siguiente imagen, se muestra cómo Chat atribuye un mensaje cuando usas la autenticación de usuarios. Chat muestra al usuario como el remitente del mensaje y atribuye la app de Chat al mensaje mostrando su nombre. El contenido del mensaje solo puede contener texto (text
).

El tamaño máximo del mensaje, incluido el contenido, es de 32,000 bytes.
En el caso de las solicitudes de webhook, la respuesta no contiene el mensaje completo. La respuesta solo propaga los campos name
y thread.name
, además de la información que estaba en la solicitud.
Solicitud HTTP
POST https://chat.googleapis.com/v1/{parent=spaces/*}/messages
La URL usa la sintaxis de la transcodificación gRPC.
Parámetros de ruta de acceso
Parámetros |
parent |
string
Obligatorio. Es el nombre del recurso del espacio en el que se creará un mensaje. Formato: spaces/{space}
|
Parámetros de consulta
Parámetros |
threadKey (deprecated) |
string
Opcional. Obsoleto: Usa thread.thread_key en su lugar. Es el ID del subproceso. Admite hasta 4,000 caracteres. Para iniciar una conversación o agregarla a una existente, crea un mensaje y especifica un threadKey o el thread.name . Para ver un ejemplo de uso, consulta Cómo iniciar o responder una conversación de mensajes.
|
requestId |
string
Opcional. Un ID de solicitud único para este mensaje. Si especificas un ID de solicitud existente, se muestra el mensaje creado con ese ID en lugar de crear uno nuevo.
|
messageReplyOption |
enum (MessageReplyOption )
Opcional. Especifica si un mensaje inicia una conversación o responde una. Solo se admite en espacios con nombre. Cuando respondes a las interacciones del usuario, se ignora este campo. En el caso de las interacciones dentro de una conversación, la respuesta se crea en la misma conversación. De lo contrario, la respuesta se creará como una conversación nueva.
|
messageId |
string
Opcional. Un ID personalizado para un mensaje. Permite que las apps de Chat obtengan, actualicen o borren un mensaje sin necesidad de almacenar el ID asignado por el sistema en el nombre del recurso del mensaje (representado en el campo name del mensaje). El valor de este campo debe cumplir con los siguientes requisitos:
- Comienza con
client- . Por ejemplo, client-custom-name es un ID personalizado válido, pero custom-name no lo es.
- Contiene hasta 63 caracteres y solo letras minúsculas, números y guiones.
- Es único dentro de un espacio. Una app de chat no puede usar el mismo ID personalizado para diferentes mensajes.
Para obtener más información, consulta Cómo asignar un nombre a un mensaje.
|
Cuerpo de la solicitud
El cuerpo de la solicitud contiene una instancia de Message
.
Cuerpo de la respuesta
Si el proceso se realiza de forma correcta, el cuerpo de la respuesta contiene una instancia recién creada de Message
.
Permisos de autorización
Se necesita uno de los siguientes permisos de OAuth:
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
Para obtener más información, consulta la Guía de autorización.
MessageReplyOption
Especifica cómo responder un mensaje. Es posible que se agreguen más estados en el futuro.
Enumeraciones |
MESSAGE_REPLY_OPTION_UNSPECIFIED |
Predeterminado. Inicia una conversación nueva. Si usas esta opción, se ignorará cualquier thread ID o threadKey que se incluya. |
REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD |
Crea el mensaje como una respuesta a la conversación especificada por thread ID o threadKey . Si falla, el mensaje inicia una conversación nueva. |
REPLY_MESSAGE_OR_FAIL |
Crea el mensaje como una respuesta a la conversación especificada por thread ID o threadKey . Si se usa un threadKey nuevo, se crea un subproceso nuevo. Si falla la creación del mensaje, se muestra un error NOT_FOUND . |
Salvo que se indique lo contrario, el contenido de esta página está sujeto a la licencia Atribución 4.0 de Creative Commons, y los ejemplos de código están sujetos a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
Última actualización: 2025-07-25 (UTC)
[null,null,["Última actualización: 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. |"]]