mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20:24:05 -08:00
feat(Pushover Node): Add 'HTML Formatting' option and credential test (#3082)
* Add html additional field https://pushover.net/api#html * ⚡ replaced input type to boolean, added credential test * ⚡ credentials and linter fixes * ⚡ Improvements * ⚡ Fix description Co-authored-by: Michael Kret <michael.k@radency.com> Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
This commit is contained in:
parent
63b6c9f128
commit
b3dc6d9d9c
|
@ -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<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',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 2.7 KiB |
4
packages/nodes-base/nodes/Pushover/pushover.svg
Normal file
4
packages/nodes-base/nodes/Pushover/pushover.svg
Normal file
|
@ -0,0 +1,4 @@
|
|||
<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="512" cy="512" r="512" style="fill:#249df1"/>
|
||||
<path d="m495.6 319.4 104-13.7-101.3 228.6c17.8-1.4 35.2-7.4 52.3-18.1 17.1-10.7 32.9-24.2 47.2-40.4 14.4-16.2 26.8-34.2 37.3-54.1 10.5-19.8 18-39.4 22.6-58.5 2.7-11.9 4-23.3 3.8-34.2-.2-10.9-3.1-20.5-8.6-28.7s-13.8-14.8-25-19.8-26.3-7.5-45.5-7.5c-22.4 0-44.4 3.6-66 10.9-21.7 7.3-41.7 17.9-60.2 31.8-18.5 13.9-34.5 31.2-48.2 52-13.7 20.8-23.5 44.4-29.4 70.8-2.3 8.7-3.6 15.6-4.1 20.9-.5 5.3-.6 9.6-.3 13 .2 3.4.7 6.1 1.4 7.9.7 1.8 1.3 3.6 1.7 5.5-23.3 0-40.3-4.7-51-14-10.7-9.3-13.3-25.7-7.9-48.9 5.5-24.2 17.9-47.2 37.3-69.1 19.4-21.9 42.4-41.2 69.1-57.8 26.7-16.6 55.9-29.9 87.6-39.7 31.7-9.8 62.6-14.7 92.7-14.7 26.5 0 48.7 3.8 66.7 11.3 18 7.5 32.1 17.5 42.1 29.8s16.3 26.7 18.8 43.1c2.5 16.4 1.7 33.5-2.4 51.3-5 21.4-14.5 43-28.4 64.7-13.9 21.7-31.4 41.3-52.3 58.8-21 17.6-45 31.8-72.2 42.8-27.1 10.9-56 16.4-86.6 16.4h-3.4l-86.9 195H302l193.6-435.4z" style="fill:#fff"/>
|
||||
</svg>
|
After Width: | Height: | Size: 1,013 B |
Loading…
Reference in a new issue