From b1467e5f105b7325cad16b03d55cb9318e8e1bbf Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Wed, 24 Apr 2024 13:35:00 -0300 Subject: [PATCH 1/5] vryno init --- .../create-unique-lead/create-unique-lead.mjs | 42 ++++++++++ components/vryno/package.json | 2 +- components/vryno/vryno.app.mjs | 82 ++++++++++++++++++- 3 files changed, 122 insertions(+), 4 deletions(-) create mode 100644 components/vryno/actions/create-unique-lead/create-unique-lead.mjs diff --git a/components/vryno/actions/create-unique-lead/create-unique-lead.mjs b/components/vryno/actions/create-unique-lead/create-unique-lead.mjs new file mode 100644 index 0000000000000..1e17cfa0e4134 --- /dev/null +++ b/components/vryno/actions/create-unique-lead/create-unique-lead.mjs @@ -0,0 +1,42 @@ +import vryno from "../../vryno.app.mjs"; +import { axios } from "@pipedream/platform"; + +export default { + key: "vryno-create-unique-lead", + name: "Create Unique Lead", + description: "Creates a unique lead in the Vryno system, ensuring no duplication of lead details. [See the documentation]()", // Placeholder for documentation link + version: "0.0.1", + type: "action", + props: { + vryno, + name: vryno.propDefinitions.name, + email: vryno.propDefinitions.email, + phoneNumber: vryno.propDefinitions.phoneNumber, + source: vryno.propDefinitions.source, + interest: vryno.propDefinitions.interest, + }, + async run({ $ }) { + // Check for duplicate lead + const duplicateCheck = await this.vryno.checkLeadDuplicate({ + email: this.email, + phoneNumber: this.phoneNumber, + }); + + if (duplicateCheck.data && duplicateCheck.data.exists) { + $.export("$summary", "A lead with the same email and phone number already exists."); + return duplicateCheck.data; + } + + // Create the lead if no duplicate was found + const response = await this.vryno.createLead({ + name: this.name, + email: this.email, + phoneNumber: this.phoneNumber, + source: this.source, + interest: this.interest, + }); + + $.export("$summary", `Successfully created unique lead with email ${this.email}`); + return response; + }, +}; diff --git a/components/vryno/package.json b/components/vryno/package.json index 9597037e2bf7a..d11e5d8421f78 100644 --- a/components/vryno/package.json +++ b/components/vryno/package.json @@ -12,4 +12,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +} diff --git a/components/vryno/vryno.app.mjs b/components/vryno/vryno.app.mjs index 0a6b412f5a3ef..610a1297f7d2d 100644 --- a/components/vryno/vryno.app.mjs +++ b/components/vryno/vryno.app.mjs @@ -1,11 +1,87 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "vryno", - propDefinitions: {}, + propDefinitions: { + name: { + type: "string", + label: "Name", + description: "Name of the lead.", + }, + email: { + type: "string", + label: "Email", + description: "Email address of the lead.", + }, + phoneNumber: { + type: "string", + label: "Phone Number", + description: "Phone number of the lead.", + }, + source: { + type: "string", + label: "Source", + description: "Source from which the lead was obtained.", + }, + interest: { + type: "string", + label: "Interest", + description: "Specific product or service the lead is interested in.", + optional: true, + }, + }, methods: { - // this.$auth contains connected account data authKeys() { console.log(Object.keys(this.$auth)); }, + _baseUrl() { + return "https://api.vryno.com"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, method = "GET", path = "/", headers, ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + method, + url: this._baseUrl() + path, + headers: { + ...headers, + "Authorization": `Bearer ${this.$auth.oauth_access_token}`, + "Content-Type": "application/json", + }, + }); + }, + async createLead({ + name, email, phoneNumber, source, interest, + }) { + const input = { + name, + email, + "contact details": { + phone: phoneNumber, + source, + }, + }; + if (interest) { + input.interest = interest; + } + return this._makeRequest({ + method: "POST", + path: "/createLead", + data: { + input, + }, + }); + }, + async checkLeadDuplicate({ + email, phoneNumber, + }) { + return this._makeRequest({ + method: "GET", + path: `/checkDuplicate?email=${email}&phone=${phoneNumber}`, + }); + }, }, -}; \ No newline at end of file +}; From 5510534921ad3d39ad46a0c49607884956e67871 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Fri, 26 Apr 2024 08:56:23 -0300 Subject: [PATCH 2/5] [Components] vryno #11624 Actions - Create Unique Lead --- .../create-unique-lead/create-unique-lead.mjs | 221 ++++++++++++++++-- components/vryno/package.json | 6 +- components/vryno/vryno.app.mjs | 82 ++----- 3 files changed, 220 insertions(+), 89 deletions(-) diff --git a/components/vryno/actions/create-unique-lead/create-unique-lead.mjs b/components/vryno/actions/create-unique-lead/create-unique-lead.mjs index 1e17cfa0e4134..5cd1b6e499227 100644 --- a/components/vryno/actions/create-unique-lead/create-unique-lead.mjs +++ b/components/vryno/actions/create-unique-lead/create-unique-lead.mjs @@ -1,42 +1,223 @@ +import { ConfigurationError } from "@pipedream/platform"; import vryno from "../../vryno.app.mjs"; -import { axios } from "@pipedream/platform"; export default { key: "vryno-create-unique-lead", name: "Create Unique Lead", - description: "Creates a unique lead in the Vryno system, ensuring no duplication of lead details. [See the documentation]()", // Placeholder for documentation link + description: "Creates a unique lead in the Vryno system, ensuring no duplication of lead details. [See the documentation](https://vrynotest.ti2.in/docs/api-documentation/how-to-create-a-record-in-any-module-in-vryno-crm/)", version: "0.0.1", type: "action", props: { vryno, - name: vryno.propDefinitions.name, - email: vryno.propDefinitions.email, - phoneNumber: vryno.propDefinitions.phoneNumber, - source: vryno.propDefinitions.source, - interest: vryno.propDefinitions.interest, + firstName: { + type: "string", + label: "First Name", + description: "The lead's first name.", + optional: true, + }, + name: { + type: "string", + label: "Last Name", + description: "The lead's last name.", + }, + email: { + type: "string", + label: "Email", + description: "The lead's email.", + optional: true, + }, + phoneNumber: { + type: "string", + label: "Phone Number", + description: "The lead's phone number.", + optional: true, + }, + company: { + type: "string", + label: "Company", + description: "The company the lead works for.", + optional: true, + }, + website: { + type: "string", + label: "Website", + description: "The lead's website.", + optional: true, + }, + ownerId: { + type: "string", + label: "Owner Id", + description: "The user Id related to the lead.", + }, + score: { + type: "integer", + label: "Score", + description: "The lead's score.", + optional: true, + }, + expectedRevenue: { + type: "integer", + label: "Expected Revenue", + description: "Expected revenue for the lead.", + optional: true, + }, + numberOfEmployees: { + type: "integer", + label: "Number Of Employees", + description: "Number of employees at the lead company.", + optional: true, + }, + + billingAddress: { + type: "string", + label: "Billing Address", + description: "The lead's billing address.", + optional: true, + }, + billingCity: { + type: "string", + label: "Billing City", + description: "The lead's billing city.", + optional: true, + }, + billingState: { + type: "string", + label: "Billing State", + description: "The lead's billing state.", + optional: true, + }, + billingCountry: { + type: "string", + label: "Billing Country", + description: "The lead's billing country.", + optional: true, + }, + billingZipcode: { + type: "string", + label: "Billing Zipcode", + description: "The lead's billing zipcode", + optional: true, + }, + shippingAddress: { + type: "string", + label: "Shipping Address", + description: "The lead's shipping address.", + optional: true, + }, + shippingCity: { + type: "string", + label: "Shipping City", + description: "The lead's shipping city.", + optional: true, + }, + shippingState: { + type: "string", + label: "Shipping State", + description: "The lead's shipping state.", + optional: true, + }, + shippingCountry: { + type: "string", + label: "Shipping Country", + description: "The lead's shipping country.", + optional: true, + }, + shippingZipcode: { + type: "string", + label: "Shipping Zipcode", + description: "The lead's shipping zipcode", + optional: true, + }, + description: { + type: "string", + label: "Description", + description: "A brief description about the lead.", + optional: true, + }, }, async run({ $ }) { - // Check for duplicate lead - const duplicateCheck = await this.vryno.checkLeadDuplicate({ - email: this.email, - phoneNumber: this.phoneNumber, + if (!this.email && !this.phoneNumber) { + throw new ConfigurationError("You must provide at least either **Email** or **Phone Number**."); + } + const duplicateCheck = await this.vryno.post({ + data: { + query: `query { + fetchLead(filters:[${this.email + ? `{name: "email", operator:"eq",value:["${this.email}"]},` + : ""}${this.phoneNumber + ? `{name: "phoneNumber", operator:"eq",value:["${this.phoneNumber}"]}` + : ""}]){ + code + status + message + messageKey + count + data { + id + } + } + }`, + }, }); - if (duplicateCheck.data && duplicateCheck.data.exists) { + console.log("duplicateCheck: ", duplicateCheck); + + if (duplicateCheck.data.fetchLead.data) { $.export("$summary", "A lead with the same email and phone number already exists."); return duplicateCheck.data; } - // Create the lead if no duplicate was found - const response = await this.vryno.createLead({ - name: this.name, - email: this.email, - phoneNumber: this.phoneNumber, - source: this.source, - interest: this.interest, + const { + vryno, + ...data + } = this; + + let query = `mutation { + createLead(input: { + `; + + for (const [ + field, + value, + ] of Object.entries(data)) { + query += `${field}:`; + if ([ + "score", + "expectedRevenue", + "numberOfEmployees", + ].includes(field)) { + query += ` ${value} + `; + } else { + query += ` "${value}" + `; + } + } + + query += `}) { + code + message + status + messageKey + data { + id + } + errors + } + }`; + + const response = await vryno.post({ + $, + data: { + query, + }, }); - $.export("$summary", `Successfully created unique lead with email ${this.email}`); + if (response.data.createLead.code != 200) { + throw new ConfigurationError(response.data.createLead.message); + } + + $.export("$summary", `Successfully created new lead with Id: ${response.data.createLead.data.id}`); return response; }, }; diff --git a/components/vryno/package.json b/components/vryno/package.json index d11e5d8421f78..a0a0886d5967a 100644 --- a/components/vryno/package.json +++ b/components/vryno/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/vryno", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Vryno Components", "main": "vryno.app.mjs", "keywords": [ @@ -11,5 +11,9 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^1.6.2" } } + diff --git a/components/vryno/vryno.app.mjs b/components/vryno/vryno.app.mjs index 610a1297f7d2d..e737cd4ca0345 100644 --- a/components/vryno/vryno.app.mjs +++ b/components/vryno/vryno.app.mjs @@ -3,84 +3,30 @@ import { axios } from "@pipedream/platform"; export default { type: "app", app: "vryno", - propDefinitions: { - name: { - type: "string", - label: "Name", - description: "Name of the lead.", - }, - email: { - type: "string", - label: "Email", - description: "Email address of the lead.", - }, - phoneNumber: { - type: "string", - label: "Phone Number", - description: "Phone number of the lead.", - }, - source: { - type: "string", - label: "Source", - description: "Source from which the lead was obtained.", - }, - interest: { - type: "string", - label: "Interest", - description: "Specific product or service the lead is interested in.", - optional: true, - }, - }, methods: { - authKeys() { - console.log(Object.keys(this.$auth)); - }, _baseUrl() { - return "https://api.vryno.com"; + return `https://${this.$auth.company_instance_name}.ms.vryno.com`; + }, + _headers() { + return { + "Authorization": `Bearer ${this.$auth.oauth_access_token}`, + "Content-Type": "application/json", + }; }, - async _makeRequest(opts = {}) { - const { - $ = this, method = "GET", path = "/", headers, ...otherOpts - } = opts; + _makeRequest({ + $ = this, path, ...otherOpts + }) { return axios($, { ...otherOpts, - method, url: this._baseUrl() + path, - headers: { - ...headers, - "Authorization": `Bearer ${this.$auth.oauth_access_token}`, - "Content-Type": "application/json", - }, + headers: this._headers(), }); }, - async createLead({ - name, email, phoneNumber, source, interest, - }) { - const input = { - name, - email, - "contact details": { - phone: phoneNumber, - source, - }, - }; - if (interest) { - input.interest = interest; - } + post(opts = {}) { return this._makeRequest({ method: "POST", - path: "/createLead", - data: { - input, - }, - }); - }, - async checkLeadDuplicate({ - email, phoneNumber, - }) { - return this._makeRequest({ - method: "GET", - path: `/checkDuplicate?email=${email}&phone=${phoneNumber}`, + path: "/api/graphql/crm", + ...opts, }); }, }, From 354739fdd2bf6c806b9e1a74559cd8b78f7fd689 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Fri, 26 Apr 2024 08:58:07 -0300 Subject: [PATCH 3/5] pnpm update --- pnpm-lock.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a254b8d197b13..1c5cd506884a4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9147,7 +9147,10 @@ importers: specifiers: {} components/vryno: - specifiers: {} + specifiers: + '@pipedream/platform': ^1.6.2 + dependencies: + '@pipedream/platform': 1.6.4 components/vtiger_crm: specifiers: From 8960f477bbecfeb1b2d6a197e2f4c3dd623421fc Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Mon, 29 Apr 2024 16:52:09 -0300 Subject: [PATCH 4/5] remove console.log --- .../vryno/actions/create-unique-lead/create-unique-lead.mjs | 3 --- 1 file changed, 3 deletions(-) diff --git a/components/vryno/actions/create-unique-lead/create-unique-lead.mjs b/components/vryno/actions/create-unique-lead/create-unique-lead.mjs index 5cd1b6e499227..f6a6387680715 100644 --- a/components/vryno/actions/create-unique-lead/create-unique-lead.mjs +++ b/components/vryno/actions/create-unique-lead/create-unique-lead.mjs @@ -67,7 +67,6 @@ export default { description: "Number of employees at the lead company.", optional: true, }, - billingAddress: { type: "string", label: "Billing Address", @@ -160,8 +159,6 @@ export default { }, }); - console.log("duplicateCheck: ", duplicateCheck); - if (duplicateCheck.data.fetchLead.data) { $.export("$summary", "A lead with the same email and phone number already exists."); return duplicateCheck.data; From 92088bfb7ee0c11cf8816f5a918d40f901dee677 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Thu, 2 May 2024 12:29:47 -0300 Subject: [PATCH 5/5] some adjusts --- .../actions/create-unique-lead/create-unique-lead.mjs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/components/vryno/actions/create-unique-lead/create-unique-lead.mjs b/components/vryno/actions/create-unique-lead/create-unique-lead.mjs index f6a6387680715..d1dc5499980df 100644 --- a/components/vryno/actions/create-unique-lead/create-unique-lead.mjs +++ b/components/vryno/actions/create-unique-lead/create-unique-lead.mjs @@ -47,7 +47,7 @@ export default { ownerId: { type: "string", label: "Owner Id", - description: "The user Id related to the lead.", + description: "The user Id related to the lead.You can find the user IDs in your account -> settings -> users & controls -> users, click on some user and the ID will be in URL.", }, score: { type: "integer", @@ -145,7 +145,8 @@ export default { ? `{name: "email", operator:"eq",value:["${this.email}"]},` : ""}${this.phoneNumber ? `{name: "phoneNumber", operator:"eq",value:["${this.phoneNumber}"]}` - : ""}]){ + : ""}], + expression:"( ( a ) and b)"){ code status message @@ -159,7 +160,7 @@ export default { }, }); - if (duplicateCheck.data.fetchLead.data) { + if (duplicateCheck.data?.fetchLead?.data?.length) { $.export("$summary", "A lead with the same email and phone number already exists."); return duplicateCheck.data; }