Method: spaces.messages.create

Stay organized with collections Save and categorize content based on your preferences.

Creates a message. For example usage, see Create a message.

Requires authentication. Fully supports service account authentication.

Supports user authentication as part of the Google Workspace Developer Preview Program, which grants early access to certain features. User authentication requires the chat.messages or chat.messages.create authorization scope.

Because Chat provides authentication for webhooks as part of the URL that's generated when a webhook is registered, webhooks can create messages without a service account or user authentication.

HTTP request

POST https://chat.googleapis.com/v1/{parent=spaces/*}/messages

The URL uses gRPC Transcoding syntax.

Path parameters

Parameters
parent

string

Required. The resource name of the space in which to create a message.

Format: spaces/{space}

Query parameters

Parameters
threadKey
(deprecated)

string

Optional. Deprecated: Use thread.thread_key instead. Opaque thread identifier. To start or add to a thread, create a message and specify a threadKey or the thread.name. For example usage, see Start or reply to a message thread.

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.

messageReplyOption

enum (MessageReplyOption)

Optional. Specifies whether a message starts a thread or replies to one. Only supported in named spaces.

messageId

string

Optional. A custom name for a Chat message assigned at creation. Must start with client- and contain only lowercase letters, numbers, and hyphens up to 63 characters in length. Specify this field to get, update, or delete the message with the specified value. For example usage, see Name a created message.

Request body

The request body contains an instance of Message.

Response body

If successful, the response body contains a newly created instance of Message.

Authorization Scopes

Requires one of the following OAuth scopes:

  • https://www.googleapis.com/auth/chat.bot
  • https://www.googleapis.com/auth/chat.messages
  • https://www.googleapis.com/auth/chat.messages.create

For more information, see the Authorization guide.

MessageReplyOption

Specifies how to reply to a message. More states may be added in the future.

Enums
MESSAGE_REPLY_OPTION_UNSPECIFIED Default. Starts a thread.
REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD Creates the message as a reply to the thread specified by thread ID or threadKey. If it fails, the message starts a new thread instead.
REPLY_MESSAGE_OR_FAIL Creates the message as a reply to the thread specified by thread ID or threadKey. If it fails, a NOT_FOUND error is returned instead.