Merge pull request #1427 from automatisch/AUT-397

feat(reddit): add new posts matching search trigger
This commit is contained in:
Ali BARIN
2023-11-10 16:03:35 +01:00
committed by GitHub
6 changed files with 70 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
import defineApp from '../../helpers/define-app';
import addAuthHeader from './common/add-auth-header';
import auth from './auth';
import triggers from './triggers';
export default defineApp({
name: 'Reddit',
@@ -13,4 +14,5 @@ export default defineApp({
supportsConnections: true,
beforeRequest: [addAuthHeader],
auth,
triggers,
});

View File

@@ -0,0 +1,3 @@
import newPostsMatchingSearch from './new-posts-matching-search';
export default [newPostsMatchingSearch];

View File

@@ -0,0 +1,48 @@
import defineTrigger from '../../../../helpers/define-trigger';
export default defineTrigger({
name: 'New posts matching search',
key: 'newPostsMatchingSearch',
pollInterval: 15,
description: 'Triggers when a search string matches a new post.',
arguments: [
{
label: 'Search Query',
key: 'searchQuery',
type: 'string' as const,
required: true,
description:
'The term or expression to look for, restricted to 512 characters. If your query contains periods (e.g., automatisch.io), ensure it is enclosed in quotes ("automatisch.io").',
variables: true,
},
],
async run($) {
const { searchQuery } = $.step.parameters;
const params = {
q: searchQuery,
type: 'link',
sort: 'new',
limit: 100,
after: undefined as unknown as string,
};
do {
const { data } = await $.http.get('/search', {
params,
});
params.after = data.data.after;
if (data.data.children?.length) {
for (const item of data.data.children) {
$.pushTriggerItem({
raw: item,
meta: {
internalId: item.data.id,
},
});
}
}
} while (params.after);
},
});

View File

@@ -293,7 +293,10 @@ export default defineConfig({
text: 'Reddit',
collapsible: true,
collapsed: true,
items: [{ text: 'Connection', link: '/apps/reddit/connection' }],
items: [
{ text: 'Triggers', link: '/apps/reddit/triggers' },
{ text: 'Connection', link: '/apps/reddit/connection' },
],
},
{
text: 'Remove.bg',

View File

@@ -0,0 +1,12 @@
---
favicon: /favicons/reddit.svg
items:
- name: New posts matching search
desc: Triggers when a search string matches a new post.
---
<script setup>
import CustomListing from '../../components/CustomListing.vue'
</script>
<CustomListing />

View File

@@ -30,6 +30,7 @@ The following integrations are currently supported by Automatisch.
- [Placetel](/apps/placetel/triggers)
- [PostgreSQL](/apps/postgresql/actions)
- [Pushover](/apps/pushover/actions)
- [Reddit](/apps/reddit/triggers)
- [Remove.bg](/apps/removebg/connection)
- [RSS](/apps/rss/triggers)
- [Salesforce](/apps/salesforce/triggers)