-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
220 additions
and
89 deletions.
There are no files selected for viewing
221 changes: 201 additions & 20 deletions
221
components/vryno/actions/create-unique-lead/create-unique-lead.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters