create method

Future<Message> create(
  1. Message request,
  2. String parent, {
  3. String? messageId,
  4. String? messageReplyOption,
  5. String? requestId,
  6. String? threadKey,
  7. String? $fields,
})

Creates a message in a Google Chat space.

For an example, see Create a message. Calling this method requires authentication and supports the following authentication types: - For text messages, user authentication or app authentication are supported. - For card messages, only app authentication is supported. (Only Chat apps can create card messages.)

request - The metadata request object.

Request parameters:

parent - Required. The resource name of the space in which to create a message. Format: spaces/{space} Value must have pattern ^spaces/\[^/\]+$.

messageId - 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. Assigning a custom name lets a a Chat app recall the message without saving the message name from the [response body](/chat/api/reference/rest/v1/spaces.messages/get#response-body) returned when creating the message. Assigning a custom name doesn't replace the generated name field, the message's resource name. Instead, it sets the custom name as the clientAssignedMessageId field, which you can reference while processing later operations, like updating or deleting the message. For example usage, see Name a created message.

messageReplyOption - Optional. Specifies whether a message starts a thread or replies to one. Only supported in named spaces. Possible string values are:

  • "MESSAGE_REPLY_OPTION_UNSPECIFIED" : Default. Starts a new thread. Using this option ignores any thread ID or thread_key that's included.
  • "REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD" : Creates the message as a reply to the thread specified by thread ID or thread_key. 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 thread_key. If a new thread_key is used, a new thread is created. If the message creation fails, a NOT_FOUND error is returned instead.

requestId - 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.

threadKey - Optional. Deprecated: Use thread.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. For example usage, see Start or reply to a message thread.

$fields - Selector specifying which fields to include in a partial response.

Completes with a Message.

Completes with a commons.ApiRequestError if the API endpoint returned an error.

If the used http.Client completes with an error when making a REST call, this method will complete with the same error.

Implementation

async.Future<Message> create(
  Message request,
  core.String parent, {
  core.String? messageId,
  core.String? messageReplyOption,
  core.String? requestId,
  core.String? threadKey,
  core.String? $fields,
}) async {
  final body_ = convert.json.encode(request);
  final queryParams_ = <core.String, core.List<core.String>>{
    if (messageId != null) 'messageId': [messageId],
    if (messageReplyOption != null)
      'messageReplyOption': [messageReplyOption],
    if (requestId != null) 'requestId': [requestId],
    if (threadKey != null) 'threadKey': [threadKey],
    if ($fields != null) 'fields': [$fields],
  };

  final url_ = 'v1/' + core.Uri.encodeFull('$parent') + '/messages';

  final response_ = await _requester.request(
    url_,
    'POST',
    body: body_,
    queryParams: queryParams_,
  );
  return Message.fromJson(response_ as core.Map<core.String, core.dynamic>);
}