-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadd-everlytic-activity-sf.js
31 lines (27 loc) · 1.18 KB
/
add-everlytic-activity-sf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
query(`SELECT Id FROM Contact WHERE Everlytic_ID__c = '${state.data.__query_params.c_id}'`);
// alterState(state => {
// console.log(state)
// return state;
// })
bulk('Event', 'upsert', { extIdField: 'Everlytic_ID__c', failOnError: true }, state => {
const time = new Date(parseInt(state.data.__query_params.timestamp)).toISOString();
const bounced = (state.data.__query_params.event === 'bounce' ? true : false);
const read = (state.data.__query_params.event === 'email_read' ? true : false);
const delivered = (state.data.__query_params.event === 'delivered' ? true : false);
const smsText = (state.data.__query_params.message ? state.data.__query_params.message : '' );
const eventId = state.data.__query_params.c_id + "/e" + state.data.__query_params.timestamp;
return [{
Everlytic_ID__c: eventId,
ActivityDateTime: time,
WhoId: state.references[0].records[0].Id, // the sfID from the above query
// Who: {
// Everlytic_ID__c: state.data.__query_params.c_id
// },
DurationInMinutes: 0,
Subject: state.data.__query_params.event,
Bounced__c: bounced,
Read_Reciept__c: read,
Delivered__c: delivered,
SMS_Text__c: smsText,
}];
});