Skip to content

Commit

Permalink
fix: handle error-first
Browse files Browse the repository at this point in the history
  • Loading branch information
gitcommitshow committed Mar 5, 2024
1 parent 08148e4 commit 0771e87
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/v0/sources/slack/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,24 @@ function processNormalEvent(slackPayload) {
break;
}
message.setEventName(normalizeEventName(slackPayload.event.type));
if (slackPayload.event.user) {
const stringifiedUserId =
typeof slackPayload.event.user === 'object'
? slackPayload.event.user.id
: slackPayload.event.user;
message.setProperty(
'anonymousId',
stringifiedUserId ? sha256(stringifiedUserId).toString().substring(0, 36) : generateUUID(),
);
// Set the user id received from Slack into externalId
message.context.externalId = [
{
type: 'slackUserId',
id: stringifiedUserId,
},
];
} else {
if (!slackPayload.event.user) {
throw new TransformationError('UserId not found');
}
const stringifiedUserId =
typeof slackPayload.event.user === 'object'
? slackPayload.event.user.id
: slackPayload.event.user;
message.setProperty(
'anonymousId',
stringifiedUserId ? sha256(stringifiedUserId).toString().substring(0, 36) : generateUUID(),
);
// Set the user id received from Slack into externalId
message.context.externalId = [
{
type: 'slackUserId',
id: stringifiedUserId,
},
];
// Set the standard common event fields. More info at https://www.rudderstack.com/docs/event-spec/standard-events/common-fields/
// originalTimestamp - The actual time (in UTC) when the event occurred
message.setProperty(
Expand Down

0 comments on commit 0771e87

Please sign in to comment.