feat(ghost): add new post published trigger (#1403)

This commit is contained in:
Rıdvan Akca
2023-11-07 14:55:35 +03:00
committed by GitHub
parent f0e8f070a8
commit 2afcfbb4bc
6 changed files with 77 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ import defineApp from '../../helpers/define-app';
import addAuthHeader from './common/add-auth-header';
import setBaseUrl from './common/set-base-url';
import auth from './auth';
import triggers from './triggers';
export default defineApp({
name: 'Ghost',
@@ -14,4 +15,5 @@ export default defineApp({
supportsConnections: true,
beforeRequest: [setBaseUrl, addAuthHeader],
auth,
triggers,
});

View File

@@ -0,0 +1,3 @@
import newPostPublished from './new-post-published';
export default [newPostPublished];

View File

@@ -0,0 +1,55 @@
import Crypto from 'crypto';
import isEmpty from 'lodash/isEmpty';
import defineTrigger from '../../../../helpers/define-trigger';
export default defineTrigger({
name: 'New post published',
key: 'newPostPublished',
type: 'webhook',
description: 'Triggers when a new post is published.',
async run($) {
const dataItem = {
raw: $.request.body,
meta: {
internalId: Crypto.randomUUID(),
},
};
$.pushTriggerItem(dataItem);
},
async testRun($) {
const lastExecutionStep = await $.getLastExecutionStep();
if (!isEmpty(lastExecutionStep?.dataOut)) {
$.pushTriggerItem({
raw: lastExecutionStep.dataOut,
meta: {
internalId: '',
},
});
}
},
async registerHook($) {
const payload = {
webhooks: [
{
event: 'post.published',
target_url: $.webhookUrl,
name: `Flow ID: ${$.flow.id}`,
},
],
};
const response = await $.http.post('/admin/webhooks/', payload);
const id = response.data.webhooks[0].id;
await $.flow.setRemoteWebhookId(id);
},
async unregisterHook($) {
await $.http.delete(`/admin/webhooks/${$.flow.remoteWebhookId}/`);
},
});

View File

@@ -99,7 +99,10 @@ export default defineConfig({
text: 'Ghost',
collapsible: true,
collapsed: true,
items: [{ text: 'Connection', link: '/apps/ghost/connection' }],
items: [
{ text: 'Triggers', link: '/apps/ghost/triggers' },
{ text: 'Connection', link: '/apps/ghost/connection' },
],
},
{
text: 'GitHub',

View File

@@ -0,0 +1,12 @@
---
favicon: /favicons/ghost.svg
items:
- name: New post published
desc: Triggers when a new post is published.
---
<script setup>
import CustomListing from '../../components/CustomListing.vue'
</script>
<CustomListing />

View File

@@ -9,6 +9,7 @@ The following integrations are currently supported by Automatisch.
- [Filter](/apps/filter/actions)
- [Flickr](/apps/flickr/triggers)
- [Formatter](/apps/formatter/actions)
- [Ghost](/apps/ghost/triggers)
- [GitHub](/apps/github/triggers)
- [GitLab](/apps/gitlab/triggers)
- [Google Calendar](/apps/google-calendar/triggers)