Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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.1.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"
}
}
117 changes: 113 additions & 4 deletions components/surveybot/surveybot.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,120 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "surveybot",
propDefinitions: {},
propDefinitions: {
surveyId: {
type: "string",
label: "Survey ID",
description: "The ID of the survey to get responses for",
async options({ page }) {
const { surveys } = await this.listSurveys({
params: {
page: page + 1,
},
});
return surveys.map(({
id: value, name: label,
}) => ({
label,
value,
}));
},
},
respondentId: {
type: "string",
label: "Respondent ID",
description: "The ID of the respondent to get",
async options({ surveyId }) {
const { responses } = await this.getSurveyResponses({
surveyId,
});

return responses.map(({
respondent: {
id: value,
name: label,
},
}) => ({
label,
value,
}));
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_apiUrl() {
return "https://surveybot.io/api/v1";
},
_getHeaders() {
return {
"X-Api-Key": `${this.$auth.api_key}`,
};
},
_makeRequest({
$ = this, path, ...opts
}) {
return axios($, {
url: `${this._apiUrl()}/${path}`,
headers: this._getHeaders(),
...opts,
});
},
listSurveys(args = {}) {
return this._makeRequest({
path: "surveys",
...args,
});
},
getSurvey(args = {}) {
return this._makeRequest({
path: "surveys",
...args,
});
},
getSurveyResponses({
surveyId, ...args
}) {
return this._makeRequest({
path: `surveys/${surveyId}/responses`,
...args,
});
},
getSurveyRespondent({
respondentId, ...args
}) {
return this._makeRequest({
path: `respondents/${respondentId}`,
...args,
});
},
async *paginate({
fn, params = {}, maxResults = null, dataField, ...opts
}) {
let hasMore = false;
let count = 0;
let page = 0;

do {
params.page = ++page;
const response = await fn({
params,
...opts,
});

const data = response[dataField];
for (const d of data) {
yield d;

if (maxResults && ++count === maxResults) {
return count;
}
}

hasMore = data.length;

} while (hasMore);
},
},
};
Loading
Loading