diff --git a/packages/nodes-base/credentials/PushoverApi.credentials.ts b/packages/nodes-base/credentials/PushoverApi.credentials.ts index 9cd9ba589d..53a0c1e1e6 100644 --- a/packages/nodes-base/credentials/PushoverApi.credentials.ts +++ b/packages/nodes-base/credentials/PushoverApi.credentials.ts @@ -1,5 +1,8 @@ import { + ICredentialDataDecryptedObject, + ICredentialTestRequest, ICredentialType, + IHttpRequestOptions, INodeProperties, } from 'n8n-workflow'; @@ -15,4 +18,19 @@ export class PushoverApi implements ICredentialType { default: '', }, ]; + async authenticate(credentials: ICredentialDataDecryptedObject, requestOptions: IHttpRequestOptions): Promise { + if (requestOptions.method === 'GET') { + Object.assign(requestOptions.qs, { token: credentials.apiKey }); + } else { + Object.assign(requestOptions.body, { token: credentials.apiKey }); + } + return requestOptions; + } + test: ICredentialTestRequest = { + request: { + baseURL: 'https://api.pushover.net/1', + url: '=/licenses.json?token={{$credentials?.apiKey}}', + method: 'GET', + }, + }; } diff --git a/packages/nodes-base/nodes/Pushover/GenericFunctions.ts b/packages/nodes-base/nodes/Pushover/GenericFunctions.ts index 5b08c58397..421a7bd9ed 100644 --- a/packages/nodes-base/nodes/Pushover/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Pushover/GenericFunctions.ts @@ -9,32 +9,28 @@ import { } from 'n8n-core'; import { - IDataObject, NodeApiError, + IDataObject, IHttpRequestMethods, IHttpRequestOptions, NodeApiError, } from 'n8n-workflow'; -export async function pushoverApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, path: string, body: any = {}, qs: IDataObject = {}, option = {}): Promise { // tslint:disable-line:no-any +export async function pushoverApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: IHttpRequestMethods, path: string, body: any = {}, qs: IDataObject = {}, option = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('pushoverApi'); - - if (method === 'GET') { - qs.token = credentials.apiKey; - } else { - body.token = credentials.apiKey as string; - } - - const options: OptionsWithUri = { + const options: IHttpRequestOptions = { + headers: { + 'Content-Type': 'multipart/form-data', + }, method, - formData: body, + body, qs, - uri: `https://api.pushover.net/1${path}`, + url: `https://api.pushover.net/1${path}`, json: true, }; + try { if (Object.keys(body).length === 0) { delete options.body; } - //@ts-ignore - return await this.helpers.request.call(this, options); + + return await this.helpers.requestWithAuthentication.call(this, 'pushoverApi', options); } catch (error) { throw new NodeApiError(this.getNode(), error); } diff --git a/packages/nodes-base/nodes/Pushover/Pushover.node.ts b/packages/nodes-base/nodes/Pushover/Pushover.node.ts index 8853d31ac6..0168288d39 100644 --- a/packages/nodes-base/nodes/Pushover/Pushover.node.ts +++ b/packages/nodes-base/nodes/Pushover/Pushover.node.ts @@ -22,7 +22,7 @@ export class Pushover implements INodeType { description: INodeTypeDescription = { displayName: 'Pushover', name: 'pushover', - icon: 'file:pushover.png', + icon: 'file:pushover.svg', group: ['input'], version: 1, subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', @@ -43,6 +43,7 @@ export class Pushover implements INodeType { displayName: 'Resource', name: 'resource', type: 'options', + noDataExpression: true, options: [ { name: 'Message', @@ -50,12 +51,13 @@ export class Pushover implements INodeType { }, ], default: 'message', - description: 'The resource to operate on.', + description: 'The resource to operate on', }, { displayName: 'Operation', name: 'operation', type: 'options', + noDataExpression: true, displayOptions: { show: { resource: [ @@ -70,7 +72,7 @@ export class Pushover implements INodeType { }, ], default: 'push', - description: 'The resource to operate on.', + description: 'The resource to operate on', }, { displayName: 'User Key', @@ -149,7 +151,7 @@ export class Pushover implements INodeType { description: 'Send as -2 to generate no notification/alert, -1 to always send as a quiet notification, 1 to display as high-priority and bypass the user\'s quiet hours, or 2 to also require confirmation from the user', }, { - displayName: 'Retry (seconds)', + displayName: 'Retry (Seconds)', name: 'retry', type: 'number', typeOptions: { @@ -173,7 +175,7 @@ export class Pushover implements INodeType { description: 'Specifies how often (in seconds) the Pushover servers will send the same notification to the user. This parameter must have a value of at least 30 seconds between retries.', }, { - displayName: 'Expire (seconds)', + displayName: 'Expire (Seconds)', name: 'expire', type: 'number', typeOptions: { @@ -247,6 +249,13 @@ export class Pushover implements INodeType { default: '', description: 'Your user\'s device name to send the message directly to that device, rather than all of the user\'s devices (multiple devices may be separated by a comma)', }, + { + displayName: 'HTML Formatting', + name: 'html', + type: 'boolean', + default: false, + description: 'Whether to enable messages formatting with HTML tags', + }, { displayName: 'Sound', name: 'sound', @@ -257,6 +266,13 @@ export class Pushover implements INodeType { default: '', description: 'The name of one of the sounds supported by device clients to override the user\'s default sound choice', }, + { + displayName: 'Timestamp', + name: 'timestamp', + type: 'dateTime', + default: '', + description: 'A Unix timestamp of your message\'s date and time to display to the user, rather than the time your message is received by our API', + }, { displayName: 'Title', name: 'title', @@ -276,7 +292,7 @@ export class Pushover implements INodeType { name: 'url', type: 'string', default: '', - description: 'a supplementary URL to show with your message', + description: 'A supplementary URL to show with your message', }, { displayName: 'URL Title', @@ -326,6 +342,10 @@ export class Pushover implements INodeType { const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; + if (additionalFields.html !== undefined) { + additionalFields.html = additionalFields.html ? '1' : ''; + } + const body: IDataObject = { user: userKey, message, diff --git a/packages/nodes-base/nodes/Pushover/pushover.png b/packages/nodes-base/nodes/Pushover/pushover.png deleted file mode 100644 index 6eb277a25f..0000000000 Binary files a/packages/nodes-base/nodes/Pushover/pushover.png and /dev/null differ diff --git a/packages/nodes-base/nodes/Pushover/pushover.svg b/packages/nodes-base/nodes/Pushover/pushover.svg new file mode 100644 index 0000000000..4d262ce497 --- /dev/null +++ b/packages/nodes-base/nodes/Pushover/pushover.svg @@ -0,0 +1,4 @@ + + + +