-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sources - New Record (Instant) Actions - Create Update Delete Record
- Loading branch information
1 parent
6fcffc8
commit 68d1632
Showing
6 changed files
with
261 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const camelCaseToWords = (s) => { | ||
const result = s.replace(/([A-Z])/g, " $1"); | ||
return result.charAt(0).toUpperCase() + result.slice(1); | ||
}; | ||
|
||
export const capitalizeFirstLetter = (string) => { | ||
return string.charAt(0).toLowerCase() + string.slice(1); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 24 additions & 42 deletions
66
components/twenty/sources/new-record-instant/new-record-instant.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,45 @@ | ||
import twenty from "../../twenty.app.mjs"; | ||
import { axios } from "@pipedream/platform"; | ||
import sampleEmit from "./test-event.mjs"; | ||
|
||
export default { | ||
key: "twenty-new-record-instant", | ||
name: "New Record Instant", | ||
name: "New Record (Instant)", | ||
description: "Emit new event when a record is created, updated, or deleted.", | ||
version: "0.0.{{ts}}", | ||
version: "0.0.1", | ||
type: "source", | ||
dedupe: "unique", | ||
props: { | ||
twenty: { | ||
type: "app", | ||
app: "twenty", | ||
}, | ||
http: { | ||
type: "$.interface.http", | ||
customResponse: true, | ||
}, | ||
twenty, | ||
http: "$.interface.http", | ||
db: "$.service.db", | ||
}, | ||
hooks: { | ||
async deploy() { | ||
// This source does not fetch historical data | ||
}, | ||
async activate() { | ||
// Logic to create a webhook subscription if supported by the app | ||
const { data } = await this.twenty.createHook({ | ||
data: { | ||
targetUrl: this.http.endpoint, | ||
operation: "*.*", | ||
}, | ||
}); | ||
|
||
this.db.set("webhookId", data.createWebhook.id); | ||
}, | ||
async deactivate() { | ||
// Logic to delete the webhook subscription if supported by the app | ||
const webhookId = this.db.get("webhookId"); | ||
await this.twenty.deleteHook(webhookId); | ||
}, | ||
}, | ||
async run(event) { | ||
const { | ||
actionType, recordId, recordData, | ||
} = event.body; | ||
const { body } = event; | ||
|
||
try { | ||
const result = await this.twenty.performAction({ | ||
actionType, | ||
recordId, | ||
recordData, | ||
}); | ||
|
||
this.$emit(result, { | ||
id: result.id || `${actionType}-${Date.now()}`, | ||
summary: `${actionType.toUpperCase()} action performed`, | ||
ts: Date.parse(result.createdAt || new Date()), | ||
}); | ||
const eventType = body.eventType; | ||
const eventName = eventType.split(".")[0]; | ||
|
||
this.http.respond({ | ||
status: 200, | ||
body: "Success", | ||
}); | ||
} catch (error) { | ||
this.http.respond({ | ||
status: 500, | ||
body: "Internal Server Error", | ||
}); | ||
console.error(`Error processing ${actionType} action:`, error); | ||
} | ||
this.$emit(body, { | ||
id: `${body.objectMetadata.id}-${body.eventDate}`, | ||
summary: `New ${body.objectMetadata.nameSingular} ${eventName}d with Id: ${body.objectMetadata.id}.`, | ||
ts: Date.parse(body.eventDate) || Date.now(), | ||
}); | ||
}, | ||
sampleEmit, | ||
}; |
61 changes: 61 additions & 0 deletions
61
components/twenty/sources/new-record-instant/test-event.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
export default { | ||
"targetUrl": "http://webhook.url", | ||
"eventType": "*.*", | ||
"objectMetadata": { | ||
"id": "12345678-1234-1234-1234-123456789012", | ||
"nameSingular": "company" | ||
}, | ||
"workspaceId": "12345678-1234-1234-1234-123456789012", | ||
"webhookId": "12345678-1234-1234-1234-123456789012", | ||
"eventDate": "2024-05-07T14:16:39.810Z", | ||
"record": { | ||
"id": "12345678-1234-1234-1234-123456789012", | ||
"name": "company test", | ||
"people": { | ||
"edges": [], | ||
"__typename": "personConnection" | ||
}, | ||
"address": "", | ||
"position": 1, | ||
"createdAt": "2024-05-07T14:16:39.350276+00:00", | ||
"employees": null, | ||
"favorites": { | ||
"edges": [], | ||
"__typename": "favoriteConnection" | ||
}, | ||
"updatedAt": "2024-05-07T14:16:39.350276+00:00", | ||
"__typename": "company", | ||
"domainName": "", | ||
"attachments": { | ||
"edges": [], | ||
"__typename": "attachmentConnection" | ||
}, | ||
"accountOwner": null, | ||
"opportunities": { | ||
"edges": [], | ||
"__typename": "opportunityConnection" | ||
}, | ||
"accountOwnerId": null, | ||
"activityTargets": { | ||
"edges": [], | ||
"__typename": "activityTargetConnection" | ||
}, | ||
"timelineActivities": { | ||
"edges": [], | ||
"__typename": "timelineActivityConnection" | ||
}, | ||
"idealCustomerProfile": false, | ||
"xLink": { | ||
"url": "", | ||
"label": "" | ||
}, | ||
"linkedinLink": { | ||
"url": "", | ||
"label": "" | ||
}, | ||
"annualRecurringRevenue": { | ||
"amountMicros": null, | ||
"currencyCode": "" | ||
} | ||
} | ||
} |
Oops, something went wrong.