-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: onboard closeCRM source (#3467)
* feat: onboard closeCRM source * fix: fixed timestamp issue * fix: fixed minor issues * fix: fixed payload * fix: test case
- Loading branch information
1 parent
11ce96b
commit bba1a3b
Showing
3 changed files
with
455 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const excludedFieldList = ['changed_fields', 'previous_data']; | ||
|
||
module.exports = { excludedFieldList }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const moment = require('moment'); | ||
const { | ||
removeUndefinedAndNullValues, | ||
removeUndefinedAndNullRecurse, | ||
generateUUID, | ||
formatTimeStamp, | ||
} = require('../../../v0/util'); | ||
const { excludedFieldList } = require('./config'); | ||
const Message = require('../../../v0/sources/message'); | ||
|
||
function processEvent(inputEvent) { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
const { event, subscription_id } = inputEvent; | ||
|
||
const message = new Message('CloseCRM'); | ||
|
||
// Set event type track | ||
message.setEventType('track'); | ||
|
||
// Set event name | ||
const eventName = `${event.object_type} ${event.action}`; | ||
message.setEventName(eventName); | ||
|
||
// Set userId | ||
if (event.lead_id) { | ||
message.setProperty('userId', event.lead_id); | ||
} else { | ||
message.setProperty('anonymousId', generateUUID()); | ||
} | ||
|
||
// Set messageId | ||
message.setProperty('messageId', event.id); | ||
|
||
// Set Timestamp | ||
const timestamp = moment.utc(event.date_updated); | ||
message.setProperty('originalTimestamp', formatTimeStamp(timestamp, 'yyyy-MM-ddTHH:mm:ss.SSSZ')); | ||
|
||
// Set properties | ||
removeUndefinedAndNullRecurse(event); | ||
message.setProperty('properties', event); | ||
message.setProperty('properties.subscription_id', subscription_id); | ||
|
||
// Remove excluding fields | ||
excludedFieldList.forEach((field) => { | ||
delete message.properties[field]; | ||
}); | ||
|
||
return message; | ||
} | ||
|
||
function process(inputEvent) { | ||
const { event } = inputEvent; | ||
const response = processEvent(event); | ||
return removeUndefinedAndNullValues(response); | ||
} | ||
|
||
exports.process = process; |
Oops, something went wrong.