Skip to content

Commit 41d16da

Browse files
committed
Webhook sources improvements
1 parent 84e6c33 commit 41d16da

File tree

8 files changed

+99
-22
lines changed

8 files changed

+99
-22
lines changed

components/salesforge/sources/common/webhook.mjs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { v4 as uuid } from "uuid";
21
import salesforge from "../../salesforge.app.mjs";
32

43
export default {
@@ -21,11 +20,15 @@ export default {
2120
this.db.set("webhookId", webhookId);
2221
},
2322
generateMeta(data) {
24-
const { id } = data;
23+
const { webhookInfo } = data;
24+
const ts = webhookInfo?.eventTime
25+
? new Date(webhookInfo.eventTime).valueOf()
26+
: Date.now();
27+
const id = `${this.getEventType()}-${ts}`;
2528
return {
26-
id: id || uuid(),
29+
id,
2730
summary: this.getSummary(data),
28-
ts: Date.now(),
31+
ts,
2932
};
3033
},
3134
},
@@ -41,15 +44,7 @@ export default {
4144
});
4245
this._setWebhookId(response.id);
4346
},
44-
async deactivate() {
45-
const webhookId = this._getWebhookId();
46-
if (webhookId) {
47-
await this.salesforge.deleteWebhook({
48-
workspaceId: this.workspaceId,
49-
webhookId,
50-
});
51-
}
52-
},
47+
// Salesforge does not seem to support deactivating/deleting webhooks via the API
5348
},
5449
async run(event) {
5550
const { body } = event;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import common from "../common/webhook.mjs";
2+
3+
export default {
4+
...common,
5+
key: "salesforge-contact-unsubscribed-instant",
6+
name: "Contact Unsubscribed (Instant)",
7+
description: "Emit new event when a contact unsubscribes in Salesforge. [See the documentation](https://help.salesforge.ai/en/articles/8680365-how-to-use-webhooks)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
methods: {
12+
...common.methods,
13+
getEventType() {
14+
return "contact_unsubscribed";
15+
},
16+
getSummary({ contact }) {
17+
return `Contact unsubscribed: ${contact?.email || "unknown contact"}`;
18+
},
19+
},
20+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import common from "../common/webhook.mjs";
2+
3+
export default {
4+
...common,
5+
key: "salesforge-email-bounced-instant",
6+
name: "Email Bounced (Instant)",
7+
description: "Emit new event when an email bounces in Salesforge. [See the documentation](https://help.salesforge.ai/en/articles/8680365-how-to-use-webhooks)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
methods: {
12+
...common.methods,
13+
getEventType() {
14+
return "email_bounced";
15+
},
16+
getSummary({ contact }) {
17+
return `Email bounced to ${contact?.email || "unknown recipient"}`;
18+
},
19+
},
20+
};

components/salesforge/sources/email-opened-instant/email-opened-instant.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
...common,
55
key: "salesforge-email-opened-instant",
66
name: "Email Opened (Instant)",
7-
description: "Emit new event when an email is opened in Salesforge. [See the documentation](https://api.salesforge.ai/public/v2/swagger/index.html)",
7+
description: "Emit new event when an email is opened in Salesforge. [See the documentation](https://help.salesforge.ai/en/articles/8680365-how-to-use-webhooks)",
88
version: "0.0.1",
99
type: "source",
1010
dedupe: "unique",
@@ -13,8 +13,8 @@ export default {
1313
getEventType() {
1414
return "email_opened";
1515
},
16-
getSummary(data) {
17-
return `Email opened: ${data.name || data.id}`;
16+
getSummary({ sequenceEmail }) {
17+
return `Email opened: "${sequenceEmail?.subject}"`;
1818
},
1919
},
2020
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import common from "../common/webhook.mjs";
2+
3+
export default {
4+
...common,
5+
key: "salesforge-email-replied-instant",
6+
name: "Email Reply Received (Instant)",
7+
description: "Emit new event when an email reply is received in Salesforge. [See the documentation](https://help.salesforge.ai/en/articles/8680365-how-to-use-webhooks)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
methods: {
12+
...common.methods,
13+
getEventType() {
14+
return "email_replied";
15+
},
16+
getSummary({ sequenceEmail }) {
17+
return `Email reply received: "${sequenceEmail?.subject}"`;
18+
},
19+
},
20+
};

components/salesforge/sources/email-sent-instant/email-sent-instant.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
...common,
55
key: "salesforge-email-sent-instant",
66
name: "Email Sent (Instant)",
7-
description: "Emit new event when an email is sent in Salesforge. [See the documentation](https://api.salesforge.ai/public/v2/swagger/index.html)",
7+
description: "Emit new event when an email is sent in Salesforge. [See the documentation](https://help.salesforge.ai/en/articles/8680365-how-to-use-webhooks)",
88
version: "0.0.1",
99
type: "source",
1010
dedupe: "unique",
@@ -13,8 +13,8 @@ export default {
1313
getEventType() {
1414
return "email_sent";
1515
},
16-
getSummary(data) {
17-
return `Email sent: ${data.name || data.id}`;
16+
getSummary({ sequenceEmail }) {
17+
return `Email sent: "${sequenceEmail?.subject}"`;
1818
},
1919
},
2020
};

components/salesforge/sources/link-clicked-instant/link-clicked-instant.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
...common,
55
key: "salesforge-link-clicked-instant",
66
name: "Link Clicked (Instant)",
7-
description: "Emit new event when a link is clicked in Salesforge. [See the documentation](https://api.salesforge.ai/public/v2/swagger/index.html)",
7+
description: "Emit new event when a link is clicked in Salesforge. [See the documentation](https://help.salesforge.ai/en/articles/8680365-how-to-use-webhooks)",
88
version: "0.0.1",
99
type: "source",
1010
dedupe: "unique",
@@ -13,8 +13,10 @@ export default {
1313
getEventType() {
1414
return "link_clicked";
1515
},
16-
getSummary(data) {
17-
return `Link clicked: ${data.name || data.url || data.id}`;
16+
getSummary({
17+
sequenceEmail, linkUrl,
18+
}) {
19+
return `Link clicked: ${linkUrl} in "${sequenceEmail?.subject}"`;
1820
},
1921
},
2022
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import common from "../common/webhook.mjs";
2+
3+
export default {
4+
...common,
5+
key: "salesforge-negative-reply-instant",
6+
name: "Negative Reply Received (Instant)",
7+
description: "Emit new event when a negative reply is received in Salesforge. [See the documentation](https://help.salesforge.ai/en/articles/8680365-how-to-use-webhooks)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
methods: {
12+
...common.methods,
13+
getEventType() {
14+
return "negative_reply";
15+
},
16+
getSummary({ contact }) {
17+
return `Negative reply received from ${contact?.email || "unknown contact"}`;
18+
},
19+
},
20+
};

0 commit comments

Comments
 (0)