0.0.20240509 • Published 5 days ago

@maxim_mazurok/gapi.client.chat-v1 v0.0.20240509

Weekly downloads
-
License
MIT
Repository
github
Last release
5 days ago

TypeScript typings for Google Chat API v1

The Google Chat API lets you build Chat apps to integrate your services with Google Chat and manage Chat resources such as spaces, members, and messages. For detailed description please check documentation.

Installing

Install typings for Google Chat API:

npm install @types/gapi.client.chat-v1 --save-dev

Usage

You need to initialize Google API client in your code:

gapi.load('client', () => {
  // now we can use gapi.client
  // ...
});

Then load api client wrapper:

gapi.client.load(
  'https://chat.googleapis.com/$discovery/rest?version=v1',
  () => {
    // now we can use:
    // gapi.client.chat
  }
);
// Deprecated, use discovery document URL, see https://github.com/google/google-api-javascript-client/blob/master/docs/reference.md#----gapiclientloadname----version----callback--
gapi.client.load('chat', 'v1', () => {
  // now we can use:
  // gapi.client.chat
});

Don't forget to authenticate your client before sending any request to resources:

// declare client_id registered in Google Developers Console
var client_id = '',
  scope = [
    // Private Service: https://www.googleapis.com/auth/chat.bot
    'https://www.googleapis.com/auth/chat.bot',

    // Delete conversations and spaces & remove access to associated files in Google Chat
    'https://www.googleapis.com/auth/chat.delete',

    // Import spaces, messages, and memberships into Google Chat.
    'https://www.googleapis.com/auth/chat.import',

    // View, add, update, and remove members from conversations in Google Chat
    'https://www.googleapis.com/auth/chat.memberships',

    // Add and remove itself from conversations in Google Chat
    'https://www.googleapis.com/auth/chat.memberships.app',

    // View members in Google Chat conversations.
    'https://www.googleapis.com/auth/chat.memberships.readonly',

    // View, compose, send, update, and delete messages, and add, view, and delete reactions to messages.
    'https://www.googleapis.com/auth/chat.messages',

    // Compose and send messages in Google Chat
    'https://www.googleapis.com/auth/chat.messages.create',

    // View, add, and delete reactions to messages in Google Chat
    'https://www.googleapis.com/auth/chat.messages.reactions',

    // Add reactions to messages in Google Chat
    'https://www.googleapis.com/auth/chat.messages.reactions.create',

    // View reactions to messages in Google Chat
    'https://www.googleapis.com/auth/chat.messages.reactions.readonly',

    // View messages and reactions in Google Chat
    'https://www.googleapis.com/auth/chat.messages.readonly',

    // Create conversations and spaces and see or edit metadata (including history settings and access settings) in Google Chat
    'https://www.googleapis.com/auth/chat.spaces',

    // Create new conversations in Google Chat
    'https://www.googleapis.com/auth/chat.spaces.create',

    // View chat and spaces in Google Chat
    'https://www.googleapis.com/auth/chat.spaces.readonly',

    // View and modify last read time for Google Chat conversations
    'https://www.googleapis.com/auth/chat.users.readstate',

    // View last read time for Google Chat conversations
    'https://www.googleapis.com/auth/chat.users.readstate.readonly',
  ],
  immediate = true;
// ...

gapi.auth.authorize(
  {client_id: client_id, scope: scope, immediate: immediate},
  authResult => {
    if (authResult && !authResult.error) {
      /* handle successful authorization */
    } else {
      /* handle authorization error */
    }
  }
);

After that you can use Google Chat API resources:

/*
Downloads media. Download is supported on the URI `/v1/media/{+name}?alt=media`.
*/
await gapi.client.chat.media.download({resourceName: 'resourceName'});

/*
Uploads an attachment. For an example, see [Upload media as a file attachment](https://developers.google.com/workspace/chat/upload-media-attachments). Requires user [authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user). You can upload attachments up to 200 MB. Certain file types aren't supported. For details, see [File types blocked by Google Chat](https://support.google.com/chat/answer/7651457?&co=GENIE.Platform%3DDesktop#File%20types%20blocked%20in%20Google%20Chat).
*/
await gapi.client.chat.media.upload({parent: 'parent'});

