Skip to content

Commit a332e95

Browse files
committed
helpspot init
1 parent f8bcaa7 commit a332e95

File tree

7 files changed

+442
-6
lines changed

7 files changed

+442
-6
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import helpspot from "../../helpspot.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "helpspot-create-request",
6+
name: "Create Request",
7+
description: "Creates a new user request. At least one of the following props is needed: first name, last name, user id, email, or phone. [See the documentation](https://support.helpspot.com/index.php?pg=kb.page&id=163)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
helpspot,
12+
note: {
13+
type: "string",
14+
label: "Note",
15+
description: "The note content for the request",
16+
},
17+
firstName: {
18+
propDefinition: [
19+
helpspot,
20+
"firstName",
21+
],
22+
},
23+
lastName: {
24+
propDefinition: [
25+
helpspot,
26+
"lastName",
27+
],
28+
},
29+
userId: {
30+
propDefinition: [
31+
helpspot,
32+
"userId",
33+
],
34+
},
35+
email: {
36+
propDefinition: [
37+
helpspot,
38+
"email",
39+
],
40+
},
41+
phone: {
42+
propDefinition: [
43+
helpspot,
44+
"phone",
45+
],
46+
},
47+
},
48+
async run({ $ }) {
49+
if (!this.firstName && !this.lastName && !this.userId && !this.email && !this.phone) {
50+
throw new Error("You must provide at least one of the following: first name, last name, user ID, email, or phone.");
51+
}
52+
53+
const response = await this.helpspot.createRequest({
54+
note: this.note,
55+
firstName: this.firstName,
56+
lastName: this.lastName,
57+
userId: this.userId,
58+
email: this.email,
59+
phone: this.phone,
60+
});
61+
62+
$.export("$summary", `Successfully created request with access key: ${response.accesskey}`);
63+
return response;
64+
},
65+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import helpspot from "../../helpspot.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "helpspot-update-request",
6+
name: "Update Request",
7+
description: "Updates an existing user request. [See the documentation](https://support.helpspot.com/index.php?pg=kb.page&id=163)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
helpspot,
12+
xRequestId: {
13+
propDefinition: [
14+
helpspot,
15+
"xRequestId",
16+
],
17+
},
18+
note: {
19+
propDefinition: [
20+
helpspot,
21+
"note",
22+
],
23+
},
24+
},
25+
async run({ $ }) {
26+
const params = {
27+
xRequestId: this.xRequestId,
28+
note: this.note,
29+
};
30+
const response = await this.helpspot.updateRequest(params);
31+
$.export("$summary", `Successfully updated request with ID ${this.xRequestId}`);
32+
return response;
33+
},
34+
};
Lines changed: 127 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,133 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "helpspot",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
searchQuery: {
8+
type: "string",
9+
label: "Search Query",
10+
description: "The search query to search for requests",
11+
},
12+
requestId: {
13+
type: "string",
14+
label: "Request ID",
15+
description: "The ID of the request to update",
16+
},
17+
xRequestId: {
18+
type: "string",
19+
label: "XRequest ID",
20+
description: "The XRequest ID needed to identify the specific request that needs to be updated",
21+
},
22+
firstName: {
23+
type: "string",
24+
label: "First Name",
25+
description: "The first name of the user. Required if no other identification details are provided",
26+
optional: true,
27+
},
28+
lastName: {
29+
type: "string",
30+
label: "Last Name",
31+
description: "The last name of the user. Required if no other identification details are provided",
32+
optional: true,
33+
},
34+
userId: {
35+
type: "string",
36+
label: "User ID",
37+
description: "The user ID of the user. Required if no other identification details are provided",
38+
optional: true,
39+
},
40+
email: {
41+
type: "string",
42+
label: "Email",
43+
description: "The email of the user. Required if no other identification details are provided",
44+
optional: true,
45+
},
46+
phone: {
47+
type: "string",
48+
label: "Phone",
49+
description: "The phone number of the user. Required if no other identification details are provided",
50+
optional: true,
51+
},
52+
note: {
53+
type: "string",
54+
label: "Note",
55+
description: "The note content for the request",
56+
},
57+
accessKey: {
58+
type: "string",
59+
label: "Access Key",
60+
description: "The access key for the specific request",
61+
},
62+
},
563
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
64+
_baseUrl() {
65+
return "https://yourdomain.helpspot.com/api/index.php";
66+
},
67+
async _makeRequest(opts = {}) {
68+
const {
69+
$ = this, method = "GET", path = "/", headers, ...otherOpts
70+
} = opts;
71+
return axios($, {
72+
...otherOpts,
73+
method,
74+
url: this._baseUrl() + path,
75+
headers: {
76+
...headers,
77+
},
78+
});
79+
},
80+
async createRequest({
81+
note, firstName, lastName, userId, email, phone,
82+
}) {
83+
const params = new URLSearchParams();
84+
params.append("method", "request.create");
85+
params.append("tNote", note);
86+
if (firstName) params.append("sFirstName", firstName);
87+
if (lastName) params.append("sLastName", lastName);
88+
if (userId) params.append("sUserId", userId);
89+
if (email) params.append("sEmail", email);
90+
if (phone) params.append("sPhone", phone);
91+
return this._makeRequest({
92+
method: "POST",
93+
data: params,
94+
});
95+
},
96+
async updateRequest({
97+
xRequestId, note,
98+
}) {
99+
const params = new URLSearchParams();
100+
params.append("method", "request.update");
101+
params.append("accesskey", xRequestId);
102+
params.append("tNote", note);
103+
return this._makeRequest({
104+
method: "POST",
105+
data: params,
106+
});
107+
},
108+
async searchRequests({ searchQuery }) {
109+
const params = new URLSearchParams();
110+
params.append("method", "request.search");
111+
params.append("query", searchQuery);
112+
return this._makeRequest({
113+
method: "POST",
114+
data: params,
115+
});
116+
},
117+
async getRequest({ requestId }) {
118+
const params = new URLSearchParams();
119+
params.append("method", "request.get");
120+
params.append("accesskey", requestId);
121+
return this._makeRequest({
122+
method: "GET",
123+
params,
124+
});
125+
},
126+
async emitNewRequest() {
127+
// Implementation to poll for new requests or subscribe to webhooks if supported.
128+
},
129+
async emitUpdatedRequest({ requestId }) {
130+
// Implementation to poll for updated requests or subscribe to webhooks if supported.
9131
},
10132
},
11-
};
133+
};

