-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[Components] Drift. Actions + Sources #16553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 8 commits
29ac629
21af602
00d7d45
c14d5e4
466aa07
f888650
6f9160a
87d0c6f
097ff38
dd9dcbd
992792a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,87 @@ | ||||||
import drift from "../../drift.app.mjs"; | ||||||
import { removeNullEntries } from "../../common/utils.mjs"; | ||||||
|
||||||
export default { | ||||||
key: "drift-create-contact", | ||||||
name: "Create Contact", | ||||||
description: "Creates a contact in Drift. [See the docs](https://devdocs.drift.com/docs/creating-a-contact).", | ||||||
version: "0.0.1", | ||||||
type: "action", | ||||||
props: { | ||||||
drift, | ||||||
email: { | ||||||
type: "string", | ||||||
label: "Email", | ||||||
description: "The contact's email address", | ||||||
}, | ||||||
name: { | ||||||
type: "string", | ||||||
label: "Name", | ||||||
description: "The contact's full name", | ||||||
optional: true, | ||||||
}, | ||||||
phone: { | ||||||
type: "string", | ||||||
label: "Phone", | ||||||
description: "The contact's phone number", | ||||||
optional: true, | ||||||
}, | ||||||
source: { | ||||||
type: "string", | ||||||
label: "Lead Source", | ||||||
description: "The value of the 'lead_create_source' custom attribute to match (case-sensitive).", | ||||||
optional: true, | ||||||
}, | ||||||
customAttributes: { | ||||||
type: "object", | ||||||
label: "Custom Attributes", | ||||||
description: "Additional custom attributes to store on the contact", | ||||||
optional: true, | ||||||
}, | ||||||
}, | ||||||
|
||||||
async run({ $ }) { | ||||||
|
||||||
const warnings = []; | ||||||
|
||||||
const { | ||||||
drift, email, name, phone, source, | ||||||
} = this; | ||||||
|
||||||
warnings.push(...drift.checkIfEmailValid(email)); | ||||||
|
||||||
const customAttributes = drift.parseIfJSONString(this.customAttributes); | ||||||
|
||||||
const attributes = removeNullEntries({ | ||||||
email, | ||||||
name, | ||||||
phone, | ||||||
source, | ||||||
...customAttributes, | ||||||
}); | ||||||
|
||||||
const existingContact = await drift.getContactByEmail({ | ||||||
$, | ||||||
params: { | ||||||
email, | ||||||
}, | ||||||
}); | ||||||
|
||||||
if (existingContact && existingContact.data.length > 0) { | ||||||
throw new Error (`Contact ${email} already exists`); | ||||||
}; | ||||||
|
||||||
const response = await drift.createContact({ | ||||||
$, | ||||||
data: { | ||||||
attributes, | ||||||
}, | ||||||
}); | ||||||
|
||||||
console.log(response.data.id); | ||||||
Comment on lines
+76
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
$.export("$summary", `Contact ${email} created.` + warnings.join("\n- ")); | ||||||
return response; | ||||||
}, | ||||||
}; | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,45 @@ | ||||||
import drift from "../../drift.app.mjs"; | ||||||
|
||||||
export default { | ||||||
key: "drift-delete-contact", | ||||||
name: "Delete Contact", | ||||||
description: "Deletes a contact in Drift by ID or email. [See the docs](https://devdocs.drift.com/docs/removing-a-contact).", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
version: "0.0.17", | ||||||
type: "action", | ||||||
props: { | ||||||
drift, | ||||||
emailOrId: { | ||||||
type: "string", | ||||||
label: "Email or Id", | ||||||
description: "The contact's email address or ID", | ||||||
}, | ||||||
}, | ||||||
|
||||||
async run({ $ }) { | ||||||
|
||||||
const warnings = []; | ||||||
|
||||||
const { drift } = this; | ||||||
|
||||||
const emailOrId = drift.trimIfString(this.emailOrId); | ||||||
|
||||||
warnings.push(...drift.checkEmailOrId(emailOrId)); | ||||||
|
||||||
let contact = await drift.getContactByEmailOrId($, emailOrId); | ||||||
contact = contact.data[0] || contact.data; | ||||||
|
||||||
const contactId = contact.id; | ||||||
const contactEmail = contact.attributes.email; | ||||||
|
||||||
const response = await drift.deleteContactById({ | ||||||
$, | ||||||
contactId, | ||||||
}); | ||||||
|
||||||
$.export("$summary", `Contact ${contactEmail} ID "${contactId}" deleted successfully.` + | ||||||
warnings.join("\n- ")); | ||||||
|
||||||
return response; | ||||||
}, | ||||||
}; | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,41 @@ | ||||||
import drift from "../../drift.app.mjs"; | ||||||
|
||||||
export default { | ||||||
key: "drift-get-contact", | ||||||
name: "Get Contact", | ||||||
description: "Retrieves a contact in Drift by ID or email. [See the docs](https://devdocs.drift.com/docs/retrieving-contact)", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
version: "0.0.1", | ||||||
type: "action", | ||||||
props: { | ||||||
drift, | ||||||
emailOrId: { | ||||||
type: "string", | ||||||
label: "Email or Id", | ||||||
description: "The contact's email address or ID", | ||||||
}, | ||||||
}, | ||||||
|
||||||
async run({ $ }) { | ||||||
|
||||||
const warnings = []; | ||||||
|
||||||
const { drift } = this; | ||||||
|
||||||
const emailOrId = drift.trimIfString(this.emailOrId); | ||||||
|
||||||
warnings.push(...drift.checkEmailOrId(emailOrId)); | ||||||
|
||||||
const response = await drift.getContactByEmailOrId($, emailOrId); | ||||||
|
||||||
const contact = response.data[0] || response.data; | ||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
if (!contact) { | ||||||
throw new Error("Failed to get contact"); | ||||||
}; | ||||||
|
||||||
$.export("$summary", `Contact ${contact.attributes.email} ID "${contact.id}"` | ||||||
+ " fetched successfully." + warnings.join("\n- ")); | ||||||
|
||||||
return contact; | ||||||
}, | ||||||
}; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,90 @@ | ||||||
import drift from "../../drift.app.mjs"; | ||||||
import { removeNullEntries } from "../../common/utils.mjs"; | ||||||
|
||||||
export default { | ||||||
key: "drift-update-contact", | ||||||
name: "Update Contact", | ||||||
description: "Updates a contact in Drift using ID or email. Only changed attributes will be updated. [See Drift API docs](https://devdocs.drift.com/docs/updating-a-contact)", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
version: "0.0.9", | ||||||
type: "action", | ||||||
props: { | ||||||
drift, | ||||||
emailOrId: { | ||||||
type: "string", | ||||||
label: "Email or ID", | ||||||
description: "The contact’s email address or numeric ID.", | ||||||
}, | ||||||
email: { | ||||||
type: "string", | ||||||
label: "Email", | ||||||
description: "The contact’s email address", | ||||||
optional: true, | ||||||
}, | ||||||
name: { | ||||||
type: "string", | ||||||
label: "Name", | ||||||
description: "The contact’s name.", | ||||||
optional: true, | ||||||
}, | ||||||
phone: { | ||||||
type: "string", | ||||||
label: "Phone", | ||||||
description: "The contact’s phone number.", | ||||||
optional: true, | ||||||
}, | ||||||
source: { | ||||||
type: "string", | ||||||
label: "Lead Source", | ||||||
description: "The value of the 'lead_create_source' custom attribute to match (case-sensitive).", | ||||||
optional: true, | ||||||
}, | ||||||
SokolovskyiK marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
customAttributes: { | ||||||
type: "object", | ||||||
label: "Custom Attributes", | ||||||
description: "Any custom attributes to update (e.g. company, job title, etc).", | ||||||
optional: true, | ||||||
}, | ||||||
}, | ||||||
|
||||||
async run({ $ }) { | ||||||
const warnings = []; | ||||||
const { | ||||||
drift, name, email, phone, source, | ||||||
} = this; | ||||||
|
||||||
const customAttributes = drift.parseIfJSONString(this.customAttributes); | ||||||
|
||||||
const attributes = removeNullEntries({ | ||||||
name, | ||||||
phone, | ||||||
email, | ||||||
source, | ||||||
...customAttributes, | ||||||
}); | ||||||
|
||||||
if (!Object.keys(attributes).length) { | ||||||
throw new Error("No attributes provided to update."); | ||||||
}; | ||||||
|
||||||
const emailOrId = drift.trimIfString(this.emailOrId); | ||||||
|
||||||
warnings.push(...drift.checkEmailOrId(emailOrId)); | ||||||
warnings.push(...drift.checkIfEmailValid(email)); | ||||||
|
||||||
let contact = await drift.getContactByEmailOrId($, emailOrId); | ||||||
SokolovskyiK marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
const contactId = contact.data[0]?.id || contact.data.id; | ||||||
|
||||||
const response = await drift.updateContact({ | ||||||
$, | ||||||
contactId, | ||||||
data: { | ||||||
attributes, | ||||||
}, | ||||||
}); | ||||||
|
||||||
$.export("$summary", `Contact ID ${contactId} updated successfully.` + warnings.join("\n- ")); | ||||||
return response; | ||||||
}, | ||||||
}; | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.