Skip to content

Commit 1a55044

Browse files
New Components - poper (#12742)
* poper init * [Components] poper #12738 Sources - New Lead * pnpm update * Update components/poper/sources/new-lead/new-lead.mjs Co-authored-by: michelle0927 <[email protected]> --------- Co-authored-by: michelle0927 <[email protected]>
1 parent d650a66 commit 1a55044

File tree

5 files changed

+159
-8
lines changed

5 files changed

+159
-8
lines changed

components/poper/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/poper",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Poper Components",
55
"main": "poper.app.mjs",
66
"keywords": [
@@ -11,5 +11,9 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.0"
1417
}
15-
}
18+
}
19+

components/poper/poper.app.mjs

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,57 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "poper",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
poperId: {
8+
type: "string",
9+
label: "Poper ID",
10+
description: "The ID of the Poper popup",
11+
async options() {
12+
const { popups } = await this.listPopups();
13+
return popups.map(({
14+
id: value, name: label,
15+
}) => ({
16+
label,
17+
value,
18+
}));
19+
},
20+
},
21+
},
522
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
23+
_baseUrl() {
24+
return "https://api.poper.ai/general/v1";
25+
},
26+
_data(data = {}) {
27+
return {
28+
...data,
29+
api_key: `${this.$auth.api_key}`,
30+
};
31+
},
32+
_makeRequest({
33+
$ = this, path, data, ...opts
34+
}) {
35+
return axios($, {
36+
method: "POST",
37+
url: this._baseUrl() + path,
38+
headers: {
39+
"Content-Type": "application/x-www-form-urlencoded",
40+
},
41+
data: this._data(data),
42+
...opts,
43+
});
44+
},
45+
listPopups() {
46+
return this._makeRequest({
47+
path: "/popup/list",
48+
});
49+
},
50+
listPoperResponses(opts = {}) {
51+
return this._makeRequest({
52+
path: "/popup/responses",
53+
...opts,
54+
});
955
},
1056
},
11-
};
57+
};
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
2+
import poper from "../../poper.app.mjs";
3+
import sampleEmit from "./test-event.mjs";
4+
5+
export default {
6+
key: "poper-new-lead",
7+
name: "New Lead from Poper Popup",
8+
description: "Emit new event when a new lead is obtained from Poper popups.",
9+
version: "0.0.1",
10+
type: "source",
11+
props: {
12+
poper,
13+
db: "$.service.db",
14+
timer: {
15+
label: "Polling interval",
16+
description: "Pipedream will poll the Poper API on this schedule",
17+
type: "$.interface.timer",
18+
default: {
19+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
20+
},
21+
},
22+
poperId: {
23+
propDefinition: [
24+
poper,
25+
"poperId",
26+
],
27+
},
28+
},
29+
methods: {
30+
_getLastId() {
31+
return this.db.get("lastId") || 0;
32+
},
33+
_setLastId(lastId) {
34+
this.db.set("lastId", lastId);
35+
},
36+
getParams() {
37+
return {};
38+
},
39+
async startEvent(maxResults = 0) {
40+
const lastId = this._getLastId();
41+
const { responses } = await this.poper.listPoperResponses({
42+
data: {
43+
popup_id: this.poperId,
44+
},
45+
});
46+
47+
const filteredResponse = responses.filter((item) => item.id > lastId);
48+
49+
if (filteredResponse.length) {
50+
if (maxResults && filteredResponse.length > maxResults) {
51+
filteredResponse.length = maxResults;
52+
}
53+
this._setLastId(filteredResponse[0].id);
54+
}
55+
56+
for (const item of filteredResponse.reverse()) {
57+
this.$emit( item, {
58+
id: item.id,
59+
summary: `New lead with Id: ${item.id}`,
60+
ts: Date.parse(item.time_stamp),
61+
});
62+
}
63+
},
64+
},
65+
hooks: {
66+
async deploy() {
67+
await this.startEvent(25);
68+
},
69+
},
70+
async run() {
71+
await this.startEvent();
72+
},
73+
sampleEmit,
74+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export default {
2+
"id": 6625,
3+
"popup_id": 1233,
4+
"time_stamp": "2024-07-05T16:22:23.830Z",
5+
"response": {
6+
"email": "[email protected]"
7+
},
8+
"system": {
9+
"page": "/",
10+
"referrer": "https://site.com.br/wp-admin/admin.php?page=poper-settings",
11+
"language": "pt-BR",
12+
"os": "Windows",
13+
"browser": "Chrome",
14+
"ip": "123.456.78.90",
15+
"city": "São Paulo",
16+
"country": "BR",
17+
"continent": "SA",
18+
"latitude": "-22.123421",
19+
"longitude": "-49.657476",
20+
"postal_code": "05040001",
21+
"region": "São Paulo",
22+
"region_code": "SP"
23+
}
24+
}

pnpm-lock.yaml

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)