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..d1dc5499980df --- /dev/null +++ b/components/vryno/actions/create-unique-lead/create-unique-lead.mjs @@ -0,0 +1,221 @@ +import { ConfigurationError } from "@pipedream/platform"; +import vryno from "../../vryno.app.mjs"; + +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](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, + 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.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", + 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({ $ }) { + 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}"]}` + : ""}], + expression:"( ( a ) and b)"){ + code + status + message + messageKey + count + data { + id + } + } + }`, + }, + }); + + if (duplicateCheck.data?.fetchLead?.data?.length) { + $.export("$summary", "A lead with the same email and phone number already exists."); + return duplicateCheck.data; + } + + 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, + }, + }); + + 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 9597037e2bf7a..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" } -} \ No newline at end of file +} + diff --git a/components/vryno/vryno.app.mjs b/components/vryno/vryno.app.mjs index 0a6b412f5a3ef..e737cd4ca0345 100644 --- a/components/vryno/vryno.app.mjs +++ b/components/vryno/vryno.app.mjs @@ -1,11 +1,33 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "vryno", - propDefinitions: {}, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return `https://${this.$auth.company_instance_name}.ms.vryno.com`; + }, + _headers() { + return { + "Authorization": `Bearer ${this.$auth.oauth_access_token}`, + "Content-Type": "application/json", + }; + }, + _makeRequest({ + $ = this, path, ...otherOpts + }) { + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: this._headers(), + }); + }, + post(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/api/graphql/crm", + ...opts, + }); }, }, -}; \ No newline at end of file +}; 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: