Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add html additional field for pushover #3082

Merged
merged 8 commits into from
May 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/nodes-base/credentials/PushoverApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {
ICredentialDataDecryptedObject,
ICredentialTestRequest,
ICredentialType,
IHttpRequestOptions,
INodeProperties,
} from 'n8n-workflow';

Expand All @@ -15,4 +18,19 @@ export class PushoverApi implements ICredentialType {
default: '',
},
];
async authenticate(credentials: ICredentialDataDecryptedObject, requestOptions: IHttpRequestOptions): Promise<IHttpRequestOptions> {
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',
},
};
}
26 changes: 11 additions & 15 deletions packages/nodes-base/nodes/Pushover/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> { // tslint:disable-line:no-any
export async function pushoverApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: IHttpRequestMethods, path: string, body: any = {}, qs: IDataObject = {}, option = {}): Promise<any> { // 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);
}
Expand Down
32 changes: 26 additions & 6 deletions packages/nodes-base/nodes/Pushover/Pushover.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}}',
Expand All @@ -43,19 +43,21 @@ export class Pushover implements INodeType {
displayName: 'Resource',
name: 'resource',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Message',
value: 'message',
},
],
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: [
Expand All @@ -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',
Expand Down Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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,
Expand Down
Binary file removed packages/nodes-base/nodes/Pushover/pushover.png
Binary file not shown.
4 changes: 4 additions & 0 deletions packages/nodes-base/nodes/Pushover/pushover.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.