Google Apps Chat V1 Client - Class ChatServiceClient (0.1.3)

Reference documentation and code samples for the Google Apps Chat V1 Client class ChatServiceClient.

Service Description: Enables developers to build Chat apps and integrations on Google Chat Platform.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods.

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parseName method to extract the individual identifiers contained within formatted names that are returned by the API.

Namespace

Google \ Apps \ Chat \ V1 \ Client

Methods

__construct

Constructor.

Parameters
Name Description
options array

Optional. Options for configuring the service API wrapper.

↳ apiEndpoint string

The address of the API remote host. May optionally include the port, formatted as "

↳ credentials string|array|FetchAuthTokenInterface|CredentialsWrapper

The credentials to be used by the client to authorize API calls. This option accepts either a path to a credentials file, or a decoded credentials file as a PHP array. Advanced usage: In addition, this option can also accept a pre-constructed Google\Auth\FetchAuthTokenInterface object or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored.

↳ credentialsConfig array

Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see Google\ApiCore\CredentialsWrapper::build() .

↳ disableRetries bool

Determines whether or not retries defined by the client configuration should be disabled. Defaults to false.

↳ clientConfig string|array

Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder.

↳ transport string|TransportInterface

The transport used for executing network requests. May be either the string rest or grpc. Defaults to grpc if gRPC support is detected on the system. Advanced usage: Additionally, it is possible to pass in an already instantiated Google\ApiCore\Transport\TransportInterface object. Note that when this object is provided, any settings in $transportConfig, and any $apiEndpoint setting, will be ignored.

↳ transportConfig array

Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'grpc' => [...], 'rest' => [...], ]; See the Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() methods for the supported options.

↳ clientCertSource callable

A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS.

completeImportSpace

Completes the import process for the specified space and makes it visible to users.

Requires app authentication and domain-wide delegation. For more information, see Authorize Google Chat apps to import data.

The async variant is Google\Apps\Chat\V1\Client\ChatServiceClient::completeImportSpaceAsync() .

Parameters
Name Description
request Google\Apps\Chat\V1\CompleteImportSpaceRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Apps\Chat\V1\CompleteImportSpaceResponse
Example
use Google\ApiCore\ApiException;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\CompleteImportSpaceRequest;
use Google\Apps\Chat\V1\CompleteImportSpaceResponse;

/**
 * @param string $formattedName Resource name of the import mode space.
 *
 *                              Format: `spaces/{space}`
 *                              Please see {@see ChatServiceClient::spaceName()} for help formatting this field.
 */
