-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[Components] intercom - new components #15292
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
components/intercom/actions/add-tag-to-contact/add-tag-to-contact.mjs
This file contains hidden or 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,75 @@ | ||
import intercom from "../../intercom.app.mjs"; | ||
|
||
export default { | ||
key: "intercom-add-tag-to-contact", | ||
name: "Add Tag To Contact", | ||
description: "Adds a specific tag to a contact in Intercom. [See the documentation](https://developers.intercom.com/docs/references/rest-api/api.intercom.io/contacts/attachtagtocontact).", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
intercom, | ||
contactId: { | ||
type: "string", | ||
label: "Contact ID", | ||
description: "The unique identifier for the contact which is given by Intercom. Eg. `63a07ddf05a32042dffac965`.", | ||
propDefinition: [ | ||
intercom, | ||
"userIds", | ||
() => ({ | ||
data: { | ||
query: { | ||
operator: "OR", | ||
value: [ | ||
{ | ||
field: "role", | ||
operator: "=", | ||
value: "user", | ||
}, | ||
{ | ||
field: "role", | ||
operator: "=", | ||
value: "lead", | ||
}, | ||
], | ||
}, | ||
}, | ||
}), | ||
], | ||
}, | ||
tagId: { | ||
propDefinition: [ | ||
intercom, | ||
"tagId", | ||
], | ||
}, | ||
}, | ||
methods: { | ||
addTagToContact({ | ||
contactId, ...args | ||
} = {}) { | ||
return this.intercom.makeRequest({ | ||
method: "POST", | ||
endpoint: `contacts/${contactId}/tags`, | ||
...args, | ||
}); | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const { | ||
addTagToContact, | ||
contactId, | ||
tagId, | ||
} = this; | ||
|
||
const response = await addTagToContact({ | ||
$, | ||
contactId, | ||
data: { | ||
id: tagId, | ||
}, | ||
}); | ||
|
||
$.export("$summary", `Successfully added tag to contact with ID \`${response.id}\`.`); | ||
return response; | ||
}, | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; |
This file contains hidden or 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
203 changes: 203 additions & 0 deletions
203
components/intercom/actions/reply-to-conversation/reply-to-conversation.mjs
This file contains hidden or 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,203 @@ | ||
import intercom from "../../intercom.app.mjs"; | ||
|
||
export default { | ||
key: "intercom-reply-to-conversation", | ||
name: "Reply To Conversation", | ||
description: "Add a reply or a note to an existing conversation thread. [See the documentation](https://developers.intercom.com/docs/references/rest-api/api.intercom.io/conversations/replyconversation).", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
intercom, | ||
conversationId: { | ||
propDefinition: [ | ||
intercom, | ||
"conversationId", | ||
], | ||
}, | ||
replyType: { | ||
type: "string", | ||
label: "Reply Type", | ||
description: "The type of the reply.", | ||
options: [ | ||
{ | ||
label: "Contact Reply", | ||
value: "user", | ||
}, | ||
{ | ||
label: "Admin Reply", | ||
value: "admin", | ||
}, | ||
], | ||
reloadProps: true, | ||
}, | ||
messageType: { | ||
propDefinition: [ | ||
intercom, | ||
"messageType", | ||
({ replyType: type }) => ({ | ||
type, | ||
}), | ||
], | ||
}, | ||
body: { | ||
type: "string", | ||
label: "Body", | ||
description: "The text body of the comment.", | ||
}, | ||
attachmentUrls: { | ||
type: "string[]", | ||
label: "Attachment URLs", | ||
description: "A list of image URLs that will be added as attachments. You can include up to 10 URLs.", | ||
optional: true, | ||
}, | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
additionalProps() { | ||
const { | ||
replyType, | ||
replyOnBehalfOf, | ||
} = this; | ||
|
||
if (replyType === "admin") { | ||
return { | ||
adminId: { | ||
type: "string", | ||
label: "Admin ID", | ||
description: "The id of the admin who is authoring the comment.", | ||
options: async () => { | ||
const { admins } = await this.intercom.listAdmins(); | ||
return admins.map((admin) => ({ | ||
label: admin.name, | ||
value: admin.id, | ||
})); | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
return { | ||
replyOnBehalfOf: { | ||
type: "string", | ||
label: "Reply On Behalf Of", | ||
description: "The user ID of the user on whose behalf the reply is being made.", | ||
options: [ | ||
{ | ||
label: "Intercom User ID", | ||
value: "intercom_user_id", | ||
}, | ||
{ | ||
label: "Email", | ||
value: "email", | ||
}, | ||
{ | ||
label: "User ID", | ||
value: "user_id", | ||
}, | ||
], | ||
reloadProps: true, | ||
}, | ||
...(replyOnBehalfOf === "intercom_user_id" && { | ||
intercomUserId: { | ||
type: "string", | ||
label: "Intercom User ID", | ||
description: "The identifier for the contact as given by Intercom.", | ||
options: async () => { | ||
const results = await this.intercom.searchContacts({ | ||
query: { | ||
field: "role", | ||
operator: "=", | ||
value: "user", | ||
}, | ||
}); | ||
return results.map((user) => ({ | ||
label: user.name || user.id, | ||
value: user.id, | ||
})); | ||
}, | ||
}, | ||
}), | ||
...(replyOnBehalfOf === "email" && { | ||
email: { | ||
type: "string", | ||
label: "Email", | ||
description: "The email you have defined for the user.", | ||
options: async () => { | ||
const results = await this.intercom.searchContacts({ | ||
query: { | ||
field: "role", | ||
operator: "=", | ||
value: "user", | ||
}, | ||
}); | ||
return results.map((user) => ({ | ||
label: user.name || user.id, | ||
value: user.email, | ||
})); | ||
}, | ||
}, | ||
}), | ||
...(replyOnBehalfOf === "user_id" && { | ||
userId: { | ||
type: "string", | ||
label: "User ID", | ||
description: "The external ID you have defined for the contact.", | ||
options: async () => { | ||
const results = await this.intercom.searchContacts({ | ||
query: { | ||
field: "role", | ||
operator: "=", | ||
value: "user", | ||
}, | ||
}); | ||
return results.map((user) => ({ | ||
label: user.name || user.id, | ||
value: user.external_id, | ||
})); | ||
}, | ||
}, | ||
}), | ||
}; | ||
}, | ||
methods: { | ||
replyToConversation({ | ||
conversationId, ...args | ||
} = {}) { | ||
return this.intercom.makeRequest({ | ||
method: "POST", | ||
endpoint: `conversations/${conversationId}/parts`, | ||
...args, | ||
}); | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const { | ||
replyToConversation, | ||
conversationId, | ||
body, | ||
attachmentUrls, | ||
replyType, | ||
adminId, | ||
intercomUserId, | ||
email, | ||
userId, | ||
messageType, | ||
} = this; | ||
|
||
const response = await replyToConversation({ | ||
$, | ||
conversationId, | ||
data: { | ||
body, | ||
attachment_urls: attachmentUrls, | ||
admin_id: adminId, | ||
intercom_user_id: intercomUserId, | ||
email, | ||
user_id: userId, | ||
message_type: messageType, | ||
type: replyType, | ||
}, | ||
}); | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
$.export("$summary", "Reply or note added successfully"); | ||
return response; | ||
}, | ||
}; |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.