feat(jotform): add new submissions trigger

This commit is contained in:
Rıdvan Akca
2024-02-05 14:50:48 +03:00
committed by Ali BARIN
parent 42f8e635ed
commit 530a920517
8 changed files with 177 additions and 1 deletions

View File

@@ -0,0 +1,3 @@
import listForms from './list-forms/index.js';
export default [listForms];

View File

@@ -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;
},
};

View File

@@ -2,6 +2,8 @@ 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 setBaseUrl from './common/set-base-url.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({ export default defineApp({
name: 'Jotform', name: 'Jotform',
@@ -14,4 +16,6 @@ export default defineApp({
primaryColor: 'FF6100', primaryColor: 'FF6100',
beforeRequest: [setBaseUrl, addAuthHeader], beforeRequest: [setBaseUrl, addAuthHeader],
auth, auth,
triggers,
dynamicData,
}); });

View File

@@ -0,0 +1,3 @@
import newSubmissions from './new-submissions/index.js';
export default [newSubmissions];

View File

@@ -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}`);
},
});

View File

@@ -256,7 +256,10 @@ export default defineConfig({
text: 'Jotform', text: 'Jotform',
collapsible: true, collapsible: true,
collapsed: 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', text: 'Mailchimp',

View 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 />

View File

@@ -25,6 +25,7 @@ The following integrations are currently supported by Automatisch.
- [HTTP Request](/apps/http-request/actions) - [HTTP Request](/apps/http-request/actions)
- [HubSpot](/apps/hubspot/actions) - [HubSpot](/apps/hubspot/actions)
- [Invoice Ninja](/apps/invoice-ninja/triggers) - [Invoice Ninja](/apps/invoice-ninja/triggers)
- [Jotform](/apps/jotform/triggers)
- [Mailchimp](/apps/mailchimp/triggers) - [Mailchimp](/apps/mailchimp/triggers)
- [MailerLite](/apps/mailerlite/triggers) - [MailerLite](/apps/mailerlite/triggers)
- [Mattermost](/apps/mattermost/actions) - [Mattermost](/apps/mattermost/actions)