-
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.
Browse files
Browse the repository at this point in the history
* [ACTION] Intercom Upsert Contact #14268 Actions - Upsert Contact * Update components/intercom/actions/upsert-contact/upsert-contact.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update components/intercom/actions/upsert-contact/upsert-contact.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update components/intercom/actions/upsert-contact/upsert-contact.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
- Loading branch information
1 parent
8fd30ef
commit 02197b3
Showing
21 changed files
with
192 additions
and
29 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
131 changes: 131 additions & 0 deletions
131
components/intercom/actions/upsert-contact/upsert-contact.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,131 @@ | ||
import { ROLE_OPTIONS } from "../../common/constants.mjs"; | ||
import intercom from "../../intercom.app.mjs"; | ||
|
||
export default { | ||
key: "intercom-upsert-contact", | ||
name: "Upsert Contact", | ||
description: "Create a new contact. If there is already a contact with the email provided, the existing contact will be updated. [See the docs here](https://developers.intercom.com/docs/references/rest-api/api.intercom.io/contacts/createcontact)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
intercom, | ||
email: { | ||
type: "string", | ||
label: "Email", | ||
description: "The contact's email.", | ||
}, | ||
role: { | ||
type: "string", | ||
label: "Role", | ||
description: "The role of the contact.", | ||
options: ROLE_OPTIONS, | ||
optional: true, | ||
}, | ||
externalId: { | ||
type: "string", | ||
label: "External Id", | ||
description: "A unique identifier for the contact which is given to Intercom.", | ||
optional: true, | ||
}, | ||
phone: { | ||
type: "string", | ||
label: "Phone", | ||
description: "The contact's phone number.", | ||
optional: true, | ||
}, | ||
name: { | ||
type: "string", | ||
label: "Name", | ||
description: "The contact's name.", | ||
optional: true, | ||
}, | ||
avatar: { | ||
type: "string", | ||
label: "Avatar", | ||
description: "An image URL containing the avatar of a contact.", | ||
optional: true, | ||
}, | ||
unsubscribedFromEmails: { | ||
type: "boolean", | ||
label: "Unsubscribed From Emails", | ||
description: "Whether the contact is unsubscribed from emails.", | ||
optional: true, | ||
}, | ||
customAttributes: { | ||
type: "object", | ||
label: "Custom Attributes", | ||
description: "The custom attributes which are set for the contact.", | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
let response = {}; | ||
let requestType = "created"; | ||
let data = { | ||
email: this.email, | ||
role: this.role, | ||
externalId: this.externalId, | ||
phone: this.phone, | ||
name: this.name, | ||
avatar: this.avatar, | ||
unsubscribedFromEmails: this.unsubscribedFromEmails, | ||
customAttributes: this.customAttributes, | ||
}; | ||
|
||
data = Object.entries(data).filter(([ | ||
, | ||
value, | ||
]) => (value != "" && value != undefined)) | ||
.reduce((obj, [ | ||
key, | ||
value, | ||
]) => Object.assign(obj, { | ||
[key]: value, | ||
}), {}); | ||
|
||
const { | ||
data: contact, total_count: total, | ||
} = await this.intercom.searchContact({ | ||
data: { | ||
query: { | ||
operator: "AND", | ||
value: [ | ||
{ | ||
field: "email", | ||
operator: "=", | ||
value: this.email, | ||
}, | ||
], | ||
}, | ||
pagination: { | ||
per_page: 1, | ||
}, | ||
}, | ||
}); | ||
|
||
if (total) { | ||
const { | ||
id: contactId, | ||
// eslint-disable-next-line no-unused-vars | ||
owner_id, | ||
...contactInfos | ||
} = contact[0]; | ||
response = await this.intercom.updateContact({ | ||
$, | ||
contactId, | ||
data: { | ||
...contactInfos, | ||
...data, | ||
}, | ||
}); | ||
requestType = "updated"; | ||
} else { | ||
response = await this.intercom.createContact({ | ||
$, | ||
data, | ||
}); | ||
} | ||
$.export("$summary", `Successfully ${requestType} contact with ID ${response.id}`); | ||
return response; | ||
}, | ||
}; |
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,10 @@ | ||
export const ROLE_OPTIONS = [ | ||
{ | ||
label: "User", | ||
value: "user", | ||
}, | ||
{ | ||
label: "Lead", | ||
value: "lead", | ||
}, | ||
]; |
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
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
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
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
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
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
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
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
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