Skip to content

Commit

Permalink
feat: onboard intercom v2 destination (initial commit)
Browse files Browse the repository at this point in the history
  • Loading branch information
manish339k committed Sep 9, 2024
1 parent f8cd6bd commit 80d928c
Show file tree
Hide file tree
Showing 3 changed files with 513 additions and 0 deletions.
113 changes: 113 additions & 0 deletions src/cdk/v2/destinations/intercom_v2/procWorkflow.yaml
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
35 changes: 35 additions & 0 deletions src/cdk/v2/destinations/intercom_v2/rtWorkflow.yaml
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]
Loading

0 comments on commit 80d928c

Please sign in to comment.