Skip to content

Commit

Permalink
New Components - vryno (#11628)
Browse files Browse the repository at this point in the history
* vryno init

* [Components] vryno #11624
Actions
 - Create Unique Lead

* pnpm update

* remove console.log

* some adjusts
  • Loading branch information
luancazarine committed May 6, 2024
1 parent 768243d commit fb2068a
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 7 deletions.
221 changes: 221 additions & 0 deletions components/vryno/actions/create-unique-lead/create-unique-lead.mjs
Original file line number Diff line number Diff line change
@@ -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;
},
};
8 changes: 6 additions & 2 deletions components/vryno/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/vryno",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Vryno Components",
"main": "vryno.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,9 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.6.2"
}
}
}

30 changes: 26 additions & 4 deletions components/vryno/vryno.app.mjs
Original file line number Diff line number Diff line change
@@ -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,
});
},
},
};
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fb2068a

Please sign in to comment.