feat(ghost): add new post published trigger (#1403)
This commit is contained in:
@@ -2,6 +2,7 @@ import defineApp from '../../helpers/define-app';
|
|||||||
import addAuthHeader from './common/add-auth-header';
|
import addAuthHeader from './common/add-auth-header';
|
||||||
import setBaseUrl from './common/set-base-url';
|
import setBaseUrl from './common/set-base-url';
|
||||||
import auth from './auth';
|
import auth from './auth';
|
||||||
|
import triggers from './triggers';
|
||||||
|
|
||||||
export default defineApp({
|
export default defineApp({
|
||||||
name: 'Ghost',
|
name: 'Ghost',
|
||||||
@@ -14,4 +15,5 @@ export default defineApp({
|
|||||||
supportsConnections: true,
|
supportsConnections: true,
|
||||||
beforeRequest: [setBaseUrl, addAuthHeader],
|
beforeRequest: [setBaseUrl, addAuthHeader],
|
||||||
auth,
|
auth,
|
||||||
|
triggers,
|
||||||
});
|
});
|
||||||
|
3
packages/backend/src/apps/ghost/triggers/index.ts
Normal file
3
packages/backend/src/apps/ghost/triggers/index.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import newPostPublished from './new-post-published';
|
||||||
|
|
||||||
|
export default [newPostPublished];
|
@@ -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}/`);
|
||||||
|
},
|
||||||
|
});
|
@@ -99,7 +99,10 @@ export default defineConfig({
|
|||||||
text: 'Ghost',
|
text: 'Ghost',
|
||||||
collapsible: true,
|
collapsible: true,
|
||||||
collapsed: 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',
|
text: 'GitHub',
|
||||||
|
12
packages/docs/pages/apps/ghost/triggers.md
Normal file
12
packages/docs/pages/apps/ghost/triggers.md
Normal 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 />
|
@@ -9,6 +9,7 @@ The following integrations are currently supported by Automatisch.
|
|||||||
- [Filter](/apps/filter/actions)
|
- [Filter](/apps/filter/actions)
|
||||||
- [Flickr](/apps/flickr/triggers)
|
- [Flickr](/apps/flickr/triggers)
|
||||||
- [Formatter](/apps/formatter/actions)
|
- [Formatter](/apps/formatter/actions)
|
||||||
|
- [Ghost](/apps/ghost/triggers)
|
||||||
- [GitHub](/apps/github/triggers)
|
- [GitHub](/apps/github/triggers)
|
||||||
- [GitLab](/apps/gitlab/triggers)
|
- [GitLab](/apps/gitlab/triggers)
|
||||||
- [Google Calendar](/apps/google-calendar/triggers)
|
- [Google Calendar](/apps/google-calendar/triggers)
|
||||||
|
Reference in New Issue
Block a user