feat(reddit): add new posts matching search trigger
This commit is contained in:
@@ -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,
|
||||
});
|
||||
|
3
packages/backend/src/apps/reddit/triggers/index.ts
Normal file
3
packages/backend/src/apps/reddit/triggers/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import newPostsMatchingSearch from './new-posts-matching-search';
|
||||
|
||||
export default [newPostsMatchingSearch];
|
@@ -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);
|
||||
},
|
||||
});
|
@@ -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',
|
||||
|
12
packages/docs/pages/apps/reddit/triggers.md
Normal file
12
packages/docs/pages/apps/reddit/triggers.md
Normal 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 />
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user