Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
db084d12e4 |
@@ -1,3 +1,4 @@
|
|||||||
import transactionCreated from './transaction-created/index.js';
|
import transactionCreated from './transaction-created/index.js';
|
||||||
|
import transactionUpdated from './transaction-updated/index.js';
|
||||||
|
|
||||||
export default [transactionCreated];
|
export default [transactionCreated, transactionUpdated];
|
||||||
|
@@ -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}`);
|
||||||
|
},
|
||||||
|
});
|
@@ -3,6 +3,8 @@ favicon: /favicons/firefly-iii.svg
|
|||||||
items:
|
items:
|
||||||
- name: Transaction created
|
- name: Transaction created
|
||||||
desc: Triggers when a new transaction is created.
|
desc: Triggers when a new transaction is created.
|
||||||
|
- name: Transaction updated
|
||||||
|
desc: Triggers when a transaction is updated.
|
||||||
---
|
---
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
Reference in New Issue
Block a user