-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Expand file tree
/
Copy pathbase-webhook.mjs
More file actions
78 lines (74 loc) · 1.62 KB
/
base-webhook.mjs
File metadata and controls
78 lines (74 loc) · 1.62 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import caspio from "../../caspio.app.mjs";
import { ConfigurationError } from "@pipedream/platform";
export default {
props: {
caspio,
db: "$.service.db",
http: {
type: "$.interface.http",
customResponse: true,
},
name: {
type: "string",
label: "Name",
description: "Meaningful label that identifies the webhook",
},
table: {
propDefinition: [
caspio,
"table",
],
},
},
hooks: {
async activate() {
const { Id: webhookId } = await this.caspio.createWebhook({
data: {
Name: this.name,
OutgoingUrls: [
this.http.endpoint,
],
},
});
this._setWebhookId(webhookId);
await this.caspio.createWebhookEvent({
webhookId,
data: {
EventType: this.getEventType(),
ObjectName: this.table,
},
});
},
async deactivate() {
const webhookId = this._getWebhookId();
if (!webhookId) {
return;
}
await this.caspio.deleteWebhook(webhookId);
},
},
methods: {
_setWebhookId(webhookId) {
this.db.set("webhookId", webhookId);
},
_getWebhookId() {
return this.db.get("webhookId");
},
getEventType() {
throw new ConfigurationError("getEventType is not implemented");
},
generateMeta() {
throw new ConfigurationError("generateMeta is not implemented");
},
},
async run({ body }) {
this.http.respond({
status: 200,
});
if (!body) {
return;
}
const meta = this.generateMeta(body);
this.$emit(body, meta);
},
};