@vulture916/activepieces-piece-lemlist
Version:
Lemlist integration for ActivePieces - Email outreach and sales engagement platform
86 lines (82 loc) • 2.64 kB
JavaScript
const { createAction, Property } = require('@activepieces/pieces-framework');
const { HttpMethod } = require('@activepieces/pieces-common');
const { lemlistAuth } = require('../../common/auth');
const { lemlistClient } = require('../../common/client');
exports.createCampaign = createAction({
auth: lemlistAuth,
name: 'create_campaign',
displayName: 'Create Campaign',
description: 'Create a new campaign',
props: {
name: Property.ShortText({
displayName: 'Campaign Name',
description: 'Name for the new campaign',
required: true,
}),
senderId: Property.ShortText({
displayName: 'Sender ID',
description: 'ID of the sender for this campaign',
required: false,
}),
scheduleId: Property.ShortText({
displayName: 'Schedule ID',
description: 'ID of the schedule to use for this campaign',
required: false,
}),
trackOpen: Property.Checkbox({
displayName: 'Track Opens',
description: 'Track when emails are opened',
required: false,
defaultValue: true,
}),
trackClick: Property.Checkbox({
displayName: 'Track Clicks',
description: 'Track when links are clicked',
required: false,
defaultValue: true,
}),
trackBounce: Property.Checkbox({
displayName: 'Track Bounces',
description: 'Track email bounces',
required: false,
defaultValue: true,
}),
domainDeductEmail: Property.Checkbox({
displayName: 'Deduce Email from Domain',
description: 'Automatically deduce email addresses from domains',
required: false,
defaultValue: false,
}),
},
async run(context) {
const body = {
name: context.propsValue.name,
};
// Only add optional fields if they are provided
if (context.propsValue.senderId) {
body.senderId = context.propsValue.senderId;
}
if (context.propsValue.scheduleId) {
body.scheduleId = context.propsValue.scheduleId;
}
if (context.propsValue.trackOpen !== undefined) {
body.trackOpen = context.propsValue.trackOpen;
}
if (context.propsValue.trackClick !== undefined) {
body.trackClick = context.propsValue.trackClick;
}
if (context.propsValue.trackBounce !== undefined) {
body.trackBounce = context.propsValue.trackBounce;
}
if (context.propsValue.domainDeductEmail !== undefined) {
body.domainDeductEmail = context.propsValue.domainDeductEmail;
}
const campaign = await lemlistClient.makeRequest(
context.auth,
HttpMethod.POST,
'/campaigns',
body
);
return campaign;
},
});