Skip to content

Commit 25307c0

Browse files
authored
13281 components surveybot (#18940)
* Implement SurveyBot actions and update package version * pnpm update * Remove unused getSurvey method and add New Survey Response source with event emission capabilities * Update package version for @pipedream/surveybot to 0.7.0
1 parent 69b4d8c commit 25307c0

File tree

8 files changed

+385
-8
lines changed

8 files changed

+385
-8
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import surveybot from "../../surveybot.app.mjs";
2+
3+
export default {
4+
key: "surveybot-get-survey-respondent",
5+
name: "Get Survey Respondent",
6+
description: "Get a respondent for a survey from SurveyBot. [See the documentation](https://app.surveybot.io/accounts/api_use_cases)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
surveybot,
16+
surveyId: {
17+
propDefinition: [
18+
surveybot,
19+
"surveyId",
20+
],
21+
},
22+
respondentId: {
23+
propDefinition: [
24+
surveybot,
25+
"respondentId",
26+
({ surveyId }) => ({
27+
surveyId,
28+
}),
29+
],
30+
},
31+
},
32+
async run({ $ }) {
33+
const respondent = await this.surveybot.getSurveyRespondent({
34+
$,
35+
respondentId: this.respondentId,
36+
});
37+
38+
$.export("$summary", `Successfully retrieved respondent with ID: "${this.respondentId}" for survey with ID: "${this.surveyId}"`);
39+
return respondent;
40+
},
41+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import surveybot from "../../surveybot.app.mjs";
2+
3+
export default {
4+
key: "surveybot-get-survey-responses",
5+
name: "Get Survey Responses",
6+
description: "Get responses for a survey from SurveyBot. [See the documentation](https://app.surveybot.io/accounts/api_use_cases)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
surveybot,
16+
surveyId: {
17+
propDefinition: [
18+
surveybot,
19+
"surveyId",
20+
],
21+
},
22+
},
23+
async run({ $ }) {
24+
const responses = await this.surveybot.getSurveyResponses({
25+
$,
26+
surveyId: this.surveyId,
27+
});
28+
29+
$.export("$summary", `Successfully retrieved survey responses for survey with ID: "${this.surveyId}"`);
30+
return responses;
31+
},
32+
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import surveybot from "../../surveybot.app.mjs";
2+
3+
export default {
4+
key: "surveybot-list-surveys",
5+
name: "List Surveys",
6+
description: "List all surveys from SurveyBot. [See the documentation](https://app.surveybot.io/accounts/api_use_cases)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
surveybot,
16+
maxResults: {
17+
type: "integer",
18+
label: "Max Results",
19+
description: "The maximum number of surveys to return",
20+
default: 100,
21+
optional: true,
22+
},
23+
},
24+
async run({ $ }) {
25+
const surveys = this.surveybot.paginate({
26+
fn: this.surveybot.listSurveys,
27+
$,
28+
max: this.maxResults,
29+
dataField: "surveys",
30+
});
31+
32+
const results = [];
33+
for await (const survey of surveys) {
34+
results.push(survey);
35+
}
36+
37+
$.export("$summary", `Successfully retrieved ${results.length} survey${results.length === 1
38+
? ""
39+
: "s"}`);
40+
return results;
41+
},
42+
};

