# Users - Chat - [API documentation](#api-documentation) - [Introduction](#introduction) - [Developer Preview Admin Access](#developer-preview-admin-access) - [Set up a Chat Bot](#set-up-a-chat-bot) - [Definitions](#definitions) - [Manage Chat Spaces](#manage-chat-spaces) - [Display Chat Spaces](#display-chat-spaces) - [Manage Chat Members](#manage-chat-members) - [Display Chat Members](#display-chat-members) - [Manage Chat Messages](#manage-chat-messages) - [Display Chat Messages](#display-chat-messages) - [Display Chat Events](#display-chat-events) - [Bulk Operations](#bulk-operations) ## API documentation * https://developers.google.com/workspace/chat/overview * https://developers.google.com/workspace/chat/api/reference/rest * https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces.members/list * https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces.messages/list * https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces.spaceEvents/list * https://support.google.com/chat/answer/7655820 * https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces/search ## Introduction These features were added in version 6.60.00. To use these commands you must update your service account authorization. ``` gam user user@domain.com update serviceaccount [*] 4) Chat API - Memberships (supports readonly) [*] 6) Chat API - Messages (supports readonly) [*] 7) Chat API - Spaces (supports readonly) [*] 9) Chat API - Spaces Delete ``` ## Developer Preview Admin Access The Chat API Developer Preview allows an admin to perform certain actions on all Chat Spaces. These commands were added in version 6.77.00. You must be enrolled in the Developer Preview program for the CHAT API to use these commands. ``` gam delete chatspace asadmin gam update chatspace asadmin gam info chatspace asadmin gam print|show chatspaces asadmin gam create chatmember asadmin gam delete|remove chatmember asadmin gam update|modify chatmember asadmin gam sync chatmembers asadmin gam info chatmember asadmin gam print|show chatmembers|asadmin ``` To use these commands you must update your service account authorization. ``` gam user user@domain.com update serviceaccount [*] 5) Chat API - Memberships Admin (supports readonly) [*] 8) Chat API - Spaces Admin (supports readonly) [*] 10) Chat API - Spaces Delete Admin ``` Added `use_chat_admin_access` Boolean variable to `gam.cfg`. ``` * When False, GAM uses user access when making all Chat API calls. For calls that support admin access, this can be overridden with the asadmin command line option. * When True, GAM uses admin access for Chat API calls that support admin access; other calls will use user access. * Default: False ``` If your account is not enrolled in the Chat API Developer Preview, you will see errors like this: ``` $ gam user admin@domain.com show chatspaces asadmin Getting all Chat Spaces that match query (customer = "customers/my_customer" AND spaceType = "SPACE") for admin@domain.com(asadmin) Chat Admin: admin@domain.com(asadmin), Show Failed: Method not found. ``` To enroll in the Developer Preview program, see: https://developers.google.com/workspace/preview Google requires that you have a Chat Bot configured in order to use the Chat API; set up a Chat Bot as described in the next section. ## Set up a Chat Bot * Run the command `gam setup chat`; it will point you to a URL to configure your Chat Bot; this is required to use the Chat API. * Enter an App name and Description of your choosing. * For the Avatar URL you can use `https://dummyimage.com/384x256/4d4d4d/0011ff.png&text=+GAM` or a public URL to an image of your own choosing. * In Functionality, uncheck both "Receive 1:1 messages" and "Join spaces and group conversations" * In Connection settings, choose "Cloud Pub/Sub" and enter "no-topic" for the topic name. GAM doesn't yet listen to pub/sub so this option is not used. * In Visibility, uncheck "Make this Chat app available to specific people and groups in Domain Workspace". * Click Save. ## Definitions * [``](Collections-of-Users) * [Drive File Selection](Drive-File-Selection) for symbols not listed here, such as `` * [Command data from Google Docs/Sheets/Storage](Command-Data-From-Google-Docs-Sheets-Storage) ``` ::= ::= ::= https://storage.cloud.google.com//| https://storage.googleapis.com//| gs:///| / ::= ||( ) ::= ((text )| (textfile [charset ])| (gdoc )| (gcsdoc )) ::= spaces//spaceEvents/ ::= spaces//members/ ::= "(,)*" ::= spaces//messages/ ::= spaces/ | space | space spaces/ ::= spaces//threads/ ::= space| groupchat| directmessage ::= "(,)*" ::= client- must contain only lowercase letters, numbers, and hyphens up to 56 characters in length. ``` ``` ::= accesssettings| admininstalled| createtime| displayname| externaluserallowed| importmode| lastactivetime| membershipcount| name| singleuserbotdm| spacedetails| spacehistorystate| spacethreadingstate|threaded| spacetype|type| spaceuri ::= "(,)*" ::= createtime| deletetime| groupmember| member| name| role| state| ::= "(,)*" ::= accessorywidgets| actionresponse| annotations| argumenttext| attachedgifs| attachment| cards| cardsv2| clientassignedmessageid| createtime| deletetime| deletionmetadata| emojireactionsummaries| fallbacktext| formattedtext| lastupdatetime| matchedurl| name| privatemessageviewer| quotedmessagemetadata| sender| slashcommand| space| text| thread| threadreply ::= "(,)*" ``` ## Manage Chat Spaces ### Create a chat space ``` gam create chatspace [type ] [restricted|(audience )] [externalusersallowed ] [members ] [displayname ] [description ] [guidelines ] [history ] [] [formatjson|returnidonly] ``` For `type space`, the following apply: * `members ` - Optional, can not specify more that 20 users * `displayname ` - Required * `description ` - Optional * `guidelines ` - Optional * `history ` - Optional For `type groupchat`, the following apply: * `members ` - Required, must specify between 2 and 20 users * `displayname ` - Ignored * `description ` - Optional * `guidelines ` - Optional * `history ` - Optional For `type directmessage`, the following apply: * `members ` - Required, must specify 1 user * `displayname ` - Ignored * `description ` - Ignored * `guidelines ` - Ignored * `history ` - Optional By default, Gam displays the information about the created chatspace as an indented list of keys and values. * `formatjson` - Display the fields in JSON format. * `returnidonly` - Display the chatspace name only Use the `` option to send an initial message to the created chatspace. The `restricted|audience` options are in Developer Preview and will not be generally available. By default, details about the chatmessage are displayed. * `returnidonly` - Display the chatmessage name only ### Update a user's chat space ``` gam update chatspace [restricted|(audience )]| ([displayname ] [type space] [description ] [guidelines|rules ] [history ]) [formatjson] ``` A groupchat space can be upgraded to a space by specifying `type space` and `displayname `. The `restricted|audience` options can not be combined with options `displayname,type,description,guidelines,history`. They are in Developer Preview and will not be generally available. By default, Gam displays the information about the created chatspace as an indented list of keys and values. * `formatjson` - Display the fields in JSON format. ### Update a chat space, asadmin ``` gam update chatspace asadmin [restricted|(audience )]| ([displayname ] [type space] [description ] [guidelines|rules ] [history ]) [formatjson] ``` A groupchat space can be upgraded to a space by specifying `type space` and `displayname `. The `restricted|audience` options can not be combined with options `displayname,type,description,guidelines,history`. They are in Developer Preview and will not be generally available. By default, Gam displays the information about the created chatspace as an indented list of keys and values. * `formatjson` - Display the fields in JSON format. ### Delete a user's chat space ``` gam delete chatspace ``` ### Delete a chat space, asadmin ``` gam delete chatspace asadmin ``` ## Display Chat Spaces ### Display information about a specific chat space for a user ``` gam info chatspace [fields ] [formatjson] ``` By default, Gam displays the information as an indented list of keys and values. * `formatjson` - Display the fields in JSON format. ### Display information about a direct message chat space between two users ``` gam info chatspacedm [fields ] [formatjson] ``` By default, Gam displays the information as an indented list of keys and values. * `formatjson` - Display the fields in JSON format. ### Display information about all chat spaces for a user ``` gam show chatspaces [types ] [fields ] [formatjson] ``` By default, chat spaces of all types are displayed. * `types ` - Display specific types of spaces. By default, Gam displays the information as an indented list of keys and values. * `formatjson` - Display the fields in JSON format. ``` gam print chatspaces [todrive *] [types ] [fields ] [formatjson [quotechar ]] ``` By default, chat spaces of all types are displayed. * `types ` - Display specific types of spaces. By default, Gam displays the information as columns of fields; the following option causes the output to be in JSON format, * `formatjson` - Display the fields in JSON format. By default, when writing CSV files, Gam uses a quote character of double quote `"`. The quote character is used to enclose columns that contain the quote character itself, the column delimiter (comma by default) and new-line characters. Any quote characters within the column are doubled. When using the `formatjson` option, double quotes are used extensively in the data resulting in hard to read/process output. The `quotechar ` option allows you to choose an alternate quote character, single quote for instance, that makes for readable/processable output. `quotechar` defaults to `gam.cfg/csv_output_quote_char`. When uploading CSV files to Google, double quote `"` should be used. ### Display information about all user's chat spaces ``` # Local file gam config auto_batch_min 1 redirect csv ./AllChatSpaces.csv multiprocess redirect stdout - multiprocess redirect stderr stdout all users print chatspaces # Google sheet gam config auto_batch_min 1 redirect csv - todrive * multiprocess redirect stdout - multiprocess redirect stderr stdout all users print chatspaces ``` Add these options as desired: ``` [types ] [formatjson [quotechar ]] ``` By default, Gam displays the information as columns of fields; the following option causes the output to be in JSON format, * `formatjson` - Display the fields in JSON format. By default, when writing CSV files, Gam uses a quote character of double quote `"`. The quote character is used to enclose columns that contain the quote character itself, the column delimiter (comma by default) and new-line characters. Any quote characters within the column are doubled. When using the `formatjson` option, double quotes are used extensively in the data resulting in hard to read/process output. The `quotechar ` option allows you to choose an alternate quote character, single quote for instance, that makes for readable/processable output. `quotechar` defaults to `gam.cfg/csv_output_quote_char`. When uploading CSV files to Google, double quote `"` should be used. ### Display information about a specific chat space, asadmin ``` gam info chatspace asadmin [fields ] [formatjson] ``` By default, Gam displays the information as an indented list of keys and values. * `formatjson` - Display the fields in JSON format. ### Display information about all chat spaces, asadmin For query and orderby information, see: https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces/search Only spaces of `` `space` are displayed; spaces of `` `groupchat` and `directmessage` are not displayed. ``` gam show chatspaces asadmin [query ] [querytime