feat(ynab): add low account balance trigger

This commit is contained in:
Rıdvan Akca
2024-01-18 15:42:28 +03:00
parent ce6ad9e0d3
commit 53f7f38e23
6 changed files with 58 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
import defineApp from '../../helpers/define-app.js'; import defineApp from '../../helpers/define-app.js';
import addAuthHeader from './common/add-auth-header.js'; import addAuthHeader from './common/add-auth-header.js';
import auth from './auth/index.js'; import auth from './auth/index.js';
import triggers from './triggers/index.js';
export default defineApp({ export default defineApp({
name: 'You Need A Budget', name: 'You Need A Budget',
@@ -13,4 +14,5 @@ export default defineApp({
supportsConnections: true, supportsConnections: true,
beforeRequest: [addAuthHeader], beforeRequest: [addAuthHeader],
auth, auth,
triggers,
}); });

View File

@@ -0,0 +1,3 @@
import lowAccountBalance from './low-account-balance/index.js';
export default [lowAccountBalance];

View File

@@ -0,0 +1,39 @@
import defineTrigger from '../../../../helpers/define-trigger.js';
export default defineTrigger({
name: 'Low account balance',
key: 'lowAccountBalance',
pollInterval: 15,
description:
'Triggers when the balance of a Checking or Savings account falls below a specified amount within a given month.',
arguments: [
{
label: 'Balance Below Amount',
key: 'balanceBelowAmount',
type: 'string',
required: true,
description: 'Account balance falls below this amount (e.g. "250.00")',
variables: true,
},
],
async run($) {
const balanceBelowAmount = $.step.parameters.balanceBelowAmount;
const formattedBalance = balanceBelowAmount * 1000;
const response = await $.http.get('/budgets/last-used/accounts');
if (response.data?.data?.accounts?.length) {
for (const account of response.data.data.accounts) {
if (account.balance < formattedBalance) {
$.pushTriggerItem({
raw: account,
meta: {
internalId: account.id,
},
});
}
}
}
},
});

View File

@@ -480,6 +480,7 @@ export default defineConfig({
collapsible: true, collapsible: true,
collapsed: true, collapsed: true,
items: [ items: [
{ text: 'Triggers', link: '/apps/you-need-a-budget/triggers' },
{ text: 'Connection', link: '/apps/you-need-a-budget/connection' }, { text: 'Connection', link: '/apps/you-need-a-budget/connection' },
], ],
}, },

View File

@@ -0,0 +1,12 @@
---
favicon: /favicons/you-need-a-budget.svg
items:
- name: Low account balance
desc: Triggers when the balance of a Checking or Savings account falls below a specified amount within a given month.
---
<script setup>
import CustomListing from '../../components/CustomListing.vue'
</script>
<CustomListing />

View File

@@ -50,5 +50,6 @@ The following integrations are currently supported by Automatisch.
- [Webhooks](/apps/webhooks/triggers) - [Webhooks](/apps/webhooks/triggers)
- [WordPress](/apps/wordpress/triggers) - [WordPress](/apps/wordpress/triggers)
- [Xero](/apps/xero/triggers) - [Xero](/apps/xero/triggers)
- [You Need A Budget](/apps/you-need-a-budget/triggers)
- [Youtube](/apps/youtube/triggers) - [Youtube](/apps/youtube/triggers)
- [Zendesk](/apps/zendesk/actions) - [Zendesk](/apps/zendesk/actions)