feat(jotform): add new submissions trigger
This commit is contained in:
3
packages/backend/src/apps/jotform/dynamic-data/index.js
Normal file
3
packages/backend/src/apps/jotform/dynamic-data/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import listForms from './list-forms/index.js';
|
||||
|
||||
export default [listForms];
|
@@ -0,0 +1,41 @@
|
||||
export default {
|
||||
name: 'List forms',
|
||||
key: 'listForms',
|
||||
|
||||
async run($) {
|
||||
const forms = {
|
||||
data: [],
|
||||
};
|
||||
let hasMore = false;
|
||||
|
||||
const params = {
|
||||
limit: 1000,
|
||||
offset: 0,
|
||||
orderby: 'created_at',
|
||||
};
|
||||
|
||||
do {
|
||||
const { data } = await $.http.get('/user/forms', { params });
|
||||
params.offset = params.offset + params.limit;
|
||||
|
||||
if (data.content?.length) {
|
||||
for (const form of data.content) {
|
||||
if (form.status === 'ENABLED') {
|
||||
forms.data.push({
|
||||
value: form.id,
|
||||
name: form.title,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (data.resultSet.count > data.resultSet.limit) {
|
||||
hasMore = true;
|
||||
} else {
|
||||
hasMore = false;
|
||||
}
|
||||
} while (hasMore);
|
||||
|
||||
return forms;
|
||||
},
|
||||
};
|
@@ -2,6 +2,8 @@ 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';
|
||||
import dynamicData from './dynamic-data/index.js';
|
||||
|
||||
export default defineApp({
|
||||
name: 'Jotform',
|
||||
@@ -14,4 +16,6 @@ export default defineApp({
|
||||
primaryColor: 'FF6100',
|
||||
beforeRequest: [setBaseUrl, addAuthHeader],
|
||||
auth,
|
||||
triggers,
|
||||
dynamicData,
|
||||
});
|
||||
|
3
packages/backend/src/apps/jotform/triggers/index.js
Normal file
3
packages/backend/src/apps/jotform/triggers/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import newSubmissions from './new-submissions/index.js';
|
||||
|
||||
export default [newSubmissions];
|
@@ -0,0 +1,109 @@
|
||||
import Crypto from 'crypto';
|
||||
import { URLSearchParams } from 'url';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New submissions',
|
||||
key: 'newSubmissions',
|
||||
type: 'webhook',
|
||||
description:
|
||||
'Triggers when a new submission has been added to a specific form.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Form',
|
||||
key: 'formId',
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listForms',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const dataItem = {
|
||||
raw: $.request.body,
|
||||
meta: {
|
||||
internalId: Crypto.randomUUID(),
|
||||
},
|
||||
};
|
||||
|
||||
$.pushTriggerItem(dataItem);
|
||||
},
|
||||
|
||||
async testRun($) {
|
||||
const sampleEventData = {
|
||||
ip: '127.0.0.1',
|
||||
type: 'WEB',
|
||||
appID: '',
|
||||
event: '',
|
||||
action: '',
|
||||
formID: Crypto.randomUUID(),
|
||||
parent: '',
|
||||
pretty: 'Name:test, E-mail:user@automatisch.io',
|
||||
teamID: '',
|
||||
unread: '',
|
||||
product: '',
|
||||
subject: '',
|
||||
isSilent: '',
|
||||
username: 'username',
|
||||
deviceIDs: 'Array',
|
||||
formTitle: 'Opt-In Form-Get Free Email Updates!',
|
||||
fromTable: '',
|
||||
customBody: '',
|
||||
documentID: '',
|
||||
rawRequest: '',
|
||||
webhookURL: '',
|
||||
customTitle: '',
|
||||
trackAction: 'Array',
|
||||
customParams: '',
|
||||
submissionID: Crypto.randomUUID(),
|
||||
customBodyParams: 'Array',
|
||||
customTitleParams: 'Array',
|
||||
};
|
||||
|
||||
const dataItem = {
|
||||
raw: sampleEventData,
|
||||
meta: {
|
||||
internalId: sampleEventData.submissionID,
|
||||
},
|
||||
};
|
||||
|
||||
$.pushTriggerItem(dataItem);
|
||||
},
|
||||
|
||||
async registerHook($) {
|
||||
const formId = $.step.parameters.formId;
|
||||
|
||||
const params = new URLSearchParams({
|
||||
webhookURL: $.webhookUrl,
|
||||
});
|
||||
|
||||
const { data } = await $.http.post(
|
||||
`/form/${formId}/webhooks`,
|
||||
params.toString()
|
||||
);
|
||||
|
||||
await $.flow.setRemoteWebhookId(data.content[0]);
|
||||
},
|
||||
|
||||
async unregisterHook($) {
|
||||
const formId = $.step.parameters.formId;
|
||||
|
||||
const { data } = await $.http.get(`/form/${formId}/webhooks`);
|
||||
|
||||
const webhookURLs = Object.values(data.content);
|
||||
const webhookId = webhookURLs.findIndex((url) => url === $.webhookUrl);
|
||||
|
||||
await $.http.delete(`/form/${formId}/webhooks/${webhookId}`);
|
||||
},
|
||||
});
|
@@ -256,7 +256,10 @@ export default defineConfig({
|
||||
text: 'Jotform',
|
||||
collapsible: true,
|
||||
collapsed: true,
|
||||
items: [{ text: 'Connection', link: '/apps/jotform/connection' }],
|
||||
items: [
|
||||
{ text: 'Triggers', link: '/apps/jotform/triggers' },
|
||||
{ text: 'Connection', link: '/apps/jotform/connection' },
|
||||
],
|
||||
},
|
||||
{
|
||||
text: 'Mailchimp',
|
||||
|
12
packages/docs/pages/apps/jotform/triggers.md
Normal file
12
packages/docs/pages/apps/jotform/triggers.md
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
favicon: /favicons/jotform.svg
|
||||
items:
|
||||
- name: New submissions
|
||||
desc: Triggers when a new submission has been added to a specific form.
|
||||
---
|
||||
|
||||
<script setup>
|
||||
import CustomListing from '../../components/CustomListing.vue'
|
||||
</script>
|
||||
|
||||
<CustomListing />
|
@@ -25,6 +25,7 @@ The following integrations are currently supported by Automatisch.
|
||||
- [HTTP Request](/apps/http-request/actions)
|
||||
- [HubSpot](/apps/hubspot/actions)
|
||||
- [Invoice Ninja](/apps/invoice-ninja/triggers)
|
||||
- [Jotform](/apps/jotform/triggers)
|
||||
- [Mailchimp](/apps/mailchimp/triggers)
|
||||
- [MailerLite](/apps/mailerlite/triggers)
|
||||
- [Mattermost](/apps/mattermost/actions)
|
||||
|
Reference in New Issue
Block a user