feat(eventbrite): add new attendee check in trigger
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import listEvents from './list-events/index.js';
|
||||
import listOrganizations from './list-organizations/index.js';
|
||||
|
||||
export default [listOrganizations];
|
||||
export default [listEvents, listOrganizations];
|
||||
|
@@ -0,0 +1,44 @@
|
||||
export default {
|
||||
name: 'List events',
|
||||
key: 'listEvents',
|
||||
|
||||
async run($) {
|
||||
const events = {
|
||||
data: [],
|
||||
};
|
||||
const organizationId = $.step.parameters.organizationId;
|
||||
|
||||
if (!organizationId) {
|
||||
return events;
|
||||
}
|
||||
|
||||
const params = {
|
||||
continuation: undefined,
|
||||
order_by: 'created_desc',
|
||||
};
|
||||
|
||||
do {
|
||||
const { data } = await $.http.get(
|
||||
`/v3/organizations/${organizationId}/events/`,
|
||||
{
|
||||
params,
|
||||
}
|
||||
);
|
||||
|
||||
if (data.pagination.has_more_items) {
|
||||
params.continuation = data.pagination.continuation;
|
||||
}
|
||||
|
||||
if (data.events) {
|
||||
for (const event of data.events) {
|
||||
events.data.push({
|
||||
value: event.id,
|
||||
name: `${event.name.text} (${event.status})`,
|
||||
});
|
||||
}
|
||||
}
|
||||
} while (params.continuation);
|
||||
|
||||
return events;
|
||||
},
|
||||
};
|
@@ -1,3 +1,4 @@
|
||||
import newAttendeeCheckIn from './new-attendee-check-in/index.js';
|
||||
import newEvents from './new-events/index.js';
|
||||
|
||||
export default [newEvents];
|
||||
export default [newAttendeeCheckIn, newEvents];
|
||||
|
@@ -0,0 +1,120 @@
|
||||
import Crypto from 'crypto';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New attendee check in',
|
||||
key: 'newAttendeeCheckIn',
|
||||
type: 'webhook',
|
||||
description: "Triggers when an attendee's barcode is scanned in.",
|
||||
arguments: [
|
||||
{
|
||||
label: 'Organization',
|
||||
key: 'organizationId',
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listOrganizations',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Event',
|
||||
key: 'eventId',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listEvents',
|
||||
},
|
||||
{
|
||||
name: 'parameters.organizationId',
|
||||
value: '{parameters.organizationId}',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const dataItem = {
|
||||
raw: $.request.body,
|
||||
meta: {
|
||||
internalId: Crypto.randomUUID(),
|
||||
},
|
||||
};
|
||||
|
||||
$.pushTriggerItem(dataItem);
|
||||
},
|
||||
|
||||
async testRun($) {
|
||||
const eventId = $.step.parameters.eventId;
|
||||
const organizationId = $.step.parameters.organizationId;
|
||||
|
||||
const params = {
|
||||
event_id: eventId,
|
||||
};
|
||||
|
||||
const {
|
||||
data: { orders },
|
||||
} = await $.http.get(`/v3/events/${eventId}/orders/`, params);
|
||||
|
||||
if (orders.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const computedWebhookEvent = {
|
||||
config: {
|
||||
action: 'barcode.checked_in',
|
||||
user_id: organizationId,
|
||||
webhook_id: '11111111',
|
||||
endpoint_url: $.webhookUrl,
|
||||
},
|
||||
api_url: orders[0].resource_uri,
|
||||
};
|
||||
|
||||
const dataItem = {
|
||||
raw: computedWebhookEvent,
|
||||
meta: {
|
||||
internalId: computedWebhookEvent.user_id,
|
||||
},
|
||||
};
|
||||
|
||||
$.pushTriggerItem(dataItem);
|
||||
},
|
||||
|
||||
async registerHook($) {
|
||||
const organizationId = $.step.parameters.organizationId;
|
||||
const eventId = $.step.parameters.eventId;
|
||||
|
||||
const payload = {
|
||||
endpoint_url: $.webhookUrl,
|
||||
actions: 'attendee.checked_in',
|
||||
event_id: eventId,
|
||||
};
|
||||
|
||||
const { data } = await $.http.post(
|
||||
`/v3/organizations/${organizationId}/webhooks/`,
|
||||
payload
|
||||
);
|
||||
|
||||
await $.flow.setRemoteWebhookId(data.id);
|
||||
},
|
||||
|
||||
async unregisterHook($) {
|
||||
await $.http.delete(`/v3/webhooks/${$.flow.remoteWebhookId}/`);
|
||||
},
|
||||
});
|
@@ -1,6 +1,8 @@
|
||||
---
|
||||
favicon: /favicons/eventbrite.svg
|
||||
items:
|
||||
- name: New attendee check in
|
||||
desc: Triggers when an attendee's barcode is scanned in.
|
||||
- name: New events
|
||||
desc: Triggers when a new event is published and live within an organization.
|
||||
---
|
||||
|
Reference in New Issue
Block a user