Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass eventOccurredTS value to the custom_args of the sendgrid/twilio body #1955

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ describe.each([
source_id: 'sourceId',
space_id: 'spaceId',
user_id: userData.userId,
event_occurred_ts: '2024-03-23T23:02:40.563Z',
__segment_internal_external_id_key__: 'email',
__segment_internal_external_id_value__: userData.email
}
Expand Down Expand Up @@ -161,7 +162,7 @@ describe.each([
]
},
traits: { '@path': '$.properties' },
eventOccurredTS: { '@path': '$.timestamp' },
eventOccurredTS: '2024-03-23T23:02:40.563Z',
...overrides
}
}
Expand Down Expand Up @@ -304,6 +305,7 @@ describe.each([
journey_id: 'journeyId',
journey_state_id: 'journeyStateId',
audience_id: 'audienceId',
event_occurred_ts: '2024-03-23T23:02:40.563Z',
__segment_internal_external_id_key__: 'email',
__segment_internal_external_id_value__: userData.email
}
Expand Down Expand Up @@ -359,7 +361,8 @@ describe.each([
customArgs: {
journey_id: 'journeyId',
journey_state_id: 'journeyStateId',
audience_id: 'audienceId'
audience_id: 'audienceId',
event_occurred_ts: '2024-03-23T23:02:40.563Z'
},
previewText: 'unused',
subject: 'Test email with metadata',
Expand All @@ -373,7 +376,7 @@ describe.each([
{ id: userData.phone, type: 'phone', subscriptionStatus: 'true', channelType: 'sms' }
],
traits: { '@path': '$.properties' },
eventOccurredTS: { '@path': '$.timestamp' }
eventOccurredTS: '2024-03-23T23:02:40.563Z'
}
})

Expand Down Expand Up @@ -423,6 +426,7 @@ describe.each([
source_id: 'sourceId',
space_id: 'spaceId',
user_id: userData.userId,
event_occurred_ts: '2024-03-23T23:02:40.563Z',
__segment_internal_external_id_key__: 'email',
__segment_internal_external_id_value__: userData.email
}
Expand Down Expand Up @@ -505,6 +509,7 @@ describe.each([
source_id: 'sourceId',
space_id: 'spaceId',
user_id: userData.userId,
event_occurred_ts: '2024-03-23T23:02:40.563Z',
__segment_internal_external_id_key__: 'email',
__segment_internal_external_id_value__: userData.email
}
Expand Down Expand Up @@ -603,6 +608,7 @@ describe.each([
source_id: 'sourceId',
space_id: 'spaceId',
user_id: userData.userId,
event_occurred_ts: '2024-03-23T23:02:40.563Z',
__segment_internal_external_id_key__: 'email',
__segment_internal_external_id_value__: userData.email
}
Expand Down Expand Up @@ -682,6 +688,7 @@ describe.each([
source_id: 'sourceId',
space_id: 'spaceId',
user_id: userData.userId,
event_occurred_ts: '2024-03-23T23:02:40.563Z',
__segment_internal_external_id_key__: 'email',
__segment_internal_external_id_value__: userData.email
}
Expand Down Expand Up @@ -782,6 +789,7 @@ describe.each([
source_id: 'sourceId',
space_id: 'spaceId',
user_id: userData.userId,
event_occurred_ts: '2024-03-23T23:02:40.563Z',
__segment_internal_external_id_key__: 'email',
__segment_internal_external_id_value__: userData.email
}
Expand Down Expand Up @@ -869,6 +877,7 @@ describe.each([
source_id: 'sourceId',
space_id: 'spaceId',
user_id: userData.userId,
event_occurred_ts: '2024-03-23T23:02:40.563Z',
__segment_internal_external_id_key__: 'email',
__segment_internal_external_id_value__: userData.email
}
Expand Down Expand Up @@ -956,6 +965,7 @@ describe.each([
source_id: 'sourceId',
space_id: 'spaceId',
user_id: userData.userId,
event_occurred_ts: '2024-03-23T23:02:40.563Z',
__segment_internal_external_id_key__: 'email',
__segment_internal_external_id_value__: userData.email
}
Expand Down Expand Up @@ -1043,6 +1053,7 @@ describe.each([
source_id: 'sourceId',
space_id: 'spaceId',
user_id: userData.userId,
event_occurred_ts: '2024-03-23T23:02:40.563Z',
__segment_internal_external_id_key__: 'email',
__segment_internal_external_id_value__: userData.email
}
Expand Down Expand Up @@ -1126,6 +1137,7 @@ describe.each([
source_id: 'sourceId',
space_id: 'spaceId',
user_id: userData.userId,
event_occurred_ts: '2024-03-23T23:02:40.563Z',
__segment_internal_external_id_key__: 'email',
__segment_internal_external_id_value__: userData.email
}
Expand Down Expand Up @@ -1212,6 +1224,7 @@ describe.each([
source_id: 'sourceId',
space_id: 'spaceId',
user_id: userData.userId,
event_occurred_ts: '2024-03-23T23:02:40.563Z',
__segment_internal_external_id_key__: 'email',
__segment_internal_external_id_value__: userData.email
}
Expand Down Expand Up @@ -2265,6 +2278,7 @@ describe.each([
source_id: 'sourceId',
space_id: 'spaceId',
user_id: userData.userId,
event_occurred_ts: '2024-03-23T23:02:40.563Z',
__segment_internal_external_id_key__: 'email',
__segment_internal_external_id_value__: userData.email
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export class SendEmailPerformer extends MessageSendPerformer<Settings, Payload>
source_id: this.settings.sourceId,
space_id: this.settings.spaceId,
user_id: this.payload.userId ?? undefined,
event_occurred_ts: this.payload?.eventOccurredTS,
__segment_internal_external_id_key__: EXTERNAL_ID_KEY,
__segment_internal_external_id_value__: profile[EXTERNAL_ID_KEY]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ const testAction = createTestAction({
badgeStrategy: null,
ttl: null,
tapActionButtons: null
}
},
eventOccurredTS: '2024-03-23T23:02:40.563Z'
})
})

Expand Down Expand Up @@ -112,7 +113,7 @@ describe('sendMobilePush action', () => {
const notifyReqBody = getDefaultExpectedNotifyApiReq(externalId)
notifyReqBody.append(
'DeliveryCallbackUrl',
`http://localhost.com/?space_id=spaceid&__segment_internal_external_id_key__=${externalId.type}&__segment_internal_external_id_value__=${externalId.id}#rp=all&rc=600`
`http://localhost.com/?space_id=spaceid&event_occurred_ts=2024-03-23T23%3A02%3A40.563Z&__segment_internal_external_id_key__=${externalId.type}&__segment_internal_external_id_value__=${externalId.id}#rp=all&rc=600`
)

nock(`https://content.twilio.com`).get(`/v1/Content/${contentSid}`).reply(200, defaultTemplate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ describe.each(['stage', 'production'])('%s environment', (environment) => {
{ type: 'email', id: 'test@twilio.com', subscriptionStatus: 'true' },
{ type: 'phone', id: phoneNumber, subscriptionStatus: 'true', channelType: 'sms' }
],
sendBasedOnOptOut: false
sendBasedOnOptOut: false,
eventOccurredTS: '2024-03-23T23:02:40.563Z'
})
})

Expand Down Expand Up @@ -401,7 +402,7 @@ describe.each(['stage', 'production'])('%s environment', (environment) => {
ShortenUrls: 'true',
Tags: defaultTags,
StatusCallback:
'http://localhost/?foo=bar&space_id=d&__segment_internal_external_id_key__=phone&__segment_internal_external_id_value__=%2B1234567891#rp=all&rc=5'
'http://localhost/?foo=bar&space_id=d&event_occurred_ts=2024-03-23T23%3A02%3A40.563Z&__segment_internal_external_id_key__=phone&__segment_internal_external_id_value__=%2B1234567891#rp=all&rc=5'
})
const twilioRequest = nock('https://api.twilio.com/2010-04-01/Accounts/a')
.post('/Messages.json', expectedTwilioRequest.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ describe.each(['stage', 'production'])('%s environment', (environment) => {
externalIds: [
{ type: 'email', id: 'test@twilio.com', subscriptionStatus: 'subscribed' },
{ type: 'phone', id: phoneNumber, subscriptionStatus: 'subscribed', channelType: 'whatsapp' }
]
],
eventOccurredTS: '2024-03-23T23:02:40.563Z'
})
})

Expand Down Expand Up @@ -269,7 +270,7 @@ describe.each(['stage', 'production'])('%s environment', (environment) => {
To: defaultTo,
Tags: defaultTags,
StatusCallback:
'http://localhost/?foo=bar&space_id=d&__segment_internal_external_id_key__=phone&__segment_internal_external_id_value__=%2B1234567891#rp=all&rc=5'
'http://localhost/?foo=bar&space_id=d&event_occurred_ts=2024-03-23T23%3A02%3A40.563Z&__segment_internal_external_id_key__=phone&__segment_internal_external_id_value__=%2B1234567891#rp=all&rc=5'
})
const twilioRequest = nock('https://api.twilio.com/2010-04-01/Accounts/a')
.post('/Messages.json', expectedTwilioRequest.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const Liquid = new LiquidJs()

export interface TwilioPayloadBase extends MessagePayloadBase {
contentSid?: string
eventOccurredTS?: string
}

export abstract class TwilioMessageSender<TPayload extends TwilioPayloadBase> extends MessageSendPerformer<
Expand Down Expand Up @@ -121,6 +122,7 @@ export abstract class TwilioMessageSender<TPayload extends TwilioPayloadBase> ex
const customArgs: Record<string, string | undefined> = {
...this.payload.customArgs,
space_id: this.settings.spaceId,
event_occurred_ts: this.payload?.eventOccurredTS,
Copy link
Member

Choose a reason for hiding this comment

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

You missed assigning adding it to Tags - which is used by Event Streams:

body.append('Tags', JSON.stringify(tags))
if (webhookUrlWithParams) {
body.append('StatusCallback', webhookUrlWithParams)
}

Even though we do pass that "webhook" (i.e. callback Url) - I don't believe it is used anymore. So most important is add it to tags. However you need to make sure you're not exceeding tag limits - I think it was up to 10 tags max.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I had the tags change but changed it back, I was waiting to ask you about the tags limit knowing it exists and it currently has 10 tags already, do you know which one I could remove safely, or if that limit can be changed? Thanks Philipp

__segment_internal_external_id_key__: externalIdType,
__segment_internal_external_id_value__: externalIdValue
}
Expand Down