feat(rss): add new items in feed trigger

This commit is contained in:
Ali BARIN
2022-10-26 22:18:07 +02:00
parent 7d7c96274d
commit 419d84da97
10 changed files with 107 additions and 12 deletions

View File

@@ -0,0 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg"
aria-label="RSS" role="img"
viewBox="0 0 512 512"><rect
width="512" height="512"
rx="15%"
fill="#f80"/><circle cx="145" cy="367" r="35" fill="#fff"/><path fill="none" stroke="#fff" stroke-width="60" d="M109 241c89 0 162 73 162 162m114 0c0-152-124-276-276-276"/></svg>

After

Width:  |  Height:  |  Size: 307 B

View File

View File

@@ -0,0 +1,13 @@
import defineApp from '../../helpers/define-app';
export default defineApp({
name: 'RSS',
key: 'rss',
iconUrl: '{BASE_URL}/apps/rss/assets/favicon.svg',
authDocUrl: 'https://automatisch.io/docs/connections/rss',
supportsConnections: false,
baseUrl: '',
apiBaseUrl: '',
primaryColor: 'ff8800',
beforeRequest: [],
});

View File

@@ -0,0 +1,33 @@
import defineTrigger from '../../../../helpers/define-trigger';
import newItemsInFeed from './new-items-in-feed';
export default defineTrigger({
name: 'New items in feed',
key: 'newItemsInFeed',
description: 'Triggers on new RSS feed items.',
pollInterval: 15,
substeps: [
{
key: 'chooseTrigger',
name: 'Set up trigger',
arguments: [
{
label: 'Feed URL',
key: 'feedUrl',
type: 'string',
required: true,
description: 'Paste your publicly accessible RSS URL here.',
variables: false,
},
],
},
{
key: 'testStep',
name: 'Test trigger',
},
],
async run($) {
await newItemsInFeed($);
},
});

View File

@@ -0,0 +1,24 @@
import { IGlobalVariable } from '@automatisch/types';
import { XMLParser } from 'fast-xml-parser';[]
const newItemsInFeed = async ($: IGlobalVariable) => {
const { data } = await $.http.get($.step.parameters.feedUrl as string);
const parser = new XMLParser();
const parsedData = parser.parse(data);
for (const item of parsedData.rss.channel.item) {
if ($.flow.isAlreadyProcessed(item.guid))
return;
const dataItem = {
raw: item,
meta: {
internalId: item.guid
}
}
$.pushTriggerItem(dataItem);
}
};
export default newItemsInFeed;