Skip to content

Commit

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

* [Components] hippo_video #10752
Sources:
 - New Event Triggered (Instant)

Actions
 - Send Personalization Request
 - Upload Video
 - Create Contact

* pnpm update

* add form-data

* pnpm update

* some adjusts

* Update components/hippo_video/actions/send-personalization-request/send-personalization-request.mjs

* some adjusts

---------

Co-authored-by: Leo Vu <18277920+vunguyenhung@users.noreply.github.com>
  • Loading branch information
luancazarine and vunguyenhung committed May 27, 2024
1 parent 7a27a3d commit 783c30c
Show file tree
Hide file tree
Showing 9 changed files with 394 additions and 8 deletions.
71 changes: 71 additions & 0 deletions components/hippo_video/actions/create-contact/create-contact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { ConfigurationError } from "@pipedream/platform";
import { parseObject } from "../../common/utils.mjs";
import hippoVideo from "../../hippo_video.app.mjs";

export default {
key: "hippo_video-create-contact",
name: "Create Contact",
description: "Creates a new contact in Hippo Video. [See the documentation](https://documenter.getpostman.com/view/5278433/Tz5naxpW#a4d73ffe-a2b6-4d68-a1ee-9fbc1417a955)",
version: "0.0.1",
type: "action",
props: {
hippoVideo,
contactEmail: {
type: "string",
label: "Contact Email",
description: "Email Address of the Contact/Lead/Prospect.",
},
firstName: {
type: "string",
label: "First Name",
description: "First Name of the Contact/Lead/Prospect.",
},
lastName: {
type: "string",
label: "Last Name",
description: "Last Name of the Contact/Lead/Prospect.",
},
companyName: {
type: "string",
label: "Company name",
description: "Company Name of the Contact/Lead/Prospect.",
},
notes: {
type: "string",
label: "Notes",
description: "Notes for the lead/prospect/contact.",
},
context: {
type: "string",
label: "Context",
description: "If sales, will be added as a prospect. If empty, will be added as people.",
optional: true,
},
listIds: {
propDefinition: [
hippoVideo,
"listIds",
],
optional: true,
},
},
async run({ $ }) {
const response = await this.hippoVideo.createContact({
$,
data: {
contact_email: this.contactEmail,
first_name: this.firstName,
last_name: this.lastName,
company_name: this.companyName,
notes: this.notes,
context: this.context,
list_ids: parseObject(this.listIds)?.join(),
},
});

if (!response.status) throw new ConfigurationError(response.message);

$.export("$summary", `Successfully created contact with Id: ${response.contact_id}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { ConfigurationError } from "@pipedream/platform";
import FormData from "form-data";
import fs from "fs";
import { checkTmp } from "../../common/utils.mjs";
import hippoVideo from "../../hippo_video.app.mjs";

export default {
key: "hippo_video-send-personalization-request",
name: "Send Personalization Request",
description: "Sends a personalization request for a specified video. [See the documentation](https://help.hippovideo.io/support/solutions/articles/19000099793-bulk-video-personalization-and-tracking-api)",
version: "0.0.1",
type: "action",
props: {
hippoVideo,
videoId: {
propDefinition: [
hippoVideo,
"videoId",
],
},
file: {
type: "string",
label: "File",
description: "csv, xls, and xlsx file saved to the [`/tmp` directory](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory). To get file schema, [see documentation](https://help.hippovideo.io/support/solutions/articles/19000099793-bulk-video-personalization-and-tracking-api)",
},
},
async run({ $ }) {
const formData = new FormData();
const file = fs.createReadStream(checkTmp(this.file));

formData.append("file", file);
formData.append("video_id", this.videoId);

const response = await this.hippoVideo.personalizeVideo({
$,
data: formData,
headers: formData.getHeaders(),
maxBodyLength: Infinity,
});

if (response.code != 200) throw new ConfigurationError(response.message || response.type);

$.export("$summary", `Successfully sent personalization request for video Id: ${this.videoId}`);
return response;
},
};
37 changes: 37 additions & 0 deletions components/hippo_video/actions/upload-video/upload-video.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { ConfigurationError } from "@pipedream/platform";
import hippoVideo from "../../hippo_video.app.mjs";

export default {
key: "hippo_video-upload-video",
name: "Upload Video",
description: "Uploads a video from a given URL. [See the documentation](https://help.hippovideo.io/support/solutions/articles/19000100703-import-api)",
version: "0.0.1",
type: "action",
props: {
hippoVideo,
title: {
type: "string",
label: "Title",
description: "Title of the video.",
},
url: {
type: "string",
label: "Video URL",
description: "Public URL of the videos to be downloaded and uploaded to HippoVideo.",
},
},
async run({ $ }) {
const response = await this.hippoVideo.uploadVideo({
$,
data: {
title: this.title,
url: this.url,
},
});

if (response.code != "200") throw new ConfigurationError(response.message);

$.export("$summary", `Video uploaded successfully with Id: ${response.video_id}`);
return response;
},
};
26 changes: 26 additions & 0 deletions components/hippo_video/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export const EVENT_OPTIONS = [
{
value: "3",
label: "Viewing Sessions",
},
{
value: "1",
label: "Video Created",
},
{
value: "4",
label: "CTA Lead Genaration",
},
{
value: "5",
label: "CTA Annotations",
},
{
value: "6",
label: "CT",
},
{
value: "18",
label: "Video Transcode",
},
];
31 changes: 31 additions & 0 deletions components/hippo_video/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export const parseObject = (obj) => {
if (!obj) return undefined;

if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (e) {
return item;
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
return obj;
};

export const checkTmp = (filename) => {
if (!filename.startsWith("/tmp")) {
return `/tmp/${filename}`;
}
return filename;
};
109 changes: 104 additions & 5 deletions components/hippo_video/hippo_video.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,110 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "hippo_video",
propDefinitions: {},
propDefinitions: {
listIds: {
type: "string[]",
label: "List Ids",
description: "A list of lists you want to add the prospect.",
async options({ page }) {
const { contacts_list: data } = await this.listLists({
params: {
page,
},
});

return data.map(({
id: value, name: label,
}) => ({
label,
value,
}));
},
},
videoId: {
type: "string",
label: "Video ID",
description: "The ID of the video to be personalized.",
async options({ page }) {
const { videos } = await this.listVideos({
params: {
page: page + 1,
},
});

return videos.map(({
id: value, title: label,
}) => ({
label,
value,
}));
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://www.hippovideo.io";
},
_params(params = {}) {
return {
...params,
email: `${this.$auth.email}`,
api_key: `${this.$auth.api_key}`,
};
},
_makeRequest({
$ = this, path, params, ...opts
}) {
return axios($, {
url: `${this._baseUrl()}${path}`,
params: this._params(params),
headers: {
"Accept": "*/*",
},
...opts,
});
},
createContact(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/contacts",
...opts,
});
},
listLists(opts = {}) {
return this._makeRequest({
path: "/contacts/names",
...opts,
});
},
listVideos(opts = {}) {
return this._makeRequest({
path: "/api/v1/me/videos/list",
...opts,
});
},
personalizeVideo(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/api/v1/me/video/bulk_personalize",
...opts,
});
},
uploadVideo(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/api/v1/me/video/import",
...opts,
});
},
updateWebhook(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/webhook",
...opts,
});
},
},
};
};
8 changes: 6 additions & 2 deletions components/hippo_video/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/hippo_video",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Hippo Video Components",
"main": "hippo_video.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,9 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.6.5",
"form-data": "^4.0.0"
}
}
}

0 comments on commit 783c30c

Please sign in to comment.