Skip to content

Commit

Permalink
⚡ Improvemvents
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoE105 committed Feb 16, 2022
1 parent b973e33 commit 00c3b1e
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 93 deletions.
10 changes: 7 additions & 3 deletions packages/nodes-base/nodes/Google/Chat/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF

const { access_token } = await getAccessToken.call(this, credentials as ICredentialDataDecryptedObject);
options.headers!.Authorization = `Bearer ${access_token}`;

console.log(options);
//@ts-ignore
responseData = await this.helpers.request(options);
}
} catch (error) {
if (error.code === 'ERR_OSSL_PEM_NO_START_LINE') {
error.statusCode = '401';
}

throw new NodeApiError(this.getNode(), error);
}
if(Object.keys(responseData as IDataObject).length !== 0) {
Expand Down Expand Up @@ -166,12 +167,15 @@ export function getPagingParameters(resource: string, operation = 'getAll') {
},
},
default: false,
description: 'If all results should be returned or only up to a given limit.',
description: 'If all results should be returned or only up to a given limit',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
typeOptions: {
maxValue: 1000,
},
displayOptions: {
show: {
resource: [
Expand All @@ -186,7 +190,7 @@ export function getPagingParameters(resource: string, operation = 'getAll') {
},
},
default: 100,
description: 'The limit of records to return. The value is capped at 1000. Server may return fewer results than requested. If unspecified, server will default to 100.',
description: 'How many results to return',
},
];
return pagingParameters;
Expand Down
87 changes: 43 additions & 44 deletions packages/nodes-base/nodes/Google/Chat/GoogleChat.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import {
IMessageUi,
} from './MessageInterface';

import {
OptionsWithUri
} from 'request';

