Skip to content
Merged
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
105 changes: 105 additions & 0 deletions components/upviral/actions/add-contact/add-contact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { ConfigurationError } from "@pipedream/platform";
import FormData from "form-data";
import upviral from "../../upviral.app.mjs";

export default {
key: "upviral-add-contact",
name: "Add Contact",
version: "0.0.1",
description: "Add a new contact in your particular campaign. [See the documentation](https://api.upviral.com/#add-contact)",
type: "action",
props: {
upviral,
campaignId: {
propDefinition: [
upviral,
"campaignId",
],
reloadProps: true,
},
email: {
type: "string",
label: "Email",
description: "The user's email address.",
},
name: {
type: "string",
label: "Name",
description: "The user's name.",
optional: true,
},
ipAddress: {
type: "string",
label: "IP Address",
description: "The user's IP Address.",
optional: true,
},
referralCode: {
type: "string",
label: "Referral Code",
description: "The unique referral code (Last part of unique Referral URL). For example - https://upvir.al/ref/XXXX, Referral Code will be XXXX.This will be the referral code of the person who referred this new contact. The original participant will get the credit for this new contact.",
optional: true,
},
},
async additionalProps() {
const props = {};
if (this.campaignId) {
let count = 0;
let data = new FormData();
data.append("campaign_id", this.campaignId);

const { custom_fields: customFields } = await this.upviral.listCustomFields({
data,
headers: data.getHeaders(),
});

for (const field of customFields) {
props[`customField-${field}`] = {
type: "string",
label: field,
description: `Custom field ${++count}`,
optional: true,
};
}
}
return props;
},
methods: {
parseCustomFields() {
const customFields = Object.entries(this).filter(([
key,
]) => key.includes("customField-"))
.map(([
key,
value,
]) => ([
key.split("-")[1],
value,
]));

return JSON.stringify(Object.fromEntries(customFields)) || null;
},
},
async run({ $ }) {
var bodyFormData = new FormData();
bodyFormData.append("campaign_id", this.campaignId);
bodyFormData.append("email", this.email);
if (this.name) bodyFormData.append("name", this.name);
if (this.ipAddress) bodyFormData.append("ip_address", this.ipAddress);
if (this.referralCode) bodyFormData.append("referral_code", this.referralCode);
bodyFormData.append("custom_fields", this.parseCustomFields() );

const response = await this.upviral.addContact({
$,
data: bodyFormData,
headers: bodyFormData.getHeaders(),
});

if (response.result === "error") {
throw new ConfigurationError(response.message);
}

$.export("$summary", `A new contact with UID: '${response.uid}' was successfully created!`);
return response;
},
};
51 changes: 51 additions & 0 deletions components/upviral/actions/add-points/add-points.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { ConfigurationError } from "@pipedream/platform";
import FormData from "form-data";
import upviral from "../../upviral.app.mjs";

export default {
key: "upviral-add-points",
name: "Add Points",
version: "0.0.1",
description: "Add points in user profile. [See the documentation](https://api.upviral.com/#add-points)",
type: "action",
props: {
upviral,
campaignId: {
propDefinition: [
upviral,
"campaignId",
],
},
leadId: {
propDefinition: [
upviral,
"leadId",
({ campaignId }) => ({
campaignId,
}),
],
},
points: {
type: "string",
label: "Points",
description: "The points to add.",
},
},
async run({ $ }) {
var bodyFormData = new FormData();
bodyFormData.append("campaign_id", this.campaignId);
bodyFormData.append("lead_id", this.leadId);
bodyFormData.append("points", this.points);

const response = await this.upviral.addPoints({
$,
data: bodyFormData,
headers: bodyFormData.getHeaders(),
});

if (response.result === "error") throw new ConfigurationError(response.message);

$.export("$summary", `${this.points} points were successfully added!`);
return response;
},
};
1 change: 1 addition & 0 deletions components/upviral/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const LIMIT = 100;
19 changes: 19 additions & 0 deletions components/upviral/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@pipedream/upviral",
"version": "0.1.0",
"description": "Pipedream UpViral Components",
"main": "upviral.app.mjs",
"keywords": [
"pipedream",
"upviral"
],
"homepage": "https://pipedream.com/apps/upviral",
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.5.1",
"form-data": "^4.0.0"
}
}
132 changes: 128 additions & 4 deletions components/upviral/upviral.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,135 @@
import { axios } from "@pipedream/platform";
import FormData from "form-data";
import { LIMIT } from "./common/constants.mjs";

export default {
type: "app",
app: "upviral",
propDefinitions: {},
propDefinitions: {
campaignId: {
type: "string",
label: "Campaign Id",
description: "The Id of the campaign.",
async options() {
const { data } = await this.listCampaigns({});

return data.map(({
id: value, name: label,
}) => ({
label,
value,
}));
},
},
leadId: {
type: "string",
label: "Lead Id",
description: "The Id of the lead.",
async options({
page, campaignId,
}) {
var formData = new FormData();
formData.append("campaign_id", campaignId);
const { data } = await this.listLeads({
params: {
start: LIMIT * page,
size: LIMIT,
},
data: formData,
headers: formData.getHeaders(),
});

return data.leads.map(({
id: value, email: label,
}) => ({
label,
value,
}));
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_apiKey() {
return this.$auth.api_key;
},
_apiUrl() {
return "https://app.upviral.com/api/v1";
},
_getParams(params) {
return {
uvapikey: this._apiKey(),
...params,
};
},
_makeRequest({
$ = this, params, ...opts
}) {
const config = {
url: `${this._apiUrl()}`,
params: this._getParams(params),
...opts,
};

return axios($, config);
},
addContact({
params, ...args
}) {
return this._makeRequest({
method: "POST",
params: {
uvmethod: "add_contact",
...params,
},
...args,
});
},
addPoints({
params, ...args
}) {
return this._makeRequest({
method: "POST",
params: {
uvmethod: "add_points",
...params,
},
...args,
});
},
listCampaigns({
params = {}, ...args
}) {
return this._makeRequest({
params: {
uvmethod: "lists",
...params,
},
...args,
});
},
listCustomFields({
params, ...args
}) {
return this._makeRequest({
method: "POST",
params: {
uvmethod: "get_custom_fields",
...params,
},
...args,
});
},
listLeads({
params, ...args
}) {
return this._makeRequest({
method: "POST",
params: {
uvmethod: "get_leads",
...params,
},
...args,
});
},
},
};
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

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