feat(mailchimp): add new subscribers trigger
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
import listAudiences from './list-audiences/index.js';
|
||||||
|
|
||||||
|
export default [listAudiences];
|
@@ -0,0 +1,40 @@
|
|||||||
|
export default {
|
||||||
|
name: 'List audiences',
|
||||||
|
key: 'listAudiences',
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const audiences = {
|
||||||
|
data: [],
|
||||||
|
};
|
||||||
|
let hasMore = false;
|
||||||
|
|
||||||
|
const params = {
|
||||||
|
sort_field: 'date_created',
|
||||||
|
sort_dir: 'DESC',
|
||||||
|
count: 1000,
|
||||||
|
offset: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
do {
|
||||||
|
const { data } = await $.http.get('/3.0/lists', { params });
|
||||||
|
params.offset = params.offset + params.count;
|
||||||
|
|
||||||
|
if (data?.lists) {
|
||||||
|
for (const audience of data.lists) {
|
||||||
|
audiences.data.push({
|
||||||
|
value: audience.id,
|
||||||
|
name: audience.name,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.total_items > params.offset) {
|
||||||
|
hasMore = true;
|
||||||
|
} else {
|
||||||
|
hasMore = false;
|
||||||
|
}
|
||||||
|
} while (hasMore);
|
||||||
|
|
||||||
|
return audiences;
|
||||||
|
},
|
||||||
|
};
|
@@ -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 setBaseUrl from './common/set-base-url.js';
|
import setBaseUrl from './common/set-base-url.js';
|
||||||
import auth from './auth/index.js';
|
import auth from './auth/index.js';
|
||||||
|
import triggers from './triggers/index.js';
|
||||||
|
import dynamicData from './dynamic-data/index.js';
|
||||||
|
|
||||||
export default defineApp({
|
export default defineApp({
|
||||||
name: 'Mailchimp',
|
name: 'Mailchimp',
|
||||||
@@ -14,4 +16,6 @@ export default defineApp({
|
|||||||
supportsConnections: true,
|
supportsConnections: true,
|
||||||
beforeRequest: [setBaseUrl, addAuthHeader],
|
beforeRequest: [setBaseUrl, addAuthHeader],
|
||||||
auth,
|
auth,
|
||||||
|
triggers,
|
||||||
|
dynamicData,
|
||||||
});
|
});
|
||||||
|
3
packages/backend/src/apps/mailchimp/triggers/index.js
Normal file
3
packages/backend/src/apps/mailchimp/triggers/index.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import newSubscribers from './new-subscribers/index.js';
|
||||||
|
|
||||||
|
export default [newSubscribers];
|
@@ -0,0 +1,105 @@
|
|||||||
|
import Crypto from 'crypto';
|
||||||
|
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||||
|
|
||||||
|
export default defineTrigger({
|
||||||
|
name: 'New subscribers',
|
||||||
|
key: 'newSubscribers',
|
||||||
|
type: 'webhook',
|
||||||
|
description: 'Triggers when a new subscriber is appended to an audience.',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
label: 'Audience',
|
||||||
|
key: 'audienceId',
|
||||||
|
type: 'dropdown',
|
||||||
|
required: true,
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
source: {
|
||||||
|
type: 'query',
|
||||||
|
name: 'getDynamicData',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'key',
|
||||||
|
value: 'listAudiences',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const dataItem = {
|
||||||
|
raw: $.request.body,
|
||||||
|
meta: {
|
||||||
|
internalId: Crypto.randomUUID(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
$.pushTriggerItem(dataItem);
|
||||||
|
},
|
||||||
|
|
||||||
|
async testRun($) {
|
||||||
|
const audienceId = $.step.parameters.audienceId;
|
||||||
|
|
||||||
|
const computedWebhookEvent = {
|
||||||
|
data: {
|
||||||
|
id: Crypto.randomUUID(),
|
||||||
|
email: 'user@automatisch.io',
|
||||||
|
ip_opt: '127.0.0.1',
|
||||||
|
merges: {
|
||||||
|
EMAIL: 'user@automatisch.io',
|
||||||
|
FNAME: 'FNAME',
|
||||||
|
LNAME: 'LNAME',
|
||||||
|
PHONE: '',
|
||||||
|
ADDRESS: '',
|
||||||
|
BIRTHDAY: '',
|
||||||
|
},
|
||||||
|
web_id: Crypto.randomUUID(),
|
||||||
|
list_id: audienceId,
|
||||||
|
email_type: 'html',
|
||||||
|
},
|
||||||
|
type: 'subscribe',
|
||||||
|
fired_at: new Date().toLocaleString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
const dataItem = {
|
||||||
|
raw: computedWebhookEvent,
|
||||||
|
meta: {
|
||||||
|
internalId: computedWebhookEvent.id,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
$.pushTriggerItem(dataItem);
|
||||||
|
},
|
||||||
|
|
||||||
|
async registerHook($) {
|
||||||
|
const audienceId = $.step.parameters.audienceId;
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
url: $.webhookUrl,
|
||||||
|
events: {
|
||||||
|
subscribe: true,
|
||||||
|
},
|
||||||
|
sources: {
|
||||||
|
user: true,
|
||||||
|
admin: true,
|
||||||
|
api: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await $.http.post(
|
||||||
|
`/3.0/lists/${audienceId}/webhooks`,
|
||||||
|
payload
|
||||||
|
);
|
||||||
|
|
||||||
|
await $.flow.setRemoteWebhookId(response.data.id);
|
||||||
|
},
|
||||||
|
|
||||||
|
async unregisterHook($) {
|
||||||
|
const audienceId = $.step.parameters.audienceId;
|
||||||
|
|
||||||
|
await $.http.delete(
|
||||||
|
`/3.0/lists/${audienceId}/webhooks/${$.flow.remoteWebhookId}`
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
12
packages/docs/pages/apps/mailchimp/triggers.md
Normal file
12
packages/docs/pages/apps/mailchimp/triggers.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
favicon: /favicons/mailchimp.svg
|
||||||
|
items:
|
||||||
|
- name: New subscribers
|
||||||
|
desc: Triggers when a new subscriber is appended to an audience.
|
||||||
|
---
|
||||||
|
|
||||||
|
<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)
|
- [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)
|
||||||
|
- [Mailchimp](/apps/mailchimp/triggers)
|
||||||
- [MailerLite](/apps/mailerlite/triggers)
|
- [MailerLite](/apps/mailerlite/triggers)
|
||||||
- [Mattermost](/apps/mattermost/actions)
|
- [Mattermost](/apps/mattermost/actions)
|
||||||
- [Miro](/apps/miro/actions)
|
- [Miro](/apps/miro/actions)
|
||||||
|
Reference in New Issue
Block a user