Skip to content
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

New Components - kommo #12549

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
66 changes: 66 additions & 0 deletions components/kommo/actions/create-lead/create-lead.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { parseObject } from "../../common/utils.mjs";
import kommo from "../../kommo.app.mjs";

export default {
key: "kommo-create-lead",
name: "Create Lead",
description: "Creates a new lead in the Kommo app. [See the documentation](https://www.kommo.com/developers/content/api_v4/leads-api/#leads-add)",
version: "0.0.1",
type: "action",
props: {
kommo,
name: {
type: "string",
label: "Name",
description: "Lead name.",
optional: true,
},
price: {
type: "integer",
label: "Price",
description: "Lead sale.",
optional: true,
},
pipelineId: {
propDefinition: [
kommo,
"pipelineId",
],
optional: true,
},
statusId: {
propDefinition: [
kommo,
"statusId",
({ pipelineId }) => ({
pipelineId,
}),
],
optional: true,
},
customFieldsValues: {
propDefinition: [
kommo,
"customFieldsValues",
],
optional: true,
},
},
async run({ $ }) {
const response = await this.kommo.createLead({
$,
data: [
{
name: this.name,
price: this.price,
status_id: this.statusId,
pipeline_id: this.pipelineId,
custom_fields_values: parseObject(this.customFieldsValues),
},
],
});

$.export("$summary", `Successfully created lead with ID: ${response?._embedded?.leads[0]?.id}`);
return response?._embedded?.leads[0];
},
};
65 changes: 65 additions & 0 deletions components/kommo/actions/search-companies/search-companies.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import kommo from "../../kommo.app.mjs";

export default {
key: "kommo-search-companies",
name: "Search Companies",
description: "Searches for companies within Kommo or lists all of them. [See the documentation](https://www.kommo.com/developers/content/api_v4/companies-api/)",
version: "0.0.1",
type: "action",
props: {
kommo,
companyId: {
propDefinition: [
kommo,
"companyId",
],
optional: true,
},
name: {
type: "string",
label: "Name",
description: "Filter by company name",
optional: true,
},
createdBy: {
propDefinition: [
kommo,
"userId",
],
label: "Created By",
description: "Filter by ID of the user who created the entity.",
optional: true,
},
updatedBy: {
propDefinition: [
kommo,
"userId",
],
label: "Updated By",
description: "Filter by ID of the user who changed the entity last.",
optional: true,
},
responsibleUserId: {
propDefinition: [
kommo,
"userId",
],
optional: true,
},
},
async run({ $ }) {
const response = await this.kommo.searchCompanies({
$,
params: {
"filter[id]": this.companyId,
"filter[name]": this.name,
"filter[created_by]": this.createdBy,
"filter[updated_by]": this.updatedBy,
"filter[responsible_user_id]": this.responsibleUserId,
},
});

$.export("$summary", `Successfully found ${response.length} companies`);
return response;
},
};
66 changes: 66 additions & 0 deletions components/kommo/actions/update-contact/update-contact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import kommo from "../../kommo.app.mjs";

export default {
key: "kommo-update-contact",
name: "Update Contact",
description: "Updates the details of an existing contact in the Kommo app. [See the documentation](https://www.kommo.com/developers/content/api_v4/contacts-api/#contacts-edit)",
version: "0.0.1",
type: "action",
props: {
kommo,
contactId: {
propDefinition: [
kommo,
"contactId",
],
},
name: {
type: "string",
label: "Name",
description: "Contact fullname.",
optional: true,
},
firstName: {
type: "string",
label: "First Name",
description: "Contact first name.",
optional: true,
},
lastName: {
type: "string",
label: "Last Name",
description: "Contact last name.",
optional: true,
},
responsibleUserId: {
propDefinition: [
kommo,
"userId",
],
optional: true,
},
customFieldsValues: {
propDefinition: [
kommo,
"customFieldsValues",
],
optional: true,
},
},
async run({ $ }) {
const response = await this.kommo.updateContact({
$,
contactId: this.contactId,
data: {
name: this.name,
first_name: this.firstName,
last_name: this.lastName,
responsible_user_id: this.responsibleUserId,
custom_fields_values: this.customFieldsValues,
},
});

$.export("$summary", `Successfully updated contact with Id: ${this.contactId}`);
return response;
},
};
24 changes: 24 additions & 0 deletions components/kommo/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const parseObject = (obj) => {
if (!obj) return undefined;

if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (e) {
return item;
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
return obj;
};
Loading
Loading