Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import {
parseObject, throwError,
} from "../../common/utils.mjs";
import kustomer from "../../kustomer.app.mjs";

export default {
key: "kustomer-create-conversation",
name: "Create Conversation",
description: "Creates a new conversation in Kustomer. [See the documentation](https://developer.kustomer.com/kustomer-api-docs/reference/createaconversation)",
version: "0.0.1",
type: "action",
props: {
kustomer,
customer: {
propDefinition: [
kustomer,
"customerId",
],
},
externalId: {
propDefinition: [
kustomer,
"externalId",
],
optional: true,
},
name: {
propDefinition: [
kustomer,
"name",
],
description: "Name of the conversation",
optional: true,
},
status: {
propDefinition: [
kustomer,
"status",
],
optional: true,
},
priority: {
propDefinition: [
kustomer,
"priority",
],
optional: true,
},
direction: {
propDefinition: [
kustomer,
"direction",
],
optional: true,
},
tags: {
propDefinition: [
kustomer,
"tags",
],
optional: true,
},
assignedUsers: {
propDefinition: [
kustomer,
"assignedUsers",
],
optional: true,
},
assignedTeams: {
propDefinition: [
kustomer,
"assignedTeams",
],
optional: true,
},
defaultLang: {
propDefinition: [
kustomer,
"defaultLang",
],
description: "Default language for the conversation",
optional: true,
},
queueId: {
propDefinition: [
kustomer,
"queueId",
],
},
},
async run({ $ }) {
try {
const response = await this.kustomer.createConversation({
$,
data: {
customer: this.customer,
externalId: this.externalId,
name: this.name,
status: this.status,
priority: this.priority,
direction: this.direction,
tags: parseObject(this.tags),
assignedUsers: parseObject(this.assignedUsers),
assignedTeams: parseObject(this.assignedTeams),
defaultLang: this.defaultLang,
queue: {
id: this.queueId,
},
},
});

$.export("$summary", `Created conversation with ID ${response.data.id}`);
return response;
} catch ({ message }) {
throwError(message);
}
},
};
203 changes: 203 additions & 0 deletions components/kustomer/actions/create-customer/create-customer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
import {
parseObject, throwError,
} from "../../common/utils.mjs";
import kustomer from "../../kustomer.app.mjs";

export default {
key: "kustomer-create-customer",
name: "Create Customer",
description: "Creates a new customer in Kustomer. [See the documentation](https://developer.kustomer.com/kustomer-api-docs/reference/createacustomer)",
version: "0.0.1",
type: "action",
props: {
kustomer,
name: {
propDefinition: [
kustomer,
"name",
],
optional: true,
},
company: {
propDefinition: [
kustomer,
"company",
],
optional: true,
},
externalId: {
propDefinition: [
kustomer,
"externalId",
],
optional: true,
},
username: {
propDefinition: [
kustomer,
"username",
],
optional: true,
},
avatarUrl: {
propDefinition: [
kustomer,
"avatarUrl",
],
optional: true,
},
externalIds: {
propDefinition: [
kustomer,
"externalIds",
],
optional: true,
},
sharedExternalIds: {
propDefinition: [
kustomer,
"sharedExternalIds",
],
optional: true,
},
emails: {
propDefinition: [
kustomer,
"emails",
],
optional: true,
},
sharedEmails: {
propDefinition: [
kustomer,
"sharedEmails",
],
optional: true,
},
phones: {
propDefinition: [
kustomer,
"phones",
],
optional: true,
},
sharedPhones: {
propDefinition: [
kustomer,
"sharedPhones",
],
optional: true,
},
whatsApps: {
propDefinition: [
kustomer,
"whatsApps",
],
optional: true,
},
urls: {
propDefinition: [
kustomer,
"urls",
],
optional: true,
},
tags: {
propDefinition: [
kustomer,
"tags",
],
optional: true,
},
sentimentPolarity: {
propDefinition: [
kustomer,
"sentimentPolarity",
],
optional: true,
},
sentimentConfidence: {
propDefinition: [
kustomer,
"sentimentConfidence",
],
optional: true,
},
birthdayAt: {
propDefinition: [
kustomer,
"birthdayAt",
],
optional: true,
},
gender: {
propDefinition: [
kustomer,
"gender",
],
optional: true,
},
defaultLang: {
propDefinition: [
kustomer,
"defaultLang",
],
optional: true,
},
},
async run({ $ }) {
try {
const sentiment = {};
if (this.sentimentConfidence) sentiment.confidence = parseInt(this.sentimentConfidence);
if (this.sentimentPolarity) sentiment.polarity = parseInt(this.sentimentPolarity);

const response = await this.kustomer.createCustomer({
$,
data: {
name: this.name,
company: this.company,
externalId: this.externalId,
username: this.username,
avatarUrl: this.avatarUrl,
externalIds: parseObject(this.externalIds)?.map((id) => ({
externalId: id,
})),
sharedExternalIds: parseObject(this.sharedExternalIds)?.map((id) => ({
externalId: id,
})),
emails: parseObject(this.emails)?.map((email) => ({
email,
})),
sharedEmails: parseObject(this.sharedEmails)?.map((email) => ({
email,
})),
phones: parseObject(this.phones)?.map((phone) => ({
phone: `${phone}`,
})),
sharedPhones: parseObject(this.sharedPhones)?.map((phone) => ({
phone: `${phone}`,
})),
whatsapps: parseObject(this.whatsApps)?.map((phone) => ({
phone: `${phone}`,
})),
urls: parseObject(this.urls)?.map((url) => ({
url,
})),
tags: parseObject(this.tags),
sentiment: Object.entries(sentiment).length
? sentiment
: undefined,
birthdayAt: this.birthdayAt,
gender: this.gender,
createdAt: this.createdAt,
importedAt: this.importedAt,
defaultLang: this.defaultLang,
},
});
$.export("$summary", `Created customer with ID ${response.data.id}`);
return response;
} catch ({ message }) {
throwError(message);
}
},
};
Loading
Loading