-
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 intercom v2 destination (initial commit)
- Loading branch information
1 parent
f8cd6bd
commit 80d928c
Showing
3 changed files
with
513 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,113 @@ | ||
bindings: | ||
- name: EventType | ||
path: ../../../../constants | ||
- path: ./utils | ||
exportAll: true | ||
- path: ../../bindings/jsontemplate | ||
exportAll: true | ||
- name: defaultRequestConfig | ||
path: ../../../../v0/util | ||
- name: removeUndefinedAndNullValues | ||
path: ../../../../v0/util | ||
- name: getFieldValueFromMessage | ||
path: ../../../../v0/util | ||
- name: isDefinedAndNotNull | ||
path: ../../../../v0/util | ||
- name: addExternalIdToTraits | ||
path: ../../../../v0/util | ||
- path: ../../bindings/jsontemplate | ||
- name: HTTP_STATUS_CODES | ||
path: ../../../../v0/util/constant | ||
|
||
steps: | ||
- name: checkIfProcessed | ||
condition: .message.statusCode | ||
template: | | ||
$.batchMode ? .message.body.JSON : .message; | ||
onComplete: return | ||
|
||
- name: messageType | ||
template: | | ||
.message.type.toLowerCase(); | ||
- name: validateInput | ||
template: | | ||
let messageType = $.outputs.messageType; | ||
$.assert(messageType, "message Type is not present. Aborting"); | ||
$.assert(messageType in {{$.EventType.([.IDENTIFY, .TRACK, .GROUP])}}, "message type " + messageType + " is not supported"); | ||
- name: apiVersion | ||
template: | | ||
const version = $.isDefinedAndNotNull(.destination.Config.apiVersion) ? .destination.Config.apiVersion : "v2"; | ||
version; | ||
- name: rEtlPayload | ||
condition: .message.context.mappedToDestination | ||
template: | | ||
$.addExternalIdToTraits(.message); | ||
const payload = $.getFieldValueFromMessage(.message, "traits"); | ||
$.context.payload = payload; | ||
- name: transformPayloadForV2 | ||
condition: $.outputs.apiVersion === "v2" && !.message.context.mappedToDestination | ||
steps: | ||
- name: identifyPayloadTransform | ||
condition: $.outputs.messageType === {{$.EventType.IDENTIFY}} | ||
template: | | ||
const payload = .message.({ | ||
external_id: {{{{$.getGenericPaths("userIdOnly")}}}}, | ||
email: {{{{$.getGenericPaths("email")}}}}, | ||
phone: {{{{$.getGenericPaths("phone")}}}}, | ||
avatar: {{{{$.getGenericPaths("avatar")}}}}, | ||
last_seen_at: $.toSeconds(.context.traits.lastSeenAt), | ||
role: .traits.role || .context.traits.role, | ||
signed_up_at: $.toSeconds(.traits.createdAt || .context.traits.createdAt), | ||
owner_id: Number(.traits.ownerId || .context.traits.ownerId) || undefined, | ||
unsubscribed_from_emails: .traits.unsubscribedFromEmails || .context.traits.unsubscribedFromEmails | ||
}); | ||
payload.name = $.getName(.message); | ||
payload.custom_attributes = .message.context.traits || {}; | ||
payload.custom_attributes = $.filterCustomAttributes(payload, "user", .destination); | ||
!(payload.external_id) && .destination.Config.sendAnonymousId ? payload.external_id = .message.anonymousId; | ||
$.context.payload = payload; | ||
- name: trackPayloadTransform | ||
condition: $.outputs.messageType === {{$.EventType.TRACK}} | ||
template: | | ||
const timestamp = .message.().( | ||
{{{{$.getGenericPaths("timestamp")}}}}; | ||
); | ||
const payload = .message.({ | ||
event_name: .event, | ||
user_id: {{{{$.getGenericPaths("userIdOnly")}}}}, | ||
email: {{{{$.getGenericPaths("email")}}}}, | ||
metadata: .properties | ||
}); | ||
payload.id = .message.properties.id || .message.traits.id; | ||
payload.created_at = $.toSeconds(timestamp); | ||
!(payload.user_id) && .destination.Config.sendAnonymousId ? payload.user_id = .message.anonymousId; | ||
payload = $.addMetadataToPayload(payload); | ||
$.context.payload = payload; | ||
- name: groupPayloadTransform | ||
condition: $.outputs.messageType === {{$.EventType.GROUP}} | ||
template: | | ||
const payload = .message.({ | ||
company_id: {{{{$.getGenericPaths("groupId")}}}}, | ||
name: {{{{$.getGenericPaths("name")}}}}, | ||
website: {{{{$.getGenericPaths("website")}}}}, | ||
plan: .traits.plan || .context.traits.plan, | ||
size: Number(.traits.size || .context.traits.size), | ||
industry: .traits.industry || .context.traits.industry, | ||
monthly_spend: .traits.monthlySpend || .context.traits.monthlySpend ? Number(.traits.monthlySpend || .context.traits.monthlySpend) : undefined, | ||
remote_created_at: .traits.remoteCreatedAt || .context.traits.remoteCreatedAt ? Number(.traits.remoteCreatedAt || .context.traits.remoteCreatedAt) : undefined | ||
}); | ||
payload.custom_attributes = .message.traits || {}; | ||
payload.custom_attributes = $.filterCustomAttributes(payload, "company", .destination); | ||
$.context.payload = payload; | ||
- name: statusCode | ||
const statusCode = $.getStatusCode(.message, $.outputs.apiVersion); | ||
statusCode | ||
|
||
- name: buildResponseForProcessTransformation | ||
const response = await $.constructResponse($.context.payload, .message, .destination, .metadata); | ||
response |
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,35 @@ | ||
bindings: | ||
- name: handleRtTfSingleEventError | ||
path: ../../../../v0/util/index | ||
- name: isDefinedAndNotNull | ||
path: ../../../../v0/util | ||
|
||
steps: | ||
- name: validateInput | ||
template: | | ||
$.assert(Array.isArray(^) && ^.length > 0, "Invalid event array") | ||
- name: transform | ||
externalWorkflow: | ||
path: ./procWorkflow.yaml | ||
loopOverInput: true | ||
|
||
- name: successfulEvents | ||
template: | | ||
$.outputs.transform#idx{$.isDefinedAndNotNull(.output)}.({ | ||
"batchedRequest": .output, | ||
"batched": false, | ||
"destination": ^[idx].destination, | ||
"metadata": ^[idx].metadata[], | ||
"statusCode": .outputs.statusCode | ||
})[] | ||
- name: failedEvents | ||
template: | | ||
$.outputs.transform#idx.error.( | ||
$.handleRtTfSingleEventError(^[idx], .originalError ?? ., {}) | ||
)[] | ||
- name: finalPayload | ||
template: | | ||
[...$.outputs.successfulEvents, ...$.outputs.failedEvents] |
Oops, something went wrong.