Skip to content

Commit

Permalink
fix: intercom export fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vklimontovich committed Dec 13, 2023
1 parent 5353174 commit 81cd0fb
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions webapps/ee-api/pages/api/marketing-automation/intercom/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,26 @@ const handler = async function handler(req: NextApiRequest, res: NextApiResponse
} else if (searchResult.data.length > 1) {
getLog().atInfo().log(`Contact ${email} has ${searchResult.data.length} in Intercom, taking the first one`);
}
const userId = searchResult.data.map(d => d.external_id).find(id => id !== undefined);
if (!userId) {
getLog()
.atInfo()
.log(`Non of ${searchResult.data.length} contacts attached to ${email} doesn't have external_id`);
const intercomUserId = searchResult.data.map(d => d.id).find(id => id !== undefined);
if (!intercomUserId) {
getLog().atInfo().log(`Non of ${searchResult.data.length} contacts attached to ${email} doesn't have id`);
invalidEvents++;
continue;
}
await client.events.create({
eventName: eventName as string,
createdAt: Math.round((timestamp as Date).getTime() / 1000),
userId: userId,
id: messageId as string,
id: intercomUserId,
});
sentEvents.eventIds.push(messageId);
await sentEventsTable.put(email as string, sentEvents);
}
}
return { ok: true, alreadySent, newEvents, invalidEvents };
const apiResponse = { ok: true, alreadySent, newEvents, invalidEvents };
getLog()
.atInfo()
.log(`Result: ${JSON.stringify(apiResponse, null, 2)}`);
return apiResponse;
};

export default withErrorHandler(handler);

1 comment on commit 81cd0fb

@vercel
Copy link

@vercel vercel bot commented on 81cd0fb Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

new-jitsu-ee-api – ./webapps/ee-api

onetag-ee-api.vercel.app
new-jitsu-ee-api-git-newjitsu-jitsu.vercel.app
new-jitsu-ee-api-jitsu.vercel.app
ee.jitsu.dev

Please sign in to comment.