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', () => {
});
Then load api client wrapper:
gapi.client.load(
'https://chat.googleapis.com/$discovery/rest?version=v1',
() => {
}
);
gapi.client.load('chat', 'v1', () => {
});
Don't forget to authenticate your client before sending any request to resources:
var client_id = '',
scope = [
'https://www.googleapis.com/auth/chat.bot',
'https://www.googleapis.com/auth/chat.delete',
'https://www.googleapis.com/auth/chat.import',
'https://www.googleapis.com/auth/chat.memberships',
'https://www.googleapis.com/auth/chat.memberships.app',
'https://www.googleapis.com/auth/chat.memberships.readonly',
'https://www.googleapis.com/auth/chat.messages',
'https://www.googleapis.com/auth/chat.messages.create',
'https://www.googleapis.com/auth/chat.messages.reactions',
'https://www.googleapis.com/auth/chat.messages.reactions.create',
'https://www.googleapis.com/auth/chat.messages.reactions.readonly',
'https://www.googleapis.com/auth/chat.messages.readonly',
'https://www.googleapis.com/auth/chat.spaces',
'https://www.googleapis.com/auth/chat.spaces.create',
'https://www.googleapis.com/auth/chat.spaces.readonly',
'https://www.googleapis.com/auth/chat.users.readstate',
'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) {
} else {
}
}
);
After that you can use Google Chat API resources:
await gapi.client.chat.media.download({resourceName: 'resourceName'});
await gapi.client.chat.media.upload({parent: 'parent'});
await gapi.client.chat.spaces.completeImport({name: 'name'});
await gapi.client.chat.spaces.create({});
await gapi.client.chat.spaces.delete({name: 'name'});
await gapi.client.chat.spaces.findDirectMessage({});
await gapi.client.chat.spaces.get({name: 'name'});
await gapi.client.chat.spaces.list({});
await gapi.client.chat.spaces.patch({name: 'name'});
await gapi.client.chat.spaces.setup({});