feat(disqus): add new comments trigger

This commit is contained in:
Rıdvan Akca
2024-01-16 13:40:00 +03:00
parent 798529007e
commit 5657f0d793
8 changed files with 155 additions and 1 deletions

View File

@@ -0,0 +1,3 @@
import listForums from './list-forums/index.js';
export default [listForums];

View File

@@ -0,0 +1,36 @@
export default {
name: 'List forums',
key: 'listForums',
async run($) {
const forums = {
data: [],
};
const params = {
limit: 100,
order: 'desc',
cursor: undefined,
};
let more;
do {
const { data } = await $.http.get('/3.0/users/listForums.json', {
params,
});
params.cursor = data.cursor.next;
more = data.cursor.hasNext;
if (data.response?.length) {
for (const forum of data.response) {
forums.data.push({
value: forum.id,
name: forum.id,
});
}
}
} while (more);
return forums;
},
};

View File

@@ -1,6 +1,8 @@
import defineApp from '../../helpers/define-app.js';
import addAuthHeader from './common/add-auth-header.js';
import auth from './auth/index.js';
import dynamicData from './dynamic-data/index.js';
import triggers from './triggers/index.js';
export default defineApp({
name: 'Disqus',
@@ -13,4 +15,6 @@ export default defineApp({
supportsConnections: true,
beforeRequest: [addAuthHeader],
auth,
dynamicData,
triggers,
});

View File

@@ -0,0 +1,3 @@
import newComments from './new-comments/index.js';
export default [newComments];

View File

@@ -0,0 +1,92 @@
import defineTrigger from '../../../../helpers/define-trigger.js';
import { URLSearchParams } from 'url';
export default defineTrigger({
name: 'New comments',
key: 'newComments',
pollInterval: 15,
description: 'Triggers when a new comment is posted in a forum using Disqus.',
arguments: [
{
label: 'Post Types',
key: 'postTypes',
type: 'dynamic',
required: false,
description:
'Which posts should be considered for inclusion in the trigger?',
fields: [
{
label: 'Type',
key: 'type',
type: 'dropdown',
required: false,
description: '',
variables: true,
options: [
{ label: 'Unapproved Posts', value: 'unapproved' },
{ label: 'Approved Posts', value: 'approved' },
{ label: 'Spam Posts', value: 'spam' },
{ label: 'Deleted Posts', value: 'deleted' },
{ label: 'Flagged Posts', value: 'flagged' },
{ label: 'Highlighted Posts', value: 'highlighted' },
],
},
],
},
{
label: 'Forum',
key: 'forumId',
type: 'dropdown',
required: true,
description: 'Select the forum where you want comments to be triggered.',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listForums',
},
],
},
},
],
async run($) {
const forumId = $.step.parameters.forumId;
const postTypes = $.step.parameters.postTypes;
const formattedCommentTypes = postTypes
.filter((type) => type.type !== '')
.map((type) => type.type);
const params = new URLSearchParams({
limit: '100',
forum: forumId,
});
if (formattedCommentTypes.length) {
formattedCommentTypes.forEach((type) => params.append('include', type));
}
let more;
do {
const { data } = await $.http.get(
`/3.0/posts/list.json?${params.toString()}`
);
params.set('cursor', data.cursor.next);
more = data.cursor.hasNext;
if (data.response?.length) {
for (const comment of data.response) {
$.pushTriggerItem({
raw: comment,
meta: {
internalId: comment.id,
},
});
}
}
} while (more);
},
});

View File

@@ -72,7 +72,10 @@ export default defineConfig({
text: 'Disqus',
collapsible: true,
collapsed: true,
items: [{ text: 'Connection', link: '/apps/disqus/connection' }],
items: [
{ text: 'Triggers', link: '/apps/disqus/triggers' },
{ text: 'Connection', link: '/apps/disqus/connection' },
],
},
{
text: 'Dropbox',

View File

@@ -0,0 +1,12 @@
---
favicon: /favicons/disqus.svg
items:
- name: New comments
desc: Triggers when a new comment is posted in a forum using Disqus.
---
<script setup>
import CustomListing from '../../components/CustomListing.vue'
</script>
<CustomListing />

View File

@@ -6,6 +6,7 @@ The following integrations are currently supported by Automatisch.
- [DeepL](/apps/deepl/actions)
- [Delay](/apps/delay/actions)
- [Discord](/apps/discord/actions)
- [Disqus](/apps/disqus/triggers)
- [Dropbox](/apps/dropbox/actions)
- [Filter](/apps/filter/actions)
- [Flickr](/apps/flickr/triggers)