import {
attachmentFields,
attachmentOperations,
Expand All @@ -44,9 +48,6 @@ import {
import * as moment from 'moment-timezone';

import * as jwt from 'jsonwebtoken';

import { OptionsWithUri } from 'request';

export class GoogleChat implements INodeType {
description: INodeTypeDescription = {
displayName: 'Google Chat',
Expand All @@ -65,7 +66,7 @@ export class GoogleChat implements INodeType {
credentials: [
{
name: 'googleApi',
required: false, // not required, webhooks do not need credentials
required: true,
testedBy: 'testGoogleTokenAuth',
},
],
Expand All @@ -77,18 +78,18 @@ export class GoogleChat implements INodeType {
noDataExpression: true,
type: 'options',
options: [
{
name: 'Attachment',
value: 'attachment',
},
{
name: 'Incoming Webhook',
value: 'incomingWebhook',
},
{
name: 'Media',
value: 'media',
},
// {
// name: 'Attachment',
// value: 'attachment',
// },
// {
// name: 'Incoming Webhook',
// value: 'incomingWebhook',
// },
// {
// name: 'Media',
// value: 'media',
// },
{
name: 'Member',
value: 'member',
Expand All @@ -105,12 +106,12 @@ export class GoogleChat implements INodeType {
default: 'message',
description: 'The resource to operate on',
},
...attachmentOperations,
...attachmentFields,
...incomingWebhookOperations,
...incomingWebhookFields,
...mediaOperations,
...mediaFields,
// ...attachmentOperations,
// ...attachmentFields,
// ...incomingWebhookOperations,
// ...incomingWebhookFields,
// ...mediaOperations,
// ...mediaFields,
...memberOperations,
...memberFields,
...messageOperations,
Expand All @@ -135,11 +136,9 @@ export class GoogleChat implements INodeType {
`/v1/spaces`,
);
for (const space of spaces) {
const spaceName = space.name;
const spaceId = space.name;
returnData.push({
name: spaceName,
value: spaceId,
name: space.displayName,
value: space.name,
});
}
return returnData;
Expand Down Expand Up @@ -276,12 +275,12 @@ export class GoogleChat implements INodeType {

// https://developers.google.com/chat/reference/rest/v1/spaces/get

const spaceName = this.getNodeParameter('spaceName', i) as string;
const spaceId = this.getNodeParameter('spaceId', i) as string;

responseData = await googleApiRequest.call(
this,
'GET',
`/v1/${spaceName}`,
`/v1/${spaceId}`,
);

} else if (operation === 'getAll') {
Expand All @@ -302,7 +301,7 @@ export class GoogleChat implements INodeType {
);
} else {
const limit = this.getNodeParameter('limit', i) as number;
qs.pageSize = limit >>> 0; // convert to an unsigned 32-bit integer
qs.pageSize = limit;

responseData = await googleApiRequest.call(
this,
Expand All @@ -323,12 +322,12 @@ export class GoogleChat implements INodeType {

// https://developers.google.com/chat/reference/rest/v1/spaces.members/get

const memberName = this.getNodeParameter('memberName', i) as string;
const memberId = this.getNodeParameter('memberId', i) as string;

responseData = await googleApiRequest.call(
this,
'GET',
`/v1/${memberName}`,
`/v1/${memberId}`,
);

} else if (operation === 'getAll') {
Expand All @@ -339,27 +338,27 @@ export class GoogleChat implements INodeType {

// https://developers.google.com/chat/reference/rest/v1/spaces.members/list

const spaceName = this.getNodeParameter('spaceName', i) as string;
const spaceId = this.getNodeParameter('spaceId', i) as string;

const returnAll = this.getNodeParameter('returnAll', 0) as IDataObject;
if (returnAll) {
responseData = await googleApiRequestAllItems.call(
this,
'memberships',
'GET',
`/v1/${spaceName}/members`,
`/v1/${spaceId}/members`,
undefined,
qs,
);

} else {
const limit = this.getNodeParameter('limit', i) as number;
qs.pageSize = limit >>> 0; // convert to an unsigned 32-bit integer
qs.pageSize = limit;

responseData = await googleApiRequest.call(
this,
'GET',
`/v1/${spaceName}/members`,
`/v1/${spaceId}/members`,
undefined,
qs,
);
Expand All @@ -376,7 +375,7 @@ export class GoogleChat implements INodeType {

// https://developers.google.com/chat/reference/rest/v1/spaces.messages/create

const spaceName = this.getNodeParameter('spaceName', i) as string;
const spaceId = this.getNodeParameter('spaceId', i) as string;

// get additional fields for threadKey and requestId
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
Expand Down Expand Up @@ -424,7 +423,7 @@ export class GoogleChat implements INodeType {
responseData = await googleApiRequest.call(
this,
'POST',
`/v1/${spaceName}/messages`,
`/v1/${spaceId}/messages`,
body,
qs,
);
Expand All @@ -437,12 +436,12 @@ export class GoogleChat implements INodeType {

// https://developers.google.com/chat/reference/rest/v1/spaces.messages/delete

const messageName = this.getNodeParameter('messageName', i) as string;
const messageId = this.getNodeParameter('messageId', i) as string;

responseData = await googleApiRequest.call(
this,
'DELETE',
`/v1/${messageName}`,
`/v1/${messageId}`,
);

} else if (operation === 'get') {
Expand All @@ -453,12 +452,12 @@ export class GoogleChat implements INodeType {

// https://developers.google.com/chat/reference/rest/v1/spaces.messages/get

const messageName = this.getNodeParameter('messageName', i) as string;
const messageId = this.getNodeParameter('messageId', i) as string;

responseData = await googleApiRequest.call(
this,
'GET',
`/v1/${messageName}`,
`/v1/${messageId}`,
);

} else if (operation === 'update') {
Expand All @@ -469,7 +468,7 @@ export class GoogleChat implements INodeType {

// https://developers.google.com/chat/reference/rest/v1/spaces.messages/update

const messageName = this.getNodeParameter('messageName', i) as string;
const messageId = this.getNodeParameter('messageId', i) as string;

let message: IMessage = {};
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
Expand Down Expand Up @@ -516,7 +515,7 @@ export class GoogleChat implements INodeType {
responseData = await googleApiRequest.call(
this,
'PUT',
`/v1/${messageName}`,
`/v1/${messageId}`,
body,
qs,
);
Expand Down Expand Up @@ -602,7 +601,7 @@ export class GoogleChat implements INodeType {
} else if (responseData !== undefined) {
returnData.push(responseData as IDataObject);
}
} catch (error) {
} catch (error) {
if (this.continueOnFail()) {
// Return the actual reason as error
if (operation === 'download') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ export const memberOperations: INodeProperties[] = [
{
name: 'Get',
value: 'get',
description: 'Returns a membership',
description: 'Get a membership',
},
{
name: 'Get All',
value: 'getAll',
description: 'Lists human memberships in a space',
description: 'Get all memberships in a space',
},
],
default: 'get',
Expand All @@ -38,11 +38,11 @@ export const memberOperations: INodeProperties[] = [

export const memberFields: INodeProperties[] = [
/* -------------------------------------------------------------------------- */
/* member:get */
/* member:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'Member Name',
name: 'memberName',
displayName: 'Member ID',
name: 'memberId',
type: 'string',
required: true,
displayOptions: {
Expand All @@ -63,8 +63,8 @@ export const memberFields: INodeProperties[] = [
/* member:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'Space Name',
name: 'spaceName',
displayName: 'Space Name/ID',
name: 'spaceId',
type: 'options',
required: true,
typeOptions: {
Expand Down
Loading

0 comments on commit 00c3b1e

Please sign in to comment.