components/surveybot/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/surveybot",
3-
"version": "0.6.0",
3+
"version": "0.7.0",
44
"description": "Pipedream surveybot Components",
55
"main": "surveybot.app.mjs",
66
"keywords": [
@@ -13,6 +13,6 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^3.0.0"
16+
"@pipedream/platform": "^3.1.0"
1717
}
1818
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
2+
import surveybot from "../../surveybot.app.mjs";
3+
import sampleEmit from "./test-event.mjs";
4+
5+
export default {
6+
key: "surveybot-new-survey-response",
7+
name: "New Survey Response",
8+
description: "Emit new event when a new survey response is received. [See the documentation](https://app.surveybot.io/accounts/api_use_cases)",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
props: {
13+
surveybot,
14+
db: "$.service.db",
15+
timer: {
16+
type: "$.interface.timer",
17+
default: {
18+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
19+
},
20+
},
21+
surveyId: {
22+
propDefinition: [
23+
surveybot,
24+
"surveyId",
25+
],
26+
},
27+
},
28+
methods: {
29+
_getLastDate() {
30+
return this.db.get("lastDate") || 0;
31+
},
32+
_setLastDate(lastDate) {
33+
this.db.set("lastDate", lastDate);
34+
},
35+
async emitEvent(maxResults = false) {
36+
const lastDate = this._getLastDate();
37+
const data = await this.surveybot.getSurveyResponses({
38+
surveyId: this.surveyId,
39+
});
40+
41+
let responses = data.responses;
42+
43+
responses = responses.filter((response) => Date.parse(response.started_at) > lastDate);
44+
45+
if (responses.length) {
46+
if (maxResults && (responses.length > maxResults)) {
47+
responses.length = maxResults;
48+
}
49+
this._setLastDate(Date.parse(responses[0].started_at));
50+
}
51+
52+
for (const item of responses.reverse()) {
53+
this.$emit(item, {
54+
id: item.id,
55+
summary: `New response for survey ${this.surveyId} by ${item.respondent.name}`,
56+
ts: Date.parse(item.started_at),
57+
});
58+
}
59+
},
60+
},
61+
hooks: {
62+
async deploy() {
63+
await this.emitEvent(25);
64+
},
65+
},
66+
async run() {
67+
await this.emitEvent();
68+
},
69+
sampleEmit,
70+
};
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
export default {
2+
"completed":true,
3+
"started_at":"03/11/2025 03:45 PM",
4+
"completed_at":"03/11/2025 03:46 PM",
5+
"id":"29360C9E3A5F5E8F61BFE425A3C8BC4E",
6+
"respondent":{
7+
"id":1789117,
8+
"name":"John Doe",
9+
"first_name":"John",
10+
"last_name":"Doe",
11+
"gender":"male",
12+
"locale":"pt_BR",
13+
"timezone":null,
14+
"email":null,
15+
"picture":null,
16+
"date_of_birth":null,
17+
"occupation":null,
18+
"address":null,
19+
"relationship_status":null,
20+
"phone_number":null,
21+
"mobile_number":null,
22+
"tags":"",
23+
"location":null,
24+
"city":null,
25+
"country":null,
26+
"attributes":[
27+
28+
]
29+
},
30+
"quiz_score":0,
31+
"answers":[
32+
{
33+
"question_id":217859,
34+
"question_text":"content removed",
35+
"content":null
36+
},
37+
{
38+
"question_id":217860,
39+
"question_text":"Which country is the largest producer of rubber?",
40+
"content":"Thailand"
41+
},
42+
{
43+
"question_id":217861,
44+
"question_text":"content removed",
45+
"content":null
46+
},
47+
{
48+
"question_id":217862,
49+
"question_text":"Which country is also known as the land of the rising sun?",
50+
"content":"Japan"
51+
},
52+
{
53+
"question_id":217863,
54+
"question_text":"content removed",
55+
"content":null
56+
},
57+
{
58+
"question_id":217864,
59+
"question_text":"In which country was Lord of the Rings filmed?",
60+
"content":"New Zealand"
61+
},
62+
{
63+
"question_id":217865,
64+
"question_text":"content removed",
65+
"content":null
66+
},
67+
{
68+
"question_id":217866,
69+
"question_text":"What was the name of Alexander's horse?",
70+
"content":"Thunderbolt "
71+
},
72+
{
73+
"question_id":217867,
74+
"question_text":"content removed",
75+
"content":null
76+
},
77+
{
78+
"question_id":217868,
79+
"question_text":"Which Shakespeare play does the line ''The lady doth protest too much, methinks'' come from?",
80+
"content":"Macbeth"
81+
},
82+
{
83+
"question_id":217869,
84+
"question_text":"content removed",
85+
"content":null
86+
}
87+
],
88+
"shared_by_respondent":null
89+
}

0 commit comments

Comments
 (0)