Skip to content

Commit

Permalink
feat: add Koala destination (#3122)
Browse files Browse the repository at this point in the history
* Add koala procWorkflow file

Basic steps for koala destination

* Add koala canonicalNames

* Add Koala integration test processor data

* Add User-Agent rudderstack header

* Add identity and track steps

Basic implementation of payload data per event_type

* Add messageId to Track call

* Include ip information

* Update endpoint url

profiles -> projects

* Update src/cdk/v2/destinations/koala/procWorkflow.yaml

Co-authored-by: Gauravudia <60897972+Gauravudia@users.noreply.github.com>

* Update src/cdk/v2/destinations/koala/procWorkflow.yaml

Co-authored-by: Gauravudia <60897972+Gauravudia@users.noreply.github.com>

* Update src/cdk/v2/destinations/koala/procWorkflow.yaml

Co-authored-by: Gauravudia <60897972+Gauravudia@users.noreply.github.com>

* Add KOALA as a routerTransform

* Fix wrong attr assignment

* Add rtWorkflow file

* Remove batch_mode step

* Conside properties data when collecting ko_profile_id and email

* Update src/cdk/v2/destinations/koala/procWorkflow.yaml

Co-authored-by: Gauravudia <60897972+Gauravudia@users.noreply.github.com>

* Update src/cdk/v2/destinations/koala/procWorkflow.yaml

Co-authored-by: Gauravudia <60897972+Gauravudia@users.noreply.github.com>

* Remove tool-versions, added by mistake

* Use context variables

* remove event attr from identity call

* Update tests data

* Update test/integrations/destinations/koala/processor/data.ts

Co-authored-by: Yashasvi Bajpai <33063622+yashasvibajpai@users.noreply.github.com>

* Update test/integrations/destinations/koala/processor/data.ts

Co-authored-by: Yashasvi Bajpai <33063622+yashasvibajpai@users.noreply.github.com>

* Update test/integrations/destinations/koala/processor/data.ts

Co-authored-by: Yashasvi Bajpai <33063622+yashasvibajpai@users.noreply.github.com>

* Update src/cdk/v2/destinations/koala/procWorkflow.yaml

Co-authored-by: Gauravudia <60897972+Gauravudia@users.noreply.github.com>

* Do not remove email from properties

lets keep email in properties

---------

Co-authored-by: Gauravudia <60897972+Gauravudia@users.noreply.github.com>
Co-authored-by: Yashasvi Bajpai <33063622+yashasvibajpai@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 12, 2024
1 parent fe72a9d commit 1ca039d
Show file tree
Hide file tree
Showing 6 changed files with 618 additions and 1 deletion.
65 changes: 65 additions & 0 deletions src/cdk/v2/destinations/koala/procWorkflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
bindings:
- name: EventType
path: ../../../../constants
- path: ../../bindings/jsontemplate
- name: defaultRequestConfig
path: ../../../../v0/util

steps:
- name: validateInput
template: |
$.assert(.message.type, "message Type is not present. Aborting message");
$.assert(.message.type in {{$.EventType.([.IDENTIFY, .TRACK])}},
"message type " + .message.type + " is not supported");
$.assertConfig(.destination.Config.publicKey, "publicKey is not present. Aborting message");
$.context.email = .message.().({{{{$.getGenericPaths("emailOnly")}}}});
$.context.ko_profile_id = .message.traits.ko_profile_id ?? .message.context.traits.ko_profile_id ?? .message.properties.ko_profile_id;
$.assert($.context.email || $.context.ko_profile_id, "Neither email or ko_profile_id are present on traits. Aborting message");
- name: setMessageType
template: |
$.context.messageType = .message.type.toLowerCase();
- name: preparePayloadForIdentify
condition: $.context.messageType === {{$.EventType.IDENTIFY}}
template: |
const traits = .message.traits ?? .message.context.traits ?? {};
const koTraits = traits{~['ko_profile_id']}
const basePayload = {
email: $.context.email,
profile_id: $.context.ko_profile_id,
identifies: [{
type: $.context.messageType,
sent_at: .message.().({{{{$.getGenericPaths("timestamp")}}}}),
traits: koTraits
}]
};
$.context.payload = basePayload
- name: preparePayloadForTrack
condition: $.context.messageType === {{$.EventType.TRACK}}
template: |
const properties = .message.properties ?? {};
const koProperties = properties{~['ko_profile_id']}
const basePayload = {
ip: .message.context.ip ?? .message.request_ip,
email: $.context.email,
profile_id: $.context.ko_profile_id,
events: [{
type: $.context.messageType,
event: .message.event,
message_id: .message.messageId,
sent_at: .message.().({{{{$.getGenericPaths("timestamp")}}}}),
properties: koProperties,
context: .message.context
}]
};
$.context.payload = basePayload
- name: buildResponseForProcessTransformation
template: |
const response = $.defaultRequestConfig();
response.body.JSON = $.context.payload;
response.endpoint = "https://api2.getkoala.com/web/projects/" + .destination.Config.publicKey + "/batch";
response.headers = {
"content-type": "application/json"
};
response
31 changes: 31 additions & 0 deletions src/cdk/v2/destinations/koala/rtWorkflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
bindings:
- name: handleRtTfSingleEventError
path: ../../../../v0/util/index

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.output.({
"batchedRequest": .,
"batched": false,
"destination": ^[idx].destination,
"metadata": ^[idx].metadata[],
"statusCode": 200
})[]
- name: failedEvents
template: |
$.outputs.transform#idx.error.(
$.handleRtTfSingleEventError(^[idx], .originalError ?? ., {})
)[]
- name: finalPayload
template: |
[...$.outputs.failedEvents, ...$.outputs.successfulEvents]
1 change: 1 addition & 0 deletions src/constants/destinationCanonicalNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const DestCanonicalNames = {
'the trade desk',
],
INTERCOM: ['INTERCOM', 'intercom', 'Intercom'],
koala: ['Koala', 'koala', 'KOALA'],
};

module.exports = { DestHandlerMap, DestCanonicalNames };
3 changes: 2 additions & 1 deletion src/features.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
"REDDIT": true,
"THE_TRADE_DESK": true,
"INTERCOM": true,
"NINETAILED": true
"NINETAILED": true,
"KOALA": true
},
"regulations": [
"BRAZE",
Expand Down
Loading

0 comments on commit 1ca039d

Please sign in to comment.