mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 06:34:05 -08:00
feat(Mocean Node): Add "Delivery Report URL" option and credential tests (#3075)
* add dlr url column add dlr url(delivery report URl) column. Allow user set the endpoint to receive the report * update update delivery report url description * ⚡ fixed nodelinter issues, added credential test, replaced icon * ⚡ Improvements Co-authored-by: d3no <d3no520@gmail.com> Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
parent
9d703e366b
commit
c89d2b10f2
|
@ -4,7 +4,7 @@ import {
|
|||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject, NodeApiError, NodeOperationError,
|
||||
IDataObject, JsonObject, NodeApiError, NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
/**
|
||||
|
@ -47,6 +47,6 @@ export async function moceanApiRequest(this: IHookFunctions | IExecuteFunctions,
|
|||
try {
|
||||
return await this.helpers.request(options);
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
throw new NodeApiError(this.getNode(), (error as JsonObject));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,29 @@
|
|||
import { IExecuteFunctions } from 'n8n-core';
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
ICredentialsDecrypted,
|
||||
ICredentialTestFunctions,
|
||||
IDataObject,
|
||||
INodeCredentialTestResult,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
JsonObject,
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {moceanApiRequest} from './GenericFunctions';
|
||||
|
||||
import {
|
||||
moceanApiRequest,
|
||||
} from './GenericFunctions';
|
||||
|
||||
export class Mocean implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Mocean',
|
||||
name: 'mocean',
|
||||
icon: 'file:mocean.png',
|
||||
subtitle: `={{$parameter["operation"] + ": " + $parameter["resource"]}}`,
|
||||
icon: 'file:mocean.svg',
|
||||
group: ['transform'],
|
||||
version: 1,
|
||||
description: 'Send SMS and voice messages via Mocean',
|
||||
|
@ -27,6 +36,7 @@ export class Mocean implements INodeType {
|
|||
{
|
||||
name: 'moceanApi',
|
||||
required: true,
|
||||
testedBy: 'moceanApiTest',
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
|
@ -36,7 +46,8 @@ export class Mocean implements INodeType {
|
|||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
options:[
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
{
|
||||
name: 'SMS',
|
||||
value: 'sms',
|
||||
|
@ -52,6 +63,7 @@ export class Mocean implements INodeType {
|
|||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
|
@ -68,7 +80,7 @@ export class Mocean implements INodeType {
|
|||
},
|
||||
],
|
||||
default: 'send',
|
||||
description: 'The operation to perform.',
|
||||
description: 'Operation to perform',
|
||||
},
|
||||
{
|
||||
displayName: 'From',
|
||||
|
@ -88,7 +100,7 @@ export class Mocean implements INodeType {
|
|||
],
|
||||
},
|
||||
},
|
||||
description: 'The number to which to send the message',
|
||||
description: 'Number to which to send the message',
|
||||
},
|
||||
|
||||
{
|
||||
|
@ -109,14 +121,14 @@ export class Mocean implements INodeType {
|
|||
],
|
||||
},
|
||||
},
|
||||
description: 'The number from which to send the message',
|
||||
description: 'Number from which to send the message',
|
||||
},
|
||||
|
||||
{
|
||||
displayName: 'Language',
|
||||
name: 'language',
|
||||
type: 'options',
|
||||
options:[
|
||||
options: [
|
||||
{
|
||||
name: 'Chinese Mandarin (China)',
|
||||
value: 'cmn-CN',
|
||||
|
@ -169,10 +181,66 @@ export class Mocean implements INodeType {
|
|||
],
|
||||
},
|
||||
},
|
||||
description: 'The message to send',
|
||||
description: 'Message to send',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'send',
|
||||
],
|
||||
resource: [
|
||||
'sms',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Delivery Report URL',
|
||||
name: 'dlrUrl',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: '',
|
||||
description: 'Delivery report URL',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
methods = {
|
||||
credentialTest: {
|
||||
async moceanApiTest(this: ICredentialTestFunctions, credential: ICredentialsDecrypted): Promise<INodeCredentialTestResult> {
|
||||
const credentials = credential.data;
|
||||
const query: IDataObject = {};
|
||||
query['mocean-api-key'] = credentials!['mocean-api-key'];
|
||||
query['mocean-api-secret'] = credentials!['mocean-api-secret'];
|
||||
|
||||
const options = {
|
||||
method: 'GET',
|
||||
qs: query,
|
||||
uri: `https://rest.moceanapi.com/rest/2/account/balance`,
|
||||
json: true,
|
||||
};
|
||||
try {
|
||||
await this.helpers.request!(options);
|
||||
} catch (error) {
|
||||
return {
|
||||
status: 'Error',
|
||||
message: `Connection details not valid: ${(error as JsonObject).message}`,
|
||||
};
|
||||
}
|
||||
return {
|
||||
status: 'OK',
|
||||
message: 'Authentication successful!',
|
||||
};
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
|
@ -185,6 +253,7 @@ export class Mocean implements INodeType {
|
|||
let requesetMethod: string;
|
||||
let resource: string;
|
||||
let text: string;
|
||||
let dlrUrl: string;
|
||||
let dataKey: string;
|
||||
// For Post
|
||||
let body: IDataObject;
|
||||
|
@ -196,7 +265,7 @@ export class Mocean implements INodeType {
|
|||
qs = {};
|
||||
try {
|
||||
resource = this.getNodeParameter('resource', itemIndex, '') as string;
|
||||
operation = this.getNodeParameter('operation',itemIndex,'') as string;
|
||||
operation = this.getNodeParameter('operation', itemIndex, '') as string;
|
||||
text = this.getNodeParameter('message', itemIndex, '') as string;
|
||||
requesetMethod = 'POST';
|
||||
body['mocean-from'] = this.getNodeParameter('from', itemIndex, '') as string;
|
||||
|
@ -215,16 +284,21 @@ export class Mocean implements INodeType {
|
|||
dataKey = 'voice';
|
||||
body['mocean-command'] = JSON.stringify(command);
|
||||
endpoint = '/rest/2/voice/dial';
|
||||
} else if(resource === 'sms') {
|
||||
} else if (resource === 'sms') {
|
||||
dlrUrl = this.getNodeParameter('options.dlrUrl', itemIndex, '') as string;
|
||||
dataKey = 'messages';
|
||||
body['mocean-text'] = text;
|
||||
if (dlrUrl !== '') {
|
||||
body['mocean-dlr-url'] = dlrUrl;
|
||||
body['mocean-dlr-mask'] = '1';
|
||||
}
|
||||
endpoint = '/rest/2/sms';
|
||||
} else {
|
||||
throw new NodeOperationError(this.getNode(), `Unknown resource ${resource}`);
|
||||
}
|
||||
|
||||
if (operation === 'send') {
|
||||
const responseData = await moceanApiRequest.call(this,requesetMethod,endpoint,body,qs);
|
||||
const responseData = await moceanApiRequest.call(this, requesetMethod, endpoint, body, qs);
|
||||
|
||||
for (const item of responseData[dataKey] as IDataObject[]) {
|
||||
item.type = resource;
|
||||
|
@ -236,7 +310,7 @@ export class Mocean implements INodeType {
|
|||
}
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message });
|
||||
returnData.push({ error: (error as JsonObject).message });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 669 B |
24
packages/nodes-base/nodes/Mocean/mocean.svg
Normal file
24
packages/nodes-base/nodes/Mocean/mocean.svg
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
|
||||
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
|
||||
width="512.000000pt" height="512.000000pt" viewBox="0 0 512.000000 512.000000"
|
||||
preserveAspectRatio="xMidYMid meet">
|
||||
<metadata>
|
||||
Created by potrace 1.16, written by Peter Selinger 2001-2019
|
||||
</metadata>
|
||||
<g transform="translate(0.000000,512.000000) scale(0.100000,-0.100000)"
|
||||
fill="#0748A6" stroke="none">
|
||||
<path d="M0 2560 l0 -2560 2560 0 2560 0 0 2560 0 2560 -2560 0 -2560 0 0
|
||||
-2560z m1544 1460 c204 -20 306 -107 374 -320 54 -167 640 -1761 648 -1762 5
|
||||
0 46 96 90 213 171 450 574 1519 590 1566 30 90 85 182 137 228 81 74 113 80
|
||||
447 80 l285 0 45 -25 c24 -14 58 -45 75 -68 l30 -44 3 -1375 c2 -1261 1 -1378
|
||||
-14 -1394 -32 -35 -82 -44 -259 -44 -180 0 -227 8 -261 46 -18 20 -19 67 -24
|
||||
1233 l-5 1211 -47 -130 c-26 -71 -221 -615 -432 -1208 -212 -594 -393 -1088
|
||||
-403 -1099 -44 -49 -66 -53 -268 -53 -174 0 -194 2 -237 22 -25 11 -53 32 -62
|
||||
45 -8 12 -82 219 -165 458 -329 959 -660 1916 -669 1940 -8 17 -11 -347 -11
|
||||
-1181 -1 -1194 -1 -1207 -21 -1232 -34 -43 -79 -52 -270 -52 -155 0 -180 2
|
||||
-215 20 -22 11 -45 31 -52 45 -10 20 -12 306 -10 1370 l2 1346 26 49 c31 62
|
||||
92 107 157 116 74 10 407 9 516 -1z"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.3 KiB |
Loading…
Reference in a new issue