Skip to content

Commit 5175f93

Browse files
committed
Initial shared webhook with 3 sources
1 parent 17baeee commit 5175f93

File tree

5 files changed

+176
-4
lines changed

5 files changed

+176
-4
lines changed
Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,62 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "salesforge",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
workspaceId: {
8+
type: "string",
9+
label: "Workspace ID",
10+
description: "Select a workspace or provide a workspace ID",
11+
async options() {
12+
const workspaces = await this.listWorkspaces();
13+
return workspaces?.map((workspace) => ({
14+
label: workspace.name,
15+
value: workspace.id,
16+
}));
17+
},
18+
},
19+
},
520
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
21+
_apiUrl() {
22+
return "https://api.salesforge.ai/public/v2";
23+
},
24+
async _makeRequest({
25+
$ = this,
26+
path,
27+
...args
28+
}) {
29+
return axios($, {
30+
url: `${this._apiUrl()}${path}`,
31+
headers: {
32+
"authorization": `${this.$auth.api_key}`,
33+
},
34+
...args,
35+
});
36+
},
37+
async listWorkspaces(args = {}) {
38+
return this._makeRequest({
39+
path: "/workspaces",
40+
...args,
41+
});
42+
},
43+
async createWebhook({
44+
workspaceId, ...args
45+
}) {
46+
return this._makeRequest({
47+
path: `/workspaces/${workspaceId}/integrations/webhooks`,
48+
method: "POST",
49+
...args,
50+
});
51+
},
52+
async deleteWebhook({
53+
workspaceId, webhookId, ...args
54+
}) {
55+
return this._makeRequest({
56+
path: `/workspaces/${workspaceId}/integrations/webhooks/${webhookId}`,
57+
method: "DELETE",
58+
...args,
59+
});
960
},
1061
},
1162
};
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { v4 as uuid } from "uuid";
2+
import salesforge from "../../salesforge.app.mjs";
3+
4+
export default {
5+
props: {
6+
salesforge,
7+
db: "$.service.db",
8+
http: "$.interface.http",
9+
workspaceId: {
10+
propDefinition: [
11+
salesforge,
12+
"workspaceId",
13+
],
14+
},
15+
},
16+
methods: {
17+
_getWebhookId() {
18+
return this.db.get("webhookId");
19+
},
20+
_setWebhookId(webhookId) {
21+
this.db.set("webhookId", webhookId);
22+
},
23+
generateMeta(data) {
24+
const { id } = data;
25+
return {
26+
id: id || uuid(),
27+
summary: this.getSummary(data),
28+
ts: Date.now(),
29+
};
30+
},
31+
},
32+
hooks: {
33+
async activate() {
34+
const response = await this.salesforge.createWebhook({
35+
workspaceId: this.workspaceId,
36+
data: {
37+
name: `Pipedream ${this.getEventType()} webhook`,
38+
type: this.getEventType(),
39+
url: this.http.endpoint,
40+
},
41+
});
42+
this._setWebhookId(response.id);
43+
},
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+
},
53+
},
54+
async run(event) {
55+
const { body } = event;
56+
if (body) {
57+
const meta = this.generateMeta(body);
58+
this.$emit(body, meta);
59+
}
60+
},
61+
};
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-opened-instant",
6+
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)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
methods: {
12+
...common.methods,
13+
getEventType() {
14+
return "email_opened";
15+
},
16+
getSummary(data) {
17+
return `Email opened: ${data.name || data.id}`;
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-sent-instant",
6+
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)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
methods: {
12+
...common.methods,
13+
getEventType() {
14+
return "email_sent";
15+
},
16+
getSummary(data) {
17+
return `Email sent: ${data.name || data.id}`;
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-link-clicked-instant",
6+
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)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
methods: {
12+
...common.methods,
13+
getEventType() {
14+
return "link_clicked";
15+
},
16+
getSummary(data) {
17+
return `Link clicked: ${data.name || data.url || data.id}`;
18+
},
19+
},
20+
};

0 commit comments

Comments
 (0)