Skip to content

Commit 7c175d7

Browse files
authored
[Components] intercom - new components (#15292)
1 parent 87c3440 commit 7c175d7

File tree

25 files changed

+557
-26
lines changed

25 files changed

+557
-26
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import intercom from "../../intercom.app.mjs";
2+
3+
export default {
4+
key: "intercom-add-tag-to-contact",
5+
name: "Add Tag To Contact",
6+
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).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
intercom,
11+
contactId: {
12+
type: "string",
13+
label: "Contact ID",
14+
description: "The unique identifier for the contact which is given by Intercom. Eg. `63a07ddf05a32042dffac965`.",
15+
propDefinition: [
16+
intercom,
17+
"userIds",
18+
() => ({
19+
data: {
20+
query: {
21+
operator: "OR",
22+
value: [
23+
{
24+
field: "role",
25+
operator: "=",
26+
value: "user",
27+
},
28+
{
29+
field: "role",
30+
operator: "=",
31+
value: "lead",
32+
},
33+
],
34+
},
35+
},
36+
}),
37+
],
38+
},
39+
tagId: {
40+
propDefinition: [
41+
intercom,
42+
"tagId",
43+
],
44+
},
45+
},
46+
methods: {
47+
addTagToContact({
48+
contactId, ...args
49+
} = {}) {
50+
return this.intercom.makeRequest({
51+
method: "POST",
52+
endpoint: `contacts/${contactId}/tags`,
53+
...args,
54+
});
55+
},
56+
},
57+
async run({ $ }) {
58+
const {
59+
addTagToContact,
60+
contactId,
61+
tagId,
62+
} = this;
63+
64+
const response = await addTagToContact({
65+
$,
66+
contactId,
67+
data: {
68+
id: tagId,
69+
},
70+
});
71+
72+
$.export("$summary", `Successfully added tag to contact with ID \`${response.id}\`.`);
73+
return response;
74+
},
75+
};

components/intercom/actions/create-note/create-note.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "intercom-create-note",
55
name: "Create Note",
66
description: "Creates a note for a specific user. [See the docs here](https://developers.intercom.com/intercom-api-reference/reference/create-note-for-contact)",
7-
version: "0.0.4",
7+
version: "0.0.5",
88
type: "action",
99
props: {
1010
intercom,
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
import intercom from "../../intercom.app.mjs";
2+
3+
export default {
4+
key: "intercom-reply-to-conversation",
5+
name: "Reply To Conversation",
6+
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).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
intercom,
11+
conversationId: {
12+
propDefinition: [
13+
intercom,
14+
"conversationId",
15+
],
16+
},
17+
replyType: {
18+
type: "string",
19+
label: "Reply Type",
20+
description: "The type of the reply.",
21+
options: [
22+
{
23+
label: "Contact Reply",
24+
value: "user",
25+
},
26+
{
27+
label: "Admin Reply",
28+
value: "admin",
29+
},
30+
],
31+
reloadProps: true,
32+
},
33+
messageType: {
34+
propDefinition: [
35+
intercom,
36+
"messageType",
37+
({ replyType: type }) => ({
38+
type,
39+
}),
40+
],
41+
},
42+
body: {
43+
type: "string",
44+
label: "Body",
45+
description: "The text body of the comment.",
46+
},
47+
attachmentUrls: {
48+
type: "string[]",
49+
label: "Attachment URLs",
50+
description: "A list of image URLs that will be added as attachments. You can include up to 10 URLs.",
51+
optional: true,
52+
},
53+
},
54+
additionalProps() {
55+
const {
56+
replyType,
57+
replyOnBehalfOf,
58+
} = this;
59+
60+
if (replyType === "admin") {
61+
return {
62+
adminId: {
63+
type: "string",
64+
label: "Admin ID",
65+
description: "The id of the admin who is authoring the comment.",
66+
options: async () => {
67+
const { admins } = await this.intercom.listAdmins();
68+
return admins.map((admin) => ({
69+
label: admin.name,
70+
value: admin.id,
71+
}));
72+
},
73+
},
74+
};
75+
}
76+
77+
return {
78+
replyOnBehalfOf: {
79+
type: "string",
80+
label: "Reply On Behalf Of",
81+
description: "The user ID of the user on whose behalf the reply is being made.",
82+
options: [
83+
{
84+
label: "Intercom User ID",
85+
value: "intercom_user_id",
86+
},
87+
{
88+
label: "Email",
89+
value: "email",
90+
},
91+
{
92+
label: "User ID",
93+
value: "user_id",
94+
},
95+
],
96+
reloadProps: true,
97+
},
98+
...(replyOnBehalfOf === "intercom_user_id" && {
99+
intercomUserId: {
100+
type: "string",
101+
label: "Intercom User ID",
102+
description: "The identifier for the contact as given by Intercom.",
103+
options: async () => {
104+
const results = await this.intercom.searchContacts({
105+
query: {
106+
field: "role",
107+
operator: "=",
108+
value: "user",
109+
},
110+
});
111+
return results.map((user) => ({
112+
label: user.name || user.id,
113+
value: user.id,
114+
}));
115+
},
116+
},
117+
}),
118+
...(replyOnBehalfOf === "email" && {
119+
email: {
120+
type: "string",
121+
label: "Email",
122+
description: "The email you have defined for the user.",
123+
options: async () => {
124+
const results = await this.intercom.searchContacts({
125+
query: {
126+
field: "role",
127+
operator: "=",
128+
value: "user",
129+
},
130+
});
131+
return results.map((user) => ({
132+
label: user.name || user.id,
133+
value: user.email,
134+
}));
135+
},
136+
},
137+
}),
138+
...(replyOnBehalfOf === "user_id" && {
139+
userId: {
140+
type: "string",
141+
label: "User ID",
142+
description: "The external ID you have defined for the contact.",
143+
options: async () => {
144+
const results = await this.intercom.searchContacts({
145+
query: {
146+
field: "role",
147+
operator: "=",
148+
value: "user",
149+
},
150+
});
151+
return results.map((user) => ({
152+
label: user.name || user.id,
153+
value: user.external_id,
154+
}));
155+
},
156+
},
157+
}),
158+
};
159+
},
160+
methods: {
161+
replyToConversation({
162+
conversationId, ...args
163+
} = {}) {
164+
return this.intercom.makeRequest({
165+
method: "POST",
166+
endpoint: `conversations/${conversationId}/parts`,
167+
...args,
168+
});
169+
},
170+
},
171+
async run({ $ }) {
172+
const {
173+
replyToConversation,
174+
conversationId,
175+
body,
176+
attachmentUrls,
177+
replyType,
178+
adminId,
179+
intercomUserId,
180+
email,
181+
userId,
182+
messageType,
183+
} = this;
184+
185+
const response = await replyToConversation({
186+
$,
187+
conversationId,
188+
data: {
189+
body,
190+
attachment_urls: attachmentUrls,
191+
admin_id: adminId,
192+
intercom_user_id: intercomUserId,
193+
email,
194+
user_id: userId,
195+
message_type: messageType,
196+
type: replyType,
197+
},
198+
});
199+
200+
$.export("$summary", "Reply or note added successfully");
201+
return response;
202+
},
203+
};

components/intercom/actions/send-incoming-message/send-incoming-message.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "intercom-send-incoming-message",
55
name: "Send Incoming Message",
66
description: "Send a message from a user into your Intercom app. [See the docs here](https://developers.intercom.com/intercom-api-reference/reference/create-a-conversation)",
7-
version: "0.0.4",
7+
version: "0.0.5",
88
type: "action",
99
props: {
1010
intercom,

0 commit comments

Comments
 (0)