/*
Completes the [import process](https://developers.google.com/workspace/chat/import-data) 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](https://developers.google.com/workspace/chat/authorize-import).
*/
await gapi.client.chat.spaces.completeImport({name: 'name'});

/*
Creates a named space. Spaces grouped by topics aren't supported. For an example, see [Create a space](https://developers.google.com/workspace/chat/create-spaces). 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](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user).
*/
await gapi.client.chat.spaces.create({});

/*
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](https://developers.google.com/workspace/chat/delete-spaces). Requires [user authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user) from a user who has permission to delete the space.
*/
await gapi.client.chat.spaces.delete({name: 'name'});

/*
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](/chat/api/guides/v1/spaces/find-direct-message). With [user authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user), returns the direct message space between the specified user and the authenticated user. With [app authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-app), returns the direct message space between the specified user and the calling Chat app. Requires [user authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user) or [app authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-app).
*/
await gapi.client.chat.spaces.findDirectMessage({});

/*
Returns details about a space. For an example, see [Get details about a space](https://developers.google.com/workspace/chat/get-spaces). Requires [authentication](https://developers.google.com/workspace/chat/authenticate-authorize). Supports [app authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-app) and [user authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user).
*/
await gapi.client.chat.spaces.get({name: 'name'});

/*
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](https://developers.google.com/workspace/chat/list-spaces). Requires [authentication](https://developers.google.com/workspace/chat/authenticate-authorize). Supports [app authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-app) and [user authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user). Lists spaces visible to the caller or authenticated user. Group chats and DMs aren't listed until the first message is sent. 
*/
await gapi.client.chat.spaces.list({});

/*
Updates a space. For an example, see [Update a space](https://developers.google.com/workspace/chat/update-spaces). 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](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user).
*/
await gapi.client.chat.spaces.patch({name: 'name'});

/*
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](https://developers.google.com/workspace/chat/set-up-spaces). 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](https://developers.google.com/workspace/chat/create-members). 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](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user).
*/
await gapi.client.chat.spaces.setup({});
0.0.20240509

5 days ago

0.0.20240507

13 days ago

0.0.20240427

20 days ago

0.0.20240425

22 days ago

0.0.20240420

26 days ago

0.0.20240418

29 days ago

0.0.20240423

25 days ago

0.0.20240416

1 month ago

0.0.20240411

1 month ago

0.0.20240414

1 month ago

0.0.20240404

1 month ago

0.0.20240402

2 months ago

0.0.20240331

2 months ago

0.0.20240326

2 months ago

0.0.20240324

2 months ago

0.0.20240321

2 months ago

0.0.20240319

2 months ago

0.0.20240317

2 months ago

0.0.20240315

2 months ago

0.0.20240312

2 months ago

0.0.20240310

2 months ago

0.0.20240305

2 months ago

0.0.20240303

3 months ago

0.0.20240227

3 months ago

0.0.20240222

3 months ago

0.0.20240223

3 months ago

0.0.20240220

3 months ago

0.0.20240211

3 months ago

0.0.20240208

3 months ago

0.0.20240204

3 months ago

0.0.20240201

4 months ago

0.0.20240130

4 months ago

0.0.20240128

4 months ago

0.0.20240123

4 months ago

0.0.20240118

4 months ago

0.0.20240117

4 months ago

0.0.20240111

4 months ago

0.0.20240109

4 months ago

0.0.20240104

4 months ago

0.0.20240102

5 months ago

0.0.20231228

5 months ago

0.0.20231217

5 months ago

0.0.20231214

5 months ago

0.0.20231212

5 months ago

0.0.20231207

6 months ago

0.0.20231203

6 months ago

0.0.20231130

6 months ago

0.0.20230816

9 months ago

0.0.20231105

7 months ago

0.0.20231114

6 months ago

0.0.20230928

8 months ago

0.0.20230808

9 months ago

0.0.20230926

8 months ago

0.0.20230806

10 months ago

0.0.20230921

8 months ago

0.0.20230803

10 months ago

0.0.20230801

10 months ago

0.0.20231102

7 months ago

0.0.20230718

10 months ago

0.0.20230711

10 months ago

0.0.20231008

7 months ago

0.0.20230831

