Skip to content

Commit

Permalink
fix: address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
manish339k committed Oct 8, 2024
1 parent 3d35e5a commit 3dbb376
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/v0/destinations/intercom_v2/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,23 @@ const transformIdentifyPayload = (event) => {
const { message, destination } = event;
const category = ConfigCategory.IDENTIFY;
const payload = constructPayload(message, MappingConfig[category.name]);
const shouldSendAnonymousId = destination.Config.sendAnonymousId;
if (!payload.external_id && shouldSendAnonymousId) {
payload.external_id = message.anonymousId;
}
if (!(payload.external_id || payload.email)) {
throw new InstrumentationError('Either email or userId is required for Identify call');
}
payload.name = getName(message);
payload.custom_attributes = message.traits || message.context.traits || {};
payload.custom_attributes = filterCustomAttributes(payload, 'user', destination);
const shouldSendAnonymousId = destination.Config.sendAnonymousId;
if (!payload.external_id && shouldSendAnonymousId) {
payload.external_id = message.anonymousId;
}
return payload;
};

const transformTrackPayload = (event) => {
const { message, destination } = event;
const category = ConfigCategory.TRACK;
let payload = constructPayload(message, MappingConfig[category.name]);
if (!(payload.user_id || payload.email)) {
throw new InstrumentationError('Either email or userId is required for Track call');
}
if (!payload.id) {
const integrationsObj = getIntegrationsObj(message, 'INTERCOM');
payload.id = integrationsObj?.id;
Expand All @@ -57,6 +54,9 @@ const transformTrackPayload = (event) => {
if (!payload.user_id && shouldSendAnonymousId) {
payload.user_id = message.anonymousId;
}
if (!(payload.user_id || payload.email || payload.id)) {
throw new InstrumentationError('Either email or userId or id is required for Track call');
}
payload = addMetadataToPayload(payload);
return payload;
};
Expand Down
2 changes: 1 addition & 1 deletion test/integrations/destinations/intercom_v2/router/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ export const data: RouterTestData[] = [
},
{
batched: false,
error: 'Either email or userId is required for Track call',
error: 'Either email or userId or id is required for Track call',
statTags: RouterInstrumentationErrorStatTags,
destination,
metadata: [generateMetadata(2)],
Expand Down

0 comments on commit 3dbb376

Please sign in to comment.