Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
db084d12e4 | ||
![]() |
1c76b02c78 |
@@ -2,6 +2,7 @@ import defineApp from '../../helpers/define-app.js';
|
||||
import addAuthHeader from './common/add-auth-header.js';
|
||||
import auth from './auth/index.js';
|
||||
import setBaseUrl from './common/set-base-url.js';
|
||||
import triggers from './triggers/index.js';
|
||||
|
||||
export default defineApp({
|
||||
name: 'Firefly III',
|
||||
@@ -14,4 +15,5 @@ export default defineApp({
|
||||
supportsConnections: true,
|
||||
beforeRequest: [setBaseUrl, addAuthHeader],
|
||||
auth,
|
||||
triggers,
|
||||
});
|
||||
|
4
packages/backend/src/apps/firefly-iii/triggers/index.js
Normal file
4
packages/backend/src/apps/firefly-iii/triggers/index.js
Normal file
@@ -0,0 +1,4 @@
|
||||
import transactionCreated from './transaction-created/index.js';
|
||||
import transactionUpdated from './transaction-updated/index.js';
|
||||
|
||||
export default [transactionCreated, transactionUpdated];
|
@@ -0,0 +1,89 @@
|
||||
import Crypto from 'crypto';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'Transaction created',
|
||||
key: 'transactionCreated',
|
||||
type: 'webhook',
|
||||
description: 'Triggers when a new transaction is created.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Title of the webhook',
|
||||
key: 'title',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const dataItem = {
|
||||
raw: $.request.body,
|
||||
meta: {
|
||||
internalId: Crypto.randomUUID(),
|
||||
},
|
||||
};
|
||||
|
||||
$.pushTriggerItem(dataItem);
|
||||
},
|
||||
|
||||
async testRun($) {
|
||||
const { data: transactions } = await $.http.get(`/api/v1/transactions`);
|
||||
|
||||
if (transactions.data.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { data: transaction } = await $.http.get(
|
||||
`/api/v1/transactions/${transactions.data[0].id}`
|
||||
);
|
||||
|
||||
const lastTransaction = transaction.data;
|
||||
|
||||
if (!lastTransaction) {
|
||||
return;
|
||||
}
|
||||
|
||||
const computedWebhookEvent = {
|
||||
url: '',
|
||||
uuid: Crypto.randomUUID(),
|
||||
content: lastTransaction.attributes,
|
||||
trigger: 'STORE_TRANSACTION',
|
||||
user_id: lastTransaction.attributes.user,
|
||||
version: '',
|
||||
response: 'TRANSACTIONS',
|
||||
};
|
||||
|
||||
const dataItem = {
|
||||
raw: computedWebhookEvent,
|
||||
meta: {
|
||||
internalId: computedWebhookEvent.uuid,
|
||||
},
|
||||
};
|
||||
|
||||
$.pushTriggerItem(dataItem);
|
||||
},
|
||||
|
||||
async registerHook($) {
|
||||
const title = $.step.parameters.title;
|
||||
|
||||
const payload = {
|
||||
active: true,
|
||||
title: title || `Flow ID: ${$.flow.id}`,
|
||||
trigger: 'STORE_TRANSACTION',
|
||||
response: 'TRANSACTIONS',
|
||||
delivery: 'JSON',
|
||||
url: $.webhookUrl,
|
||||
};
|
||||
|
||||
const response = await $.http.post('/api/v1/webhooks', payload);
|
||||
const id = response.data.data.id;
|
||||
|
||||
await $.flow.setRemoteWebhookId(id);
|
||||
},
|
||||
|
||||
async unregisterHook($) {
|
||||
await $.http.delete(`/api/v1/webhooks/${$.flow.remoteWebhookId}`);
|
||||
},
|
||||
});
|
@@ -0,0 +1,89 @@
|
||||
import Crypto from 'crypto';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'Transaction updated',
|
||||
key: 'transactionUpdated',
|
||||
type: 'webhook',
|
||||
description: 'Triggers when a transaction is updated.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Title of the webhook',
|
||||
key: 'title',
|
||||
type: 'string',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const dataItem = {
|
||||
raw: $.request.body,
|
||||
meta: {
|
||||
internalId: Crypto.randomUUID(),
|
||||
},
|
||||
};
|
||||
|
||||
$.pushTriggerItem(dataItem);
|
||||
},
|
||||
|
||||
async testRun($) {
|
||||
const { data: transactions } = await $.http.get(`/api/v1/transactions`);
|
||||
|
||||
if (transactions.data.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { data: transaction } = await $.http.get(
|
||||
`/api/v1/transactions/${transactions.data[0].id}`
|
||||
);
|
||||
|
||||
const lastTransaction = transaction.data;
|
||||
|
||||
if (!lastTransaction) {
|
||||
return;
|
||||
}
|
||||
|
||||
const computedWebhookEvent = {
|
||||
url: '',
|
||||
uuid: Crypto.randomUUID(),
|
||||
content: lastTransaction.attributes,
|
||||
trigger: 'UPDATE_TRANSACTION',
|
||||
user_id: lastTransaction.attributes.user,
|
||||
version: '',
|
||||
response: 'TRANSACTIONS',
|
||||
};
|
||||
|
||||
const dataItem = {
|
||||
raw: computedWebhookEvent,
|
||||
meta: {
|
||||
internalId: computedWebhookEvent.uuid,
|
||||
},
|
||||
};
|
||||
|
||||
$.pushTriggerItem(dataItem);
|
||||
},
|
||||
|
||||
async registerHook($) {
|
||||
const title = $.step.parameters.title;
|
||||
|
||||
const payload = {
|
||||
active: true,
|
||||
title: title || `Flow ID: ${$.flow.id}`,
|
||||
trigger: 'UPDATE_TRANSACTION',
|
||||
response: 'TRANSACTIONS',
|
||||
delivery: 'JSON',
|
||||
url: $.webhookUrl,
|
||||
};
|
||||
|
||||
const response = await $.http.post('/api/v1/webhooks', payload);
|
||||
const id = response.data.data.id;
|
||||
|
||||
await $.flow.setRemoteWebhookId(id);
|
||||
},
|
||||
|
||||
async unregisterHook($) {
|
||||
await $.http.delete(`/api/v1/webhooks/${$.flow.remoteWebhookId}`);
|
||||
},
|
||||
});
|
@@ -126,7 +126,10 @@ export default defineConfig({
|
||||
text: 'Firefly III',
|
||||
collapsible: true,
|
||||
collapsed: true,
|
||||
items: [{ text: 'Connection', link: '/apps/firefly-iii/connection' }],
|
||||
items: [
|
||||
{ text: 'Triggers', link: '/apps/firefly-iii/triggers' },
|
||||
{ text: 'Connection', link: '/apps/firefly-iii/connection' },
|
||||
],
|
||||
},
|
||||
{
|
||||
text: 'Flickr',
|
||||
|
14
packages/docs/pages/apps/firefly-iii/triggers.md
Normal file
14
packages/docs/pages/apps/firefly-iii/triggers.md
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
favicon: /favicons/firefly-iii.svg
|
||||
items:
|
||||
- name: Transaction created
|
||||
desc: Triggers when a new transaction is created.
|
||||
- name: Transaction updated
|
||||
desc: Triggers when a transaction is updated.
|
||||
---
|
||||
|
||||
<script setup>
|
||||
import CustomListing from '../../components/CustomListing.vue'
|
||||
</script>
|
||||
|
||||
<CustomListing />
|
@@ -12,6 +12,7 @@ The following integrations are currently supported by Automatisch.
|
||||
- [Disqus](/apps/disqus/triggers)
|
||||
- [Dropbox](/apps/dropbox/actions)
|
||||
- [Filter](/apps/filter/actions)
|
||||
- [Firefly III](/apps/firefly-iii/triggers)
|
||||
- [Flickr](/apps/flickr/triggers)
|
||||
- [Formatter](/apps/formatter/actions)
|
||||
- [Ghost](/apps/ghost/triggers)
|
||||
|
Reference in New Issue
Block a user