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
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import surveybot from "../../surveybot.app.mjs";

export default {
key: "surveybot-get-survey-respondent",
name: "Get Survey Respondent",
description: "Get a respondent for a survey from SurveyBot. [See the documentation](https://app.surveybot.io/accounts/api_use_cases)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
surveybot,
surveyId: {
propDefinition: [
surveybot,
"surveyId",
],
},
respondentId: {
propDefinition: [
surveybot,
"respondentId",
({ surveyId }) => ({
surveyId,
}),
],
},
},
async run({ $ }) {
const respondent = await this.surveybot.getSurveyRespondent({
$,
respondentId: this.respondentId,
});

$.export("$summary", `Successfully retrieved respondent with ID: "${this.respondentId}" for survey with ID: "${this.surveyId}"`);
return respondent;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import surveybot from "../../surveybot.app.mjs";

export default {
key: "surveybot-get-survey-responses",
name: "Get Survey Responses",
description: "Get responses for a survey from SurveyBot. [See the documentation](https://app.surveybot.io/accounts/api_use_cases)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
surveybot,
surveyId: {
propDefinition: [
surveybot,
"surveyId",
],
},
},
async run({ $ }) {
const responses = await this.surveybot.getSurveyResponses({
$,
surveyId: this.surveyId,
});

$.export("$summary", `Successfully retrieved survey responses for survey with ID: "${this.surveyId}"`);
return responses;
},
};
42 changes: 42 additions & 0 deletions components/surveybot/actions/list-surveys/list-surveys.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import surveybot from "../../surveybot.app.mjs";

export default {
key: "surveybot-list-surveys",
name: "List Surveys",
description: "List all surveys from SurveyBot. [See the documentation](https://app.surveybot.io/accounts/api_use_cases)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
surveybot,
maxResults: {
type: "integer",
label: "Max Results",
description: "The maximum number of surveys to return",
default: 100,
optional: true,
},
},
async run({ $ }) {
const surveys = this.surveybot.paginate({
fn: this.surveybot.listSurveys,
$,
max: this.maxResults,
dataField: "surveys",
});

const results = [];
for await (const survey of surveys) {
results.push(survey);
}

$.export("$summary", `Successfully retrieved ${results.length} survey${results.length === 1
? ""
: "s"}`);
return results;
},
};
4 changes: 2 additions & 2 deletions components/surveybot/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/surveybot",
"version": "0.6.0",
"version": "0.7.0",
"description": "Pipedream surveybot Components",
"main": "surveybot.app.mjs",
"keywords": [
Expand All @@ -13,6 +13,6 @@
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.0"
"@pipedream/platform": "^3.1.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import surveybot from "../../surveybot.app.mjs";
import sampleEmit from "./test-event.mjs";

export default {
key: "surveybot-new-survey-response",
name: "New Survey Response",
description: "Emit new event when a new survey response is received. [See the documentation](https://app.surveybot.io/accounts/api_use_cases)",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
surveybot,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
surveyId: {
propDefinition: [
surveybot,
"surveyId",
],
},
},
methods: {
_getLastDate() {
return this.db.get("lastDate") || 0;
},
_setLastDate(lastDate) {
this.db.set("lastDate", lastDate);
},
async emitEvent(maxResults = false) {
const lastDate = this._getLastDate();
const data = await this.surveybot.getSurveyResponses({
surveyId: this.surveyId,
});

let responses = data.responses;

responses = responses.filter((response) => Date.parse(response.started_at) > lastDate);

if (responses.length) {
if (maxResults && (responses.length > maxResults)) {
responses.length = maxResults;
}
this._setLastDate(Date.parse(responses[0].started_at));
}

for (const item of responses.reverse()) {
this.$emit(item, {
id: item.id,
summary: `New response for survey ${this.surveyId} by ${item.respondent.name}`,
ts: Date.parse(item.started_at),
});
}
},
},
hooks: {
async deploy() {
await this.emitEvent(25);
},
},
async run() {
await this.emitEvent();
},
sampleEmit,
};
89 changes: 89 additions & 0 deletions components/surveybot/sources/new-survey-response/test-event.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
export default {
"completed":true,
"started_at":"03/11/2025 03:45 PM",
"completed_at":"03/11/2025 03:46 PM",
"id":"29360C9E3A5F5E8F61BFE425A3C8BC4E",
"respondent":{
"id":1789117,
"name":"John Doe",
"first_name":"John",
"last_name":"Doe",
"gender":"male",
"locale":"pt_BR",
"timezone":null,
"email":null,
"picture":null,
"date_of_birth":null,
"occupation":null,
"address":null,
"relationship_status":null,
"phone_number":null,
"mobile_number":null,
"tags":"",
"location":null,
"city":null,
"country":null,
"attributes":[

]
},
"quiz_score":0,
"answers":[
{
"question_id":217859,
"question_text":"content removed",
"content":null
},
{
"question_id":217860,
"question_text":"Which country is the largest producer of rubber?",
"content":"Thailand"
},
{
"question_id":217861,
"question_text":"content removed",
"content":null
},
{
"question_id":217862,
"question_text":"Which country is also known as the land of the rising sun?",
"content":"Japan"
},
{
"question_id":217863,
"question_text":"content removed",
"content":null
},
{
"question_id":217864,
"question_text":"In which country was Lord of the Rings filmed?",
"content":"New Zealand"
},
{
"question_id":217865,
"question_text":"content removed",
"content":null
},
{
"question_id":217866,
"question_text":"What was the name of Alexander's horse?",
"content":"Thunderbolt "
},
{
"question_id":217867,
"question_text":"content removed",
"content":null
},
{
"question_id":217868,
"question_text":"Which Shakespeare play does the line ''The lady doth protest too much, methinks'' come from?",
"content":"Macbeth"
},
{
"question_id":217869,
"question_text":"content removed",
"content":null
}
],
"shared_by_respondent":null
}
Loading
Loading