9 months ago

0.0.20230716

10 months ago

0.0.20231012

7 months ago

0.0.20231011

7 months ago

0.0.20230829

9 months ago

0.0.20230708

10 months ago

0.0.20230827

9 months ago

0.0.20230706

11 months ago

0.0.20230821

9 months ago

0.0.20231116

6 months ago

0.0.20230822

9 months ago

0.0.20230704

11 months ago

0.0.20231121

6 months ago

0.0.20231003

8 months ago

0.0.20231005

7 months ago

0.0.20231029

7 months ago

0.0.20230729

10 months ago

0.0.20231017

7 months ago

0.0.20230723

10 months ago

0.0.20231019

7 months ago

0.0.20230727

10 months ago

0.0.20231024

7 months ago

0.0.20231026

7 months ago

0.0.20230910

8 months ago

0.0.20230914

8 months ago

0.0.20230912

8 months ago

0.0.20230629

11 months ago

0.0.20230905

9 months ago

0.0.20230627

11 months ago

0.0.20230903

9 months ago

0.0.20230622

11 months ago

0.0.20230625

11 months ago

0.0.20230618

11 months ago

0.0.20230611

11 months ago

0.0.20230608

11 months ago

0.0.20230525

12 months ago

0.0.20230606

12 months ago

0.0.20230603

12 months ago

0.0.20230530

12 months ago

0.0.20230514

1 year ago

0.0.20230518

12 months ago

0.0.20230516

1 year ago

0.0.20230521

12 months ago

0.0.20230502

1 year ago

0.0.20230504

1 year ago

0.0.20230427

1 year ago

0.0.20230412

1 year ago

0.0.20230413

1 year ago

0.0.20230418

1 year ago

0.0.20230420

1 year ago

0.0.20230326

1 year ago

0.0.20230404

1 year ago

0.0.20230402

1 year ago

0.0.20230328

1 year ago

0.0.20230406

1 year ago

0.0.20230330

1 year ago

0.0.20230314

1 year ago

0.0.20230319

1 year ago

0.0.20230323

1 year ago

0.0.20230425

1 year ago

0.0.20230304

1 year ago

0.0.20230423

1 year ago

0.0.20230302

1 year ago

0.0.20230309

1 year ago

0.0.20230307

1 year ago

0.0.20230312

1 year ago

0.0.20230216

1 year ago

0.0.20230219

1 year ago

0.0.20230221

1 year ago

0.0.20230205

1 year ago

0.0.20230129

1 year ago

0.0.20230126

1 year ago

0.0.20230209

1 year ago

0.0.20230207

1 year ago

0.0.20230131

1 year ago

0.0.20230212

1 year ago

0.0.20230202

1 year ago

0.0.20221115

1 year ago

0.0.20230115

1 year ago

0.0.20221213

1 year ago

0.0.20221112

2 years ago

0.0.20230119

1 year ago

0.0.20221110

2 years ago

0.0.20221208

1 year ago

0.0.20230103

1 year ago

0.0.20221206

1 year ago

0.0.20230123

1 year ago

0.0.20230101

1 year ago

0.0.20221204

1 year ago

0.0.20221105

2 years ago

0.0.20221126

1 year ago

0.0.20221103

2 years ago

0.0.20221122

1 year ago

0.0.20221120

1 year ago

0.0.20221219

1 year ago

0.0.20221013

2 years ago

0.0.20221011

2 years ago

0.0.20221009

2 years ago

0.0.20221029

2 years ago

0.0.20221020

2 years ago

0.0.20221006

2 years ago

0.0.20221027

2 years ago

0.0.20221025

2 years ago

0.0.20221101

2 years ago

0.0.20221001

2 years ago

0.0.20220927

2 years ago

0.0.20221019

2 years ago

0.0.20220925

2 years ago

0.0.20220917

2 years ago

0.0.20220906

2 years ago

0.0.20220818

2 years ago

0.0.20220819

2 years ago

0.0.20220920

2 years ago

0.0.20220914

2 years ago

0.0.20220826

2 years ago

0.0.20220915

2 years ago

0.0.20220904

2 years ago

0.0.20220816

2 years ago

0.0.20220811

2 years ago

0.0.20220805

2 years ago