feat(flowers-software): add new activity trigger
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import isEmpty from 'lodash/isEmpty';
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import webhookFilters from '../../common/webhook-filters';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New activity',
|
||||
key: 'newActivity',
|
||||
type: 'webhook',
|
||||
description: 'Triggers when a new activity occurs.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Activity type',
|
||||
key: 'filters',
|
||||
type: 'dropdown' as const,
|
||||
required: true,
|
||||
description: 'Pick an activity type to receive events for.',
|
||||
variables: false,
|
||||
options: webhookFilters,
|
||||
},
|
||||
],
|
||||
|
||||
async testRun($) {
|
||||
if (!isEmpty($.lastExecutionStep?.dataOut)) {
|
||||
$.pushTriggerItem({
|
||||
raw: $.lastExecutionStep.dataOut,
|
||||
meta: {
|
||||
internalId: '',
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
async registerHook($) {
|
||||
const payload = {
|
||||
name: $.flow.id,
|
||||
type: 'POST',
|
||||
url: $.webhookUrl,
|
||||
filters: [$.step.parameters.filters]
|
||||
};
|
||||
|
||||
const { data } = await $.http.post(
|
||||
`/v2/public/api/webhooks`,
|
||||
payload
|
||||
);
|
||||
|
||||
await $.flow.setRemoteWebhookId(data.id);
|
||||
},
|
||||
|
||||
async unregisterHook($) {
|
||||
await $.http.delete(
|
||||
`/v2/public/api/webhooks/${$.flow.remoteWebhookId}`
|
||||
);
|
||||
},
|
||||
});
|
Reference in New Issue
Block a user