function complete_import_space_sample(string $formattedName): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $request = (new CompleteImportSpaceRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var CompleteImportSpaceResponse $response */
        $response = $chatServiceClient->completeImportSpace($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = ChatServiceClient::spaceName('[SPACE]');

    complete_import_space_sample($formattedName);
}

createMembership

Creates a human membership or app membership for the calling app. Creating memberships for other apps isn't supported. For an example, see Invite or add a user or a Google Chat app to a space.

When creating a membership, if the specified member has their auto-accept policy turned off, then they're invited, and must accept the space invitation before joining. Otherwise, creating a membership adds the member directly to the specified space. Requires user authentication.

To specify the member to add, set the membership.member.name for the human or app member.

  • To add the calling app to a space or a direct message between two human users, use users/app. Unable to add other apps to the space.

  • To add a human user, use users/{user}, where {user} can be the email address for the user. For users in the same Workspace organization {user} can also be the id for the person from the People API, or the id for the user in the Directory API. For example, if the People API Person profile ID for user@example.com is 123456789, you can add the user to the space by setting the membership.member.name to users/user@example.com or users/123456789.

The async variant is Google\Apps\Chat\V1\Client\ChatServiceClient::createMembershipAsync() .

Parameters
Name Description
request Google\Apps\Chat\V1\CreateMembershipRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Apps\Chat\V1\Membership
Example
use Google\ApiCore\ApiException;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\CreateMembershipRequest;
use Google\Apps\Chat\V1\Membership;

/**
 * @param string $formattedParent The resource name of the space for which to create the
 *                                membership.
 *
 *                                Format: spaces/{space}
 *                                Please see {@see ChatServiceClient::spaceName()} for help formatting this field.
 */
function create_membership_sample(string $formattedParent): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $membership = new Membership();
    $request = (new CreateMembershipRequest())
        ->setParent($formattedParent)
        ->setMembership($membership);

    // Call the API and handle any network failures.
    try {
        /** @var Membership $response */
        $response = $chatServiceClient->createMembership($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = ChatServiceClient::spaceName('[SPACE]');

    create_membership_sample($formattedParent);
}

createMessage

Creates a message in a Google Chat space. The maximum message size, including text and cards, is 32,000 bytes. For an example, see Send 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.)

The async variant is Google\Apps\Chat\V1\Client\ChatServiceClient::createMessageAsync() .

Parameters
Name Description
request Google\Apps\Chat\V1\CreateMessageRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Apps\Chat\V1\Message
Example
use Google\ApiCore\ApiException;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\CreateMessageRequest;
use Google\Apps\Chat\V1\Message;

/**
 * @param string $formattedParent The resource name of the space in which to create a message.
 *
 *                                Format: `spaces/{space}`
 *                                Please see {@see ChatServiceClient::spaceName()} for help formatting this field.
 */
function create_message_sample(string $formattedParent): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $message = new Message();
    $request = (new CreateMessageRequest())
        ->setParent($formattedParent)
        ->setMessage($message);

    // Call the API and handle any network failures.
    try {
        /** @var Message $response */
        $response = $chatServiceClient->createMessage($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = ChatServiceClient::spaceName('[SPACE]');

    create_message_sample($formattedParent);
}

createReaction

Creates a reaction and adds it to a message. Only unicode emojis are supported. For an example, see Add a reaction to a message.

Requires user authentication.

The async variant is Google\Apps\Chat\V1\Client\ChatServiceClient::createReactionAsync() .

Parameters
Name Description
request Google\Apps\Chat\V1\CreateReactionRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Apps\Chat\V1\Reaction
Example
use Google\ApiCore\ApiException;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\CreateReactionRequest;
use Google\Apps\Chat\V1\Reaction;

/**
 * @param string $formattedParent The message where the reaction is created.
 *
 *                                Format: `spaces/{space}/messages/{message}`
 *                                Please see {@see ChatServiceClient::messageName()} for help formatting this field.
 */
function create_reaction_sample(string $formattedParent): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $reaction = new Reaction();
    $request = (new CreateReactionRequest())
        ->setParent($formattedParent)
        ->setReaction($reaction);

    // Call the API and handle any network failures.
    try {
        /** @var Reaction $response */
        $response = $chatServiceClient->createReaction($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = ChatServiceClient::messageName('[SPACE]', '[MESSAGE]');

    create_reaction_sample($formattedParent);
}

createSpace

Creates a named space. Spaces grouped by topics aren't supported. For an example, see Create a space.

If you receive the error message ALREADY_EXISTS when creating a space, try a different displayName. An existing space within the Google Workspace organization might already use this display name.

Requires user authentication.

The async variant is Google\Apps\Chat\V1\Client\ChatServiceClient::createSpaceAsync() .

Parameters
Name Description
request Google\Apps\Chat\V1\CreateSpaceRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Apps\Chat\V1\Space
Example
use Google\ApiCore\ApiException;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\CreateSpaceRequest;
use Google\Apps\Chat\V1\Space;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function create_space_sample(): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $space = new Space();
    $request = (new CreateSpaceRequest())
        ->setSpace($space);

    // Call the API and handle any network failures.
    try {
        /** @var Space $response */
        $response = $chatServiceClient->createSpace($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

deleteMembership

Parameters
Name Description
request Google\Apps\Chat\V1\DeleteMembershipRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Apps\Chat\V1\Membership
Example
use Google\ApiCore\ApiException;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\DeleteMembershipRequest;
use Google\Apps\Chat\V1\Membership;

/**
 * @param string $formattedName Resource name of the membership to delete. Chat apps can delete
 *                              human users' or their own memberships. Chat apps can't delete other apps'
 *                              memberships.
 *
 *                              When deleting a human membership, requires the `chat.memberships` scope and
 *                              `spaces/{space}/members/{member}` format. You can use the email as an
 *                              alias for `{member}`. For example,
 *                              `spaces/{space}/members/example@gmail.com` where `example@gmail.com` is the
 *                              email of the Google Chat user.
 *
 *                              When deleting an app membership, requires the `chat.memberships.app` scope
 *                              and `spaces/{space}/members/app` format.
 *
 *                              Format: `spaces/{space}/members/{member}` or `spaces/{space}/members/app`. Please see
 *                              {@see ChatServiceClient::membershipName()} for help formatting this field.
 */
function delete_membership_sample(string $formattedName): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $request = (new DeleteMembershipRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var Membership $response */
        $response = $chatServiceClient->deleteMembership($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = ChatServiceClient::membershipName('[SPACE]', '[MEMBER]');

    delete_membership_sample($formattedName);
}

deleteMessage

Deletes a message.

For an example, see Delete a message.

Requires authentication. Supports app authentication and user authentication. When using app authentication, requests can only delete messages created by the calling Chat app.

The async variant is Google\Apps\Chat\V1\Client\ChatServiceClient::deleteMessageAsync() .

Parameters
Name Description
request Google\Apps\Chat\V1\DeleteMessageRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Example
use Google\ApiCore\ApiException;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\DeleteMessageRequest;

/**
 * @param string $formattedName Resource name of the message.
 *
 *                              Format: `spaces/{space}/messages/{message}`
 *
 *                              If you've set a custom ID for your message, you can use the value from the
 *                              `clientAssignedMessageId` field for `{message}`. For details, see [Name a
 *                              message]
 *                              (https://developers.google.com/workspace/chat/create-messages#name_a_created_message). Please see
 *                              {@see ChatServiceClient::messageName()} for help formatting this field.
 */
function delete_message_sample(string $formattedName): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $request = (new DeleteMessageRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        $chatServiceClient->deleteMessage($request);
        printf('Call completed successfully.' . PHP_EOL);
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = ChatServiceClient::messageName('[SPACE]', '[MESSAGE]');

    delete_message_sample($formattedName);
}

deleteReaction

Deletes a reaction to a message. Only unicode emojis are supported.

For an example, see Delete a reaction. Requires user authentication.

The async variant is Google\Apps\Chat\V1\Client\ChatServiceClient::deleteReactionAsync() .

Parameters
Name Description
request Google\Apps\Chat\V1\DeleteReactionRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Example
use Google\ApiCore\ApiException;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\DeleteReactionRequest;

/**
 * @param string $formattedName Name of the reaction to delete.
 *
 *                              Format: `spaces/{space}/messages/{message}/reactions/{reaction}`
 *                              Please see {@see ChatServiceClient::reactionName()} for help formatting this field.
 */
function delete_reaction_sample(string $formattedName): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $request = (new DeleteReactionRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        $chatServiceClient->deleteReaction($request);
        printf('Call completed successfully.' . PHP_EOL);
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = ChatServiceClient::reactionName('[SPACE]', '[MESSAGE]', '[REACTION]');

    delete_reaction_sample($formattedName);
}

deleteSpace

Deletes a named space. Always performs a cascading delete, which means that the space's child resources—like messages posted in the space and memberships in the space—are also deleted. For an example, see Delete a space.

Requires user authentication from a user who has permission to delete the space.

The async variant is Google\Apps\Chat\V1\Client\ChatServiceClient::deleteSpaceAsync() .

Parameters
Name Description
request Google\Apps\Chat\V1\DeleteSpaceRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Example
use Google\ApiCore\ApiException;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\DeleteSpaceRequest;

/**
 * @param string $formattedName Resource name of the space to delete.
 *
 *                              Format: `spaces/{space}`
 *                              Please see {@see ChatServiceClient::spaceName()} for help formatting this field.
 */
function delete_space_sample(string $formattedName): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $request = (new DeleteSpaceRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        $chatServiceClient->deleteSpace($request);
        printf('Call completed successfully.' . PHP_EOL);
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = ChatServiceClient::spaceName('[SPACE]');

    delete_space_sample($formattedName);
}

findDirectMessage

Returns the existing direct message with the specified user. If no direct message space is found, returns a 404 NOT_FOUND error. For an example, see Find a direct message.

With user authentication, returns the direct message space between the specified user and the authenticated user.

With app authentication, returns the direct message space between the specified user and the calling Chat app.

Requires user authentication or app authentication.

The async variant is Google\Apps\Chat\V1\Client\ChatServiceClient::findDirectMessageAsync() .

Parameters
Name Description
request Google\Apps\Chat\V1\FindDirectMessageRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Apps\Chat\V1\Space
Example
use Google\ApiCore\ApiException;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\FindDirectMessageRequest;
use Google\Apps\Chat\V1\Space;

/**
 * @param string $name Resource name of the user to find direct message with.
 *
 *                     Format: `users/{user}`, where `{user}` is either the `id` for the
 *                     [person](https://developers.google.com/people/api/rest/v1/people) from the
 *                     People API, or the `id` for the
 *                     [user](https://developers.google.com/admin-sdk/directory/reference/rest/v1/users)
 *                     in the Directory API. For example, if the People API profile ID is
 *                     `123456789`, you can find a direct message with that person by using
 *                     `users/123456789` as the `name`. When [authenticated as a
 *                     user](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user),
 *                     you can use the email as an alias for `{user}`. For example,
 *                     `users/example@gmail.com` where `example@gmail.com` is the email of the
 *                     Google Chat user.
 */
function find_direct_message_sample(string $name): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $request = (new FindDirectMessageRequest())
        ->setName($name);

    // Call the API and handle any network failures.
    try {
        /** @var Space $response */
        $response = $chatServiceClient->findDirectMessage($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $name = '[NAME]';

    find_direct_message_sample($name);
}

getAttachment

Gets the metadata of a message attachment. The attachment data is fetched using the media API.

For an example, see Get metadata about a message attachment. Requires app authentication.

The async variant is Google\Apps\Chat\V1\Client\ChatServiceClient::getAttachmentAsync() .

Parameters
Name Description
request Google\Apps\Chat\V1\GetAttachmentRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Apps\Chat\V1\Attachment
Example
use Google\ApiCore\ApiException;
use Google\Apps\Chat\V1\Attachment;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\GetAttachmentRequest;

/**
 * @param string $formattedName Resource name of the attachment, in the form
 *                              `spaces/*/messages/*/attachments/*`. Please see
 *                              {@see ChatServiceClient::attachmentName()} for help formatting this field.
 */
function get_attachment_sample(string $formattedName): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $request = (new GetAttachmentRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var Attachment $response */
        $response = $chatServiceClient->getAttachment($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = ChatServiceClient::attachmentName('[SPACE]', '[MESSAGE]', '[ATTACHMENT]');

    get_attachment_sample($formattedName);
}

getMembership

Parameters
Name Description
request Google\Apps\Chat\V1\GetMembershipRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Apps\Chat\V1\Membership
Example
use Google\ApiCore\ApiException;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\GetMembershipRequest;
use Google\Apps\Chat\V1\Membership;

/**
 * @param string $formattedName Resource name of the membership to retrieve.
 *
 *                              To get the app's own membership [by using user
 *                              authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user),
 *                              you can optionally use `spaces/{space}/members/app`.
 *
 *                              Format: `spaces/{space}/members/{member}` or `spaces/{space}/members/app`
 *
 *                              When [authenticated as a
 *                              user](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user),
 *                              you can use the user's email as an alias for `{member}`. For example,
 *                              `spaces/{space}/members/example@gmail.com` where `example@gmail.com` is the
 *                              email of the Google Chat user. Please see
 *                              {@see ChatServiceClient::membershipName()} for help formatting this field.
 */
function get_membership_sample(string $formattedName): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $request = (new GetMembershipRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var Membership $response */
        $response = $chatServiceClient->getMembership($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = ChatServiceClient::membershipName('[SPACE]', '[MEMBER]');

    get_membership_sample($formattedName);
}

getMessage

Returns details about a message.

For an example, see Get details about a message.

Requires authentication. Supports app authentication and user authentication.

Note: Might return a message from a blocked member or space.

The async variant is Google\Apps\Chat\V1\Client\ChatServiceClient::getMessageAsync() .

Parameters
Name Description
request Google\Apps\Chat\V1\GetMessageRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Apps\Chat\V1\Message
Example
use Google\ApiCore\ApiException;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\GetMessageRequest;
use Google\Apps\Chat\V1\Message;

/**
 * @param string $formattedName Resource name of the message.
 *
 *                              Format: `spaces/{space}/messages/{message}`
 *
 *                              If you've set a custom ID for your message, you can use the value from the
 *                              `clientAssignedMessageId` field for `{message}`. For details, see [Name a
 *                              message]
 *                              (https://developers.google.com/workspace/chat/create-messages#name_a_created_message). Please see
 *                              {@see ChatServiceClient::messageName()} for help formatting this field.
 */
function get_message_sample(string $formattedName): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $request = (new GetMessageRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var Message $response */
        $response = $chatServiceClient->getMessage($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = ChatServiceClient::messageName('[SPACE]', '[MESSAGE]');

    get_message_sample($formattedName);
}

getSpace

Returns details about a space. For an example, see Get details about a space.

Requires authentication. Supports app authentication and user authentication.

The async variant is Google\Apps\Chat\V1\Client\ChatServiceClient::getSpaceAsync() .

Parameters
Name Description
request Google\Apps\Chat\V1\GetSpaceRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Apps\Chat\V1\Space
Example
use Google\ApiCore\ApiException;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\GetSpaceRequest;
use Google\Apps\Chat\V1\Space;

/**
 * @param string $formattedName Resource name of the space, in the form "spaces/*".
 *
 *                              Format: `spaces/{space}`
 *                              Please see {@see ChatServiceClient::spaceName()} for help formatting this field.
 */
function get_space_sample(string $formattedName): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $request = (new GetSpaceRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var Space $response */
        $response = $chatServiceClient->getSpace($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = ChatServiceClient::spaceName('[SPACE]');

    get_space_sample($formattedName);
}

getSpaceReadState

Returns details about a user's read state within a space, used to identify read and unread messages. For an example, see Get details about a user's space read state.

Requires user authentication.

The async variant is Google\Apps\Chat\V1\Client\ChatServiceClient::getSpaceReadStateAsync() .

Parameters
Name Description
request Google\Apps\Chat\V1\GetSpaceReadStateRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Apps\Chat\V1\SpaceReadState
Example
use Google\ApiCore\ApiException;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\GetSpaceReadStateRequest;
use Google\Apps\Chat\V1\SpaceReadState;

/**
 * @param string $formattedName Resource name of the space read state to retrieve.
 *
 *                              Only supports getting read state for the calling user.
 *
 *                              To refer to the calling user, set one of the following:
 *
 *                              - The `me` alias. For example, `users/me/spaces/{space}/spaceReadState`.
 *
 *                              - Their Workspace email address. For example,
 *                              `users/user@example.com/spaces/{space}/spaceReadState`.
 *
 *                              - Their user id. For example,
 *                              `users/123456789/spaces/{space}/spaceReadState`.
 *
 *                              Format: users/{user}/spaces/{space}/spaceReadState
 *                              Please see {@see ChatServiceClient::spaceReadStateName()} for help formatting this field.
 */
function get_space_read_state_sample(string $formattedName): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $request = (new GetSpaceReadStateRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var SpaceReadState $response */
        $response = $chatServiceClient->getSpaceReadState($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = ChatServiceClient::spaceReadStateName('[USER]', '[SPACE]');

    get_space_read_state_sample($formattedName);
}

getThreadReadState

Returns details about a user's read state within a thread, used to identify read and unread messages. For an example, see Get details about a user's thread read state.

Requires user authentication.

The async variant is Google\Apps\Chat\V1\Client\ChatServiceClient::getThreadReadStateAsync() .

Parameters
Name Description
request Google\Apps\Chat\V1\GetThreadReadStateRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Apps\Chat\V1\ThreadReadState
Example
use Google\ApiCore\ApiException;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\GetThreadReadStateRequest;
use Google\Apps\Chat\V1\ThreadReadState;

/**
 * @param string $formattedName Resource name of the thread read state to retrieve.
 *
 *                              Only supports getting read state for the calling user.
 *
 *                              To refer to the calling user, set one of the following:
 *
 *                              - The `me` alias. For example,
 *                              `users/me/spaces/{space}/threads/{thread}/threadReadState`.
 *
 *                              - Their Workspace email address. For example,
 *                              `users/user@example.com/spaces/{space}/threads/{thread}/threadReadState`.
 *
 *                              - Their user id. For example,
 *                              `users/123456789/spaces/{space}/threads/{thread}/threadReadState`.
 *
 *                              Format: users/{user}/spaces/{space}/threads/{thread}/threadReadState
 *                              Please see {@see ChatServiceClient::threadReadStateName()} for help formatting this field.
 */
function get_thread_read_state_sample(string $formattedName): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $request = (new GetThreadReadStateRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var ThreadReadState $response */
        $response = $chatServiceClient->getThreadReadState($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = ChatServiceClient::threadReadStateName('[USER]', '[SPACE]', '[THREAD]');

    get_thread_read_state_sample($formattedName);
}

listMemberships

Lists memberships in a space. For an example, see List users and Google Chat apps in a space. Listing memberships with app authentication lists memberships in spaces that the Chat app has access to, but excludes Chat app memberships, including its own. Listing memberships with User authentication lists memberships in spaces that the authenticated user has access to.

Requires authentication. Supports app authentication and user authentication.

The async variant is Google\Apps\Chat\V1\Client\ChatServiceClient::listMembershipsAsync() .

Parameters
Name Description
request Google\Apps\Chat\V1\ListMembershipsRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\ListMembershipsRequest;
use Google\Apps\Chat\V1\Membership;

/**
 * @param string $formattedParent The resource name of the space for which to fetch a membership
 *                                list.
 *
 *                                Format: spaces/{space}
 *                                Please see {@see ChatServiceClient::spaceName()} for help formatting this field.
 */
function list_memberships_sample(string $formattedParent): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $request = (new ListMembershipsRequest())
        ->setParent($formattedParent);

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $chatServiceClient->listMemberships($request);

        /** @var Membership $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = ChatServiceClient::spaceName('[SPACE]');

    list_memberships_sample($formattedParent);
}

listMessages

Lists messages in a space that the caller is a member of, including messages from blocked members and spaces. For an example, see List messages.

Requires user authentication.

The async variant is Google\Apps\Chat\V1\Client\ChatServiceClient::listMessagesAsync() .

Parameters
Name Description
request Google\Apps\Chat\V1\ListMessagesRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\ListMessagesRequest;
use Google\Apps\Chat\V1\Message;

/**
 * @param string $formattedParent The resource name of the space to list messages from.
 *
 *                                Format: `spaces/{space}`
 *                                Please see {@see ChatServiceClient::spaceName()} for help formatting this field.
 */
function list_messages_sample(string $formattedParent): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $request = (new ListMessagesRequest())
        ->setParent($formattedParent);

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $chatServiceClient->listMessages($request);

        /** @var Message $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = ChatServiceClient::spaceName('[SPACE]');

    list_messages_sample($formattedParent);
}

listReactions

Lists reactions to a message. For an example, see List reactions for a message.

Requires user authentication.

The async variant is Google\Apps\Chat\V1\Client\ChatServiceClient::listReactionsAsync() .

Parameters
Name Description
request Google\Apps\Chat\V1\ListReactionsRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\ListReactionsRequest;
use Google\Apps\Chat\V1\Reaction;

/**
 * @param string $formattedParent The message users reacted to.
 *
 *                                Format: `spaces/{space}/messages/{message}`
 *                                Please see {@see ChatServiceClient::messageName()} for help formatting this field.
 */
function list_reactions_sample(string $formattedParent): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $request = (new ListReactionsRequest())
        ->setParent($formattedParent);

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $chatServiceClient->listReactions($request);

        /** @var Reaction $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = ChatServiceClient::messageName('[SPACE]', '[MESSAGE]');

    list_reactions_sample($formattedParent);
}

listSpaces

Lists spaces the caller is a member of. Group chats and DMs aren't listed until the first message is sent. For an example, see List spaces.

Requires authentication. Supports app authentication and user authentication.

Lists spaces visible to the caller or authenticated user. Group chats and DMs aren't listed until the first message is sent.

The async variant is Google\Apps\Chat\V1\Client\ChatServiceClient::listSpacesAsync() .

Parameters
Name Description
request Google\Apps\Chat\V1\ListSpacesRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\ListSpacesRequest;
use Google\Apps\Chat\V1\Space;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function list_spaces_sample(): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $request = new ListSpacesRequest();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $chatServiceClient->listSpaces($request);

        /** @var Space $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

setUpSpace

Creates a space and adds specified users to it. The calling user is automatically added to the space, and shouldn't be specified as a membership in the request. For an example, see Set up a space with initial members.

To specify the human members to add, add memberships with the appropriate membership.member.name. To add a human user, use users/{user}, where {user} can be the email address for the user. For users in the same Workspace organization {user} can also be the id for the person from the People API, or the id for the user in the Directory API. For example, if the People API Person profile ID for user@example.com is 123456789, you can add the user to the space by setting the membership.member.name to users/user@example.com or users/123456789.

For a named space or group chat, if the caller blocks, or is blocked by some members, or doesn't have permission to add some members, then those members aren't added to the created space.

To create a direct message (DM) between the calling user and another human user, specify exactly one membership to represent the human user. If one user blocks the other, the request fails and the DM isn't created.

To create a DM between the calling user and the calling app, set Space.singleUserBotDm to true and don't specify any memberships. You can only use this method to set up a DM with the calling app. To add the calling app as a member of a space or an existing DM between two human users, see Invite or add a user or app to a space.

If a DM already exists between two users, even when one user blocks the other at the time a request is made, then the existing DM is returned.

Spaces with threaded replies aren't supported. If you receive the error message ALREADY_EXISTS when setting up a space, try a different displayName. An existing space within the Google Workspace organization might already use this display name.

Requires user authentication.

The async variant is Google\Apps\Chat\V1\Client\ChatServiceClient::setUpSpaceAsync() .

Parameters
Name Description
request Google\Apps\Chat\V1\SetUpSpaceRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Apps\Chat\V1\Space
Example
use Google\ApiCore\ApiException;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\SetUpSpaceRequest;
use Google\Apps\Chat\V1\Space;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function set_up_space_sample(): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $space = new Space();
    $request = (new SetUpSpaceRequest())
        ->setSpace($space);

    // Call the API and handle any network failures.
    try {
        /** @var Space $response */
        $response = $chatServiceClient->setUpSpace($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

updateMembership

Parameters
Name Description
request Google\Apps\Chat\V1\UpdateMembershipRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Apps\Chat\V1\Membership
Example
use Google\ApiCore\ApiException;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\Membership;
use Google\Apps\Chat\V1\UpdateMembershipRequest;
use Google\Protobuf\FieldMask;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function update_membership_sample(): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $membership = new Membership();
    $updateMask = new FieldMask();
    $request = (new UpdateMembershipRequest())
        ->setMembership($membership)
        ->setUpdateMask($updateMask);

    // Call the API and handle any network failures.
    try {
        /** @var Membership $response */
        $response = $chatServiceClient->updateMembership($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

updateMessage

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

Requires authentication. Supports app authentication and user authentication. When using app authentication, requests can only update messages created by the calling Chat app.

The async variant is Google\Apps\Chat\V1\Client\ChatServiceClient::updateMessageAsync() .

Parameters
Name Description
request Google\Apps\Chat\V1\UpdateMessageRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Apps\Chat\V1\Message
Example
use Google\ApiCore\ApiException;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\Message;
use Google\Apps\Chat\V1\UpdateMessageRequest;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function update_message_sample(): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $message = new Message();
    $request = (new UpdateMessageRequest())
        ->setMessage($message);

    // Call the API and handle any network failures.
    try {
        /** @var Message $response */
        $response = $chatServiceClient->updateMessage($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

updateSpace

Updates a space. For an example, see Update a space.

If you're updating the displayName field and receive the error message ALREADY_EXISTS, try a different display name.. An existing space within the Google Workspace organization might already use this display name.

Requires user authentication.

The async variant is Google\Apps\Chat\V1\Client\ChatServiceClient::updateSpaceAsync() .

Parameters
Name Description
request Google\Apps\Chat\V1\UpdateSpaceRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Apps\Chat\V1\Space
Example
use Google\ApiCore\ApiException;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\Space;
use Google\Apps\Chat\V1\UpdateSpaceRequest;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function update_space_sample(): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $space = new Space();
    $request = (new UpdateSpaceRequest())
        ->setSpace($space);

    // Call the API and handle any network failures.
    try {
        /** @var Space $response */
        $response = $chatServiceClient->updateSpace($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

updateSpaceReadState

Updates a user's read state within a space, used to identify read and unread messages. For an example, see Update a user's space read state.

Requires user authentication.

The async variant is Google\Apps\Chat\V1\Client\ChatServiceClient::updateSpaceReadStateAsync() .

Parameters
Name Description
request Google\Apps\Chat\V1\UpdateSpaceReadStateRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Apps\Chat\V1\SpaceReadState
Example
use Google\ApiCore\ApiException;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\SpaceReadState;
use Google\Apps\Chat\V1\UpdateSpaceReadStateRequest;
use Google\Protobuf\FieldMask;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function update_space_read_state_sample(): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $spaceReadState = new SpaceReadState();
    $updateMask = new FieldMask();
    $request = (new UpdateSpaceReadStateRequest())
        ->setSpaceReadState($spaceReadState)
        ->setUpdateMask($updateMask);

    // Call the API and handle any network failures.
    try {
        /** @var SpaceReadState $response */
        $response = $chatServiceClient->updateSpaceReadState($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

uploadAttachment

Uploads an attachment. For an example, see Upload media as a file attachment.

Requires user authentication.

You can upload attachments up to 200 MB. Certain file types aren't supported. For details, see File types blocked by Google Chat.

The async variant is Google\Apps\Chat\V1\Client\ChatServiceClient::uploadAttachmentAsync() .

Parameters
Name Description
request Google\Apps\Chat\V1\UploadAttachmentRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Apps\Chat\V1\UploadAttachmentResponse
Example
use Google\ApiCore\ApiException;
use Google\Apps\Chat\V1\Client\ChatServiceClient;
use Google\Apps\Chat\V1\UploadAttachmentRequest;
use Google\Apps\Chat\V1\UploadAttachmentResponse;

/**
 * @param string $formattedParent Resource name of the Chat space in which the attachment is
 *                                uploaded. Format "spaces/{space}". Please see
 *                                {@see ChatServiceClient::spaceName()} for help formatting this field.
 * @param string $filename        The filename of the attachment, including the file extension.
 */
function upload_attachment_sample(string $formattedParent, string $filename): void
{
    // Create a client.
    $chatServiceClient = new ChatServiceClient();

    // Prepare the request message.
    $request = (new UploadAttachmentRequest())
        ->setParent($formattedParent)
        ->setFilename($filename);

    // Call the API and handle any network failures.
    try {
        /** @var UploadAttachmentResponse $response */
        $response = $chatServiceClient->uploadAttachment($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = ChatServiceClient::spaceName('[SPACE]');
    $filename = '[FILENAME]';

    upload_attachment_sample($formattedParent, $filename);
}

completeImportSpaceAsync

Parameters
Name Description
request Google\Apps\Chat\V1\CompleteImportSpaceRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

createMembershipAsync

Parameters
Name Description
request Google\Apps\Chat\V1\CreateMembershipRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

createMessageAsync

Parameters
Name Description
request Google\Apps\Chat\V1\CreateMessageRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

createReactionAsync

Parameters
Name Description
request Google\Apps\Chat\V1\CreateReactionRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

createSpaceAsync

Parameters
Name Description
request Google\Apps\Chat\V1\CreateSpaceRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

deleteMembershipAsync

Parameters
Name Description
request Google\Apps\Chat\V1\DeleteMembershipRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

deleteMessageAsync

Parameters
Name Description
request Google\Apps\Chat\V1\DeleteMessageRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

deleteReactionAsync

Parameters
Name Description
request Google\Apps\Chat\V1\DeleteReactionRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

deleteSpaceAsync

Parameters
Name Description
request Google\Apps\Chat\V1\DeleteSpaceRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

findDirectMessageAsync

Parameters
Name Description
request Google\Apps\Chat\V1\FindDirectMessageRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

getAttachmentAsync

Parameters
Name Description
request Google\Apps\Chat\V1\GetAttachmentRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

getMembershipAsync

Parameters
Name Description
request Google\Apps\Chat\V1\GetMembershipRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

getMessageAsync

Parameters
Name Description
request Google\Apps\Chat\V1\GetMessageRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

getSpaceAsync

Parameters
Name Description
request Google\Apps\Chat\V1\GetSpaceRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

getSpaceReadStateAsync

Parameters
Name Description
request Google\Apps\Chat\V1\GetSpaceReadStateRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

getThreadReadStateAsync

Parameters
Name Description
request Google\Apps\Chat\V1\GetThreadReadStateRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

listMembershipsAsync

Parameters
Name Description
request Google\Apps\Chat\V1\ListMembershipsRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

listMessagesAsync

Parameters
Name Description
request Google\Apps\Chat\V1\ListMessagesRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

listReactionsAsync

Parameters
Name Description
request Google\Apps\Chat\V1\ListReactionsRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

listSpacesAsync

Parameters
Name Description
request Google\Apps\Chat\V1\ListSpacesRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

setUpSpaceAsync

Parameters
Name Description
request Google\Apps\Chat\V1\SetUpSpaceRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

updateMembershipAsync

Parameters
Name Description
request Google\Apps\Chat\V1\UpdateMembershipRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

updateMessageAsync

Parameters
Name Description
request Google\Apps\Chat\V1\UpdateMessageRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

updateSpaceAsync

Parameters
Name Description
request Google\Apps\Chat\V1\UpdateSpaceRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

updateSpaceReadStateAsync

Parameters
Name Description
request Google\Apps\Chat\V1\UpdateSpaceReadStateRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

uploadAttachmentAsync

Parameters
Name Description
request Google\Apps\Chat\V1\UploadAttachmentRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

static::attachmentName

Formats a string containing the fully-qualified path to represent a attachment resource.

Parameters
Name Description
space string
message string
attachment string
Returns
Type Description
string The formatted attachment resource.

static::membershipName

Formats a string containing the fully-qualified path to represent a membership resource.

Parameters
Name Description
space string
member string
Returns
Type Description
string The formatted membership resource.

static::messageName

Formats a string containing the fully-qualified path to represent a message resource.

Parameters
Name Description
space string
message string
Returns
Type Description
string The formatted message resource.

static::quotedMessageMetadataName

Formats a string containing the fully-qualified path to represent a quoted_message_metadata resource.

Parameters
Name Description
space string
message string
quotedMessageMetadata string
Returns
Type Description
string The formatted quoted_message_metadata resource.

static::reactionName

Formats a string containing the fully-qualified path to represent a reaction resource.

Parameters
Name Description
space string
message string
reaction string
Returns
Type Description
string The formatted reaction resource.

static::spaceName

Formats a string containing the fully-qualified path to represent a space resource.

Parameter
Name Description
space string
Returns
Type Description
string The formatted space resource.

static::spaceReadStateName

Formats a string containing the fully-qualified path to represent a space_read_state resource.

Parameters
Name Description
user string
space string
Returns
Type Description
string The formatted space_read_state resource.

static::threadName

Formats a string containing the fully-qualified path to represent a thread resource.

Parameters
Name Description
space string
thread string
Returns
Type Description
string The formatted thread resource.

static::threadReadStateName

Formats a string containing the fully-qualified path to represent a thread_read_state resource.

Parameters
Name Description
user string
space string
thread string
Returns
Type Description
string The formatted thread_read_state resource.

static::parseName

Parses a formatted name string and returns an associative array of the components in the name.

The following name formats are supported: Template: Pattern

  • attachment: spaces/{space}/messages/{message}/attachments/{attachment}
  • membership: spaces/{space}/members/{member}
  • message: spaces/{space}/messages/{message}
  • quotedMessageMetadata: spaces/{space}/messages/{message}/quotedMessageMetadata/{quoted_message_metadata}
  • reaction: spaces/{space}/messages/{message}/reactions/{reaction}
  • space: spaces/{space}
  • spaceReadState: users/{user}/spaces/{space}/spaceReadState
  • thread: spaces/{space}/threads/{thread}
  • threadReadState: users/{user}/spaces/{space}/threads/{thread}/threadReadState

The optional $template argument can be supplied to specify a particular pattern, and must match one of the templates listed above. If no $template argument is provided, or if the $template argument does not match one of the templates listed, then parseName will check each of the supported templates, and return the first match.

Parameters
Name Description
formattedName string

The formatted name string

template string

Optional name of template to match

Returns
Type Description
array An associative array from name component IDs to component values.