components/helpspot/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import helpspot from "../../helpspot.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "helpspot-new-request",
6+
name: "New Request Created",
7+
description: "Emit new event when a new request is created. [See the documentation](https://support.helpspot.com/index.php?pg=kb.page&id=163)",
8+
version: "0.0.{{ts}}",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
helpspot,
13+
db: "$.service.db",
14+
timer: {
15+
type: "$.interface.timer",
16+
default: {
17+
intervalSeconds: 60,
18+
},
19+
},
20+
},
21+
methods: {
22+
_getLastRequestId() {
23+
return this.db.get("lastRequestId") || null;
24+
},
25+
_setLastRequestId(id) {
26+
this.db.set("lastRequestId", id);
27+
},
28+
async emitNewRequests() {
29+
const lastRequestId = this._getLastRequestId();
30+
const searchQuery = lastRequestId
31+
? `xRequest>${lastRequestId}`
32+
: "Date_Created:[* TO NOW]";
33+
34+
const newRequests = await this.helpspot.searchRequests({
35+
searchQuery,
36+
});
37+
38+
for (const request of newRequests) {
39+
this.$emit(request, {
40+
id: request.xRequest,
41+
summary: `New Request: ${request.xRequest}`,
42+
ts: Date.parse(request.dtGMTOpened),
43+
});
44+
}
45+
46+
if (newRequests.length) {
47+
this._setLastRequestId(newRequests[newRequests.length - 1].xRequest);
48+
}
49+
},
50+
},
51+
hooks: {
52+
async deploy() {
53+
await this.emitNewRequests();
54+
},
55+
async activate() {
56+
await this.emitNewRequests();
57+
},
58+
async deactivate() {
59+
// Clean up any resources if needed
60+
},
61+
},
62+
async run() {
63+
await this.emitNewRequests();
64+
},
65+
};
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { axios } from "@pipedream/platform";
2+
import helpspot from "../../helpspot.app.mjs";
3+
4+
export default {
5+
key: "helpspot-new-search",
6+
name: "New Search Event",
7+
description: "Emit new event based on a search. [See the documentation](https://support.helpspot.com/index.php?pg=kb.page&id=163)",
8+
version: "0.0.{{ts}}",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
helpspot,
13+
db: "$.service.db",
14+
searchQuery: {
15+
propDefinition: [
16+
helpspot,
17+
"searchQuery",
18+
],
19+
},
20+
timer: {
21+
type: "$.interface.timer",
22+
label: "Poll Schedule",
23+
description: "Pipedream will poll the HelpSpot API on this schedule",
24+
default: {
25+
intervalSeconds: 3600,
26+
},
27+
},
28+
},
29+
methods: {
30+
_getLastSearchId() {
31+
return this.db.get("lastSearchId") || null;
32+
},
33+
_setLastSearchId(id) {
34+
this.db.set("lastSearchId", id);
35+
},
36+
},
37+
hooks: {
38+
async deploy() {
39+
const results = await this.helpspot.searchRequests({
40+
searchQuery: this.searchQuery,
41+
});
42+
const lastResult = results[results.length - 1];
43+
44+
if (lastResult) {
45+
this._setLastSearchId(lastResult.xRequest);
46+
}
47+
48+
for (const result of results.slice(0, 50)) {
49+
this.$emit(result, {
50+
id: result.xRequest,
51+
summary: `New request: ${result.sTitle || result.sFirstName || result.sLastName || result.tNote}`,
52+
ts: Date.parse(result.dtGMTOpened),
53+
});
54+
}
55+
},
56+
},
57+
async run() {
58+
const lastSearchId = this._getLastSearchId();
59+
const results = await this.helpspot.searchRequests({
60+
searchQuery: this.searchQuery,
61+
});
62+
63+
for (const result of results) {
64+
if (!lastSearchId || result.xRequest > lastSearchId) {
65+
this.$emit(result, {
66+
id: result.xRequest,
67+
summary: `New request: ${result.sTitle || result.sFirstName || result.sLastName || result.tNote}`,
68+
ts: Date.parse(result.dtGMTOpened),
69+
});
70+
}
71+
}
72+
73+
const newLastResult = results[results.length - 1];
74+
if (newLastResult) {
75+
this._setLastSearchId(newLastResult.xRequest);
76+
}
77+
},
78+
};

0 commit comments

Comments
 (0)