2019-10-04 18:06:26 -07:00
|
|
|
import { IExecuteFunctions } from 'n8n-core';
|
|
|
|
import {
|
2020-10-01 05:01:39 -07:00
|
|
|
IDataObject,
|
|
|
|
ILoadOptionsFunctions,
|
2019-10-04 18:06:26 -07:00
|
|
|
INodeExecutionData,
|
|
|
|
INodePropertyOptions,
|
2020-10-01 05:01:39 -07:00
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
2021-04-16 09:33:36 -07:00
|
|
|
NodeApiError,
|
|
|
|
NodeOperationError,
|
2019-10-04 18:06:26 -07:00
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
2019-10-15 10:21:48 -07:00
|
|
|
import { awsApiRequestSOAP } from './GenericFunctions';
|
2019-10-05 06:27:19 -07:00
|
|
|
|
2019-10-05 08:05:58 -07:00
|
|
|
export class AwsSns implements INodeType {
|
2019-10-04 18:06:26 -07:00
|
|
|
description: INodeTypeDescription = {
|
2019-10-05 08:05:58 -07:00
|
|
|
displayName: 'AWS SNS',
|
|
|
|
name: 'awsSns',
|
2021-06-12 12:00:37 -07:00
|
|
|
icon: 'file:sns.svg',
|
2019-10-04 18:06:26 -07:00
|
|
|
group: ['output'],
|
|
|
|
version: 1,
|
|
|
|
subtitle: '={{$parameter["topic"]}}',
|
2019-10-05 08:05:58 -07:00
|
|
|
description: 'Sends data to AWS SNS',
|
2019-10-04 18:06:26 -07:00
|
|
|
defaults: {
|
2019-10-05 08:05:58 -07:00
|
|
|
name: 'AWS SNS',
|
2019-10-05 06:27:19 -07:00
|
|
|
color: '#FF9900',
|
2019-10-04 18:06:26 -07:00
|
|
|
},
|
|
|
|
inputs: ['main'],
|
|
|
|
outputs: ['main'],
|
|
|
|
credentials: [
|
|
|
|
{
|
|
|
|
name: 'aws',
|
|
|
|
required: true,
|
2020-10-22 06:46:03 -07:00
|
|
|
},
|
2019-10-04 18:06:26 -07:00
|
|
|
],
|
|
|
|
properties: [
|
2019-10-15 10:24:45 -07:00
|
|
|
{
|
|
|
|
displayName: 'Operation',
|
|
|
|
name: 'operation',
|
|
|
|
type: 'options',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Publish',
|
|
|
|
value: 'publish',
|
|
|
|
description: 'Publish a message to a topic',
|
|
|
|
},
|
|
|
|
],
|
2019-10-16 02:18:39 -07:00
|
|
|
default: 'publish',
|
2019-10-15 10:24:45 -07:00
|
|
|
description: 'The operation to perform.',
|
|
|
|
},
|
2019-10-04 18:06:26 -07:00
|
|
|
{
|
|
|
|
displayName: 'Topic',
|
|
|
|
name: 'topic',
|
|
|
|
type: 'options',
|
|
|
|
typeOptions: {
|
|
|
|
loadOptionsMethod: 'getTopics',
|
|
|
|
},
|
2019-10-15 10:24:45 -07:00
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
operation: [
|
|
|
|
'publish',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2019-10-04 18:06:26 -07:00
|
|
|
options: [],
|
|
|
|
default: '',
|
|
|
|
required: true,
|
|
|
|
description: 'The topic you want to publish to',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Subject',
|
|
|
|
name: 'subject',
|
|
|
|
type: 'string',
|
2019-10-15 10:24:45 -07:00
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
operation: [
|
|
|
|
'publish',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2019-10-04 18:06:26 -07:00
|
|
|
default: '',
|
2019-10-15 10:21:48 -07:00
|
|
|
required: true,
|
2019-10-04 18:06:26 -07:00
|
|
|
description: 'Subject when the message is delivered to email endpoints',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Message',
|
|
|
|
name: 'message',
|
|
|
|
type: 'string',
|
2019-10-15 10:24:45 -07:00
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
operation: [
|
|
|
|
'publish',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2019-10-04 18:06:26 -07:00
|
|
|
required: true,
|
|
|
|
typeOptions: {
|
|
|
|
alwaysOpenEditWindow: true,
|
|
|
|
},
|
|
|
|
default: '',
|
|
|
|
description: 'The message you want to send',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
methods = {
|
|
|
|
loadOptions: {
|
|
|
|
// Get all the available topics to display them to user so that he can
|
|
|
|
// select them easily
|
|
|
|
async getTopics(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
2021-04-16 09:33:36 -07:00
|
|
|
const data = await awsApiRequestSOAP.call(this, 'sns', 'GET', '/?Action=ListTopics');
|
2019-10-04 18:06:26 -07:00
|
|
|
|
2019-10-16 02:18:39 -07:00
|
|
|
let topics = data.ListTopicsResponse.ListTopicsResult.Topics.member;
|
|
|
|
|
|
|
|
if (!Array.isArray(topics)) {
|
|
|
|
// If user has only a single topic no array get returned so we make
|
|
|
|
// one manually to be able to process everything identically
|
|
|
|
topics = [topics];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const topic of topics) {
|
|
|
|
const topicArn = topic.TopicArn as string;
|
|
|
|
const topicName = topicArn.split(':')[5];
|
2019-10-05 06:27:19 -07:00
|
|
|
|
2019-10-04 18:06:26 -07:00
|
|
|
returnData.push({
|
|
|
|
name: topicName,
|
|
|
|
value: topicArn,
|
|
|
|
});
|
|
|
|
}
|
2019-10-16 02:18:39 -07:00
|
|
|
|
2019-10-04 18:06:26 -07:00
|
|
|
return returnData;
|
2020-10-22 06:46:03 -07:00
|
|
|
},
|
2019-10-04 18:06:26 -07:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
|
|
const items = this.getInputData();
|
|
|
|
const returnData: IDataObject[] = [];
|
|
|
|
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
2019-10-15 10:21:48 -07:00
|
|
|
const params = [
|
|
|
|
'TopicArn=' + this.getNodeParameter('topic', i) as string,
|
|
|
|
'Subject=' + this.getNodeParameter('subject', i) as string,
|
|
|
|
'Message=' + this.getNodeParameter('message', i) as string,
|
|
|
|
];
|
2019-10-04 18:06:26 -07:00
|
|
|
|
2021-04-16 09:33:36 -07:00
|
|
|
|
|
|
|
const responseData = await awsApiRequestSOAP.call(this, 'sns', 'GET', '/?Action=Publish&' + params.join('&'));
|
2019-10-15 10:21:48 -07:00
|
|
|
returnData.push({MessageId: responseData.PublishResponse.PublishResult.MessageId} as IDataObject);
|
2019-10-04 18:06:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return [this.helpers.returnJsonArray(returnData)];
|
|
|
|
}
|
|
|
|
}
|