Skip to content

Commit b6e4ac2

Browse files
authored
New Components - kustomer (#15989)
* kustomer init * [Components] kustomer #15920 Sources - New Conversation (Instant) - New Customer (Instant) - New Message (Instant) - Updated Conversation (Instant) - Updated Customer (Instant) Actions - Create Conversation - Update Conversation - Create Customer - Update Customer * pnpm update * fix error validation
1 parent 3aea15a commit b6e4ac2

File tree

20 files changed

+2434
-8
lines changed

20 files changed

+2434
-8
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import {
2+
parseObject, throwError,
3+
} from "../../common/utils.mjs";
4+
import kustomer from "../../kustomer.app.mjs";
5+
6+
export default {
7+
key: "kustomer-create-conversation",
8+
name: "Create Conversation",
9+
description: "Creates a new conversation in Kustomer. [See the documentation](https://developer.kustomer.com/kustomer-api-docs/reference/createaconversation)",
10+
version: "0.0.1",
11+
type: "action",
12+
props: {
13+
kustomer,
14+
customer: {
15+
propDefinition: [
16+
kustomer,
17+
"customerId",
18+
],
19+
},
20+
externalId: {
21+
propDefinition: [
22+
kustomer,
23+
"externalId",
24+
],
25+
optional: true,
26+
},
27+
name: {
28+
propDefinition: [
29+
kustomer,
30+
"name",
31+
],
32+
description: "Name of the conversation",
33+
optional: true,
34+
},
35+
status: {
36+
propDefinition: [
37+
kustomer,
38+
"status",
39+
],
40+
optional: true,
41+
},
42+
priority: {
43+
propDefinition: [
44+
kustomer,
45+
"priority",
46+
],
47+
optional: true,
48+
},
49+
direction: {
50+
propDefinition: [
51+
kustomer,
52+
"direction",
53+
],
54+
optional: true,
55+
},
56+
tags: {
57+
propDefinition: [
58+
kustomer,
59+
"tags",
60+
],
61+
optional: true,
62+
},
63+
assignedUsers: {
64+
propDefinition: [
65+
kustomer,
66+
"assignedUsers",
67+
],
68+
optional: true,
69+
},
70+
assignedTeams: {
71+
propDefinition: [
72+
kustomer,
73+
"assignedTeams",
74+
],
75+
optional: true,
76+
},
77+
defaultLang: {
78+
propDefinition: [
79+
kustomer,
80+
"defaultLang",
81+
],
82+
description: "Default language for the conversation",
83+
optional: true,
84+
},
85+
queueId: {
86+
propDefinition: [
87+
kustomer,
88+
"queueId",
89+
],
90+
},
91+
},
92+
async run({ $ }) {
93+
try {
94+
const response = await this.kustomer.createConversation({
95+
$,
96+
data: {
97+
customer: this.customer,
98+
externalId: this.externalId,
99+
name: this.name,
100+
status: this.status,
101+
priority: this.priority,
102+
direction: this.direction,
103+
tags: parseObject(this.tags),
104+
assignedUsers: parseObject(this.assignedUsers),
105+
assignedTeams: parseObject(this.assignedTeams),
106+
defaultLang: this.defaultLang,
107+
queue: {
108+
id: this.queueId,
109+
},
110+
},
111+
});
112+
113+
$.export("$summary", `Created conversation with ID ${response.data.id}`);
114+
return response;
115+
} catch ({ message }) {
116+
throwError(message);
117+
}
118+
},
119+
};
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
import {
2+
parseObject, throwError,
3+
} from "../../common/utils.mjs";
4+
import kustomer from "../../kustomer.app.mjs";
5+
6+
export default {
7+
key: "kustomer-create-customer",
8+
name: "Create Customer",
9+
description: "Creates a new customer in Kustomer. [See the documentation](https://developer.kustomer.com/kustomer-api-docs/reference/createacustomer)",
10+
version: "0.0.1",
11+
type: "action",
12+
props: {
13+
kustomer,
14+
name: {
15+
propDefinition: [
16+
kustomer,
17+
"name",
18+
],
19+
optional: true,
20+
},
21+
company: {
22+
propDefinition: [
23+
kustomer,
24+
"company",
25+
],
26+
optional: true,
27+
},
28+
externalId: {
29+
propDefinition: [
30+
kustomer,
31+
"externalId",
32+
],
33+
optional: true,
34+
},
35+
username: {
36+
propDefinition: [
37+
kustomer,
38+
"username",
39+
],
40+
optional: true,
41+
},
42+
avatarUrl: {
43+
propDefinition: [
44+
kustomer,
45+
"avatarUrl",
46+
],
47+
optional: true,
48+
},
49+
externalIds: {
50+
propDefinition: [
51+
kustomer,
52+
"externalIds",
53+
],
54+
optional: true,
55+
},
56+
sharedExternalIds: {
57+
propDefinition: [
58+
kustomer,
59+
"sharedExternalIds",
60+
],
61+
optional: true,
62+
},
63+
emails: {
64+
propDefinition: [
65+
kustomer,
66+
"emails",
67+
],
68+
optional: true,
69+
},
70+
sharedEmails: {
71+
propDefinition: [
72+
kustomer,
73+
"sharedEmails",
74+
],
75+
optional: true,
76+
},
77+
phones: {
78+
propDefinition: [
79+
kustomer,
80+
"phones",
81+
],
82+
optional: true,
83+
},
84+
sharedPhones: {
85+
propDefinition: [
86+
kustomer,
87+
"sharedPhones",
88+
],
89+
optional: true,
90+
},
91+
whatsApps: {
92+
propDefinition: [
93+
kustomer,
94+
"whatsApps",
95+
],
96+
optional: true,
97+
},
98+
urls: {
99+
propDefinition: [
100+
kustomer,
101+
"urls",
102+
],
103+
optional: true,
104+
},
105+
tags: {
106+
propDefinition: [
107+
kustomer,
108+
"tags",
109+
],
110+
optional: true,
111+
},
112+
sentimentPolarity: {
113+
propDefinition: [
114+
kustomer,
115+
"sentimentPolarity",
116+
],
117+
optional: true,
118+
},
119+
sentimentConfidence: {
120+
propDefinition: [
121+
kustomer,
122+
"sentimentConfidence",
123+
],
124+
optional: true,
125+
},
126+
birthdayAt: {
127+
propDefinition: [
128+
kustomer,
129+
"birthdayAt",
130+
],
131+
optional: true,
132+
},
133+
gender: {
134+
propDefinition: [
135+
kustomer,
136+
"gender",
137+
],
138+
optional: true,
139+
},
140+
defaultLang: {
141+
propDefinition: [
142+
kustomer,
143+
"defaultLang",
144+
],
145+
optional: true,
146+
},
147+
},
148+
async run({ $ }) {
149+
try {
150+
const sentiment = {};
151+
if (this.sentimentConfidence) sentiment.confidence = parseInt(this.sentimentConfidence);
152+
if (this.sentimentPolarity) sentiment.polarity = parseInt(this.sentimentPolarity);
153+
154+
const response = await this.kustomer.createCustomer({
155+
$,
156+
data: {
157+
name: this.name,
158+
company: this.company,
159+
externalId: this.externalId,
160+
username: this.username,
161+
avatarUrl: this.avatarUrl,
162+
externalIds: parseObject(this.externalIds)?.map((id) => ({
163+
externalId: id,
164+
})),
165+
sharedExternalIds: parseObject(this.sharedExternalIds)?.map((id) => ({
166+
externalId: id,
167+
})),
168+
emails: parseObject(this.emails)?.map((email) => ({
169+
email,
170+
})),
171+
sharedEmails: parseObject(this.sharedEmails)?.map((email) => ({
172+
email,
173+
})),
174+
phones: parseObject(this.phones)?.map((phone) => ({
175+
phone: `${phone}`,
176+
})),
177+
sharedPhones: parseObject(this.sharedPhones)?.map((phone) => ({
178+
phone: `${phone}`,
179+
})),
180+
whatsapps: parseObject(this.whatsApps)?.map((phone) => ({
181+
phone: `${phone}`,
182+
})),
183+
urls: parseObject(this.urls)?.map((url) => ({
184+
url,
185+
})),
186+
tags: parseObject(this.tags),
187+
sentiment: Object.entries(sentiment).length
188+
? sentiment
189+
: undefined,
190+
birthdayAt: this.birthdayAt,
191+
gender: this.gender,
192+
createdAt: this.createdAt,
193+
importedAt: this.importedAt,
194+
defaultLang: this.defaultLang,
195+
},
196+
});
197+
$.export("$summary", `Created customer with ID ${response.data.id}`);
198+
return response;
199+
} catch ({ message }) {
200+
throwError(message);
201+
}
202+
},
203+
};

0 commit comments

Comments
 (0)