-
Notifications
You must be signed in to change notification settings - Fork 5.6k
13281 components surveybot #18940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
13281 components surveybot #18940
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7725901
Implement SurveyBot actions and update package version
luancazarine 09ad4db
pnpm update
luancazarine e7729b8
Remove unused getSurvey method and add New Survey Response source wit…
luancazarine 3adb165
Update package version for @pipedream/surveybot to 0.7.0
luancazarine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
components/surveybot/actions/get-survey-respondent/get-survey-respondent.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| }, | ||
| }; |
32 changes: 32 additions & 0 deletions
32
components/surveybot/actions/get-survey-responses/get-survey-responses.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
42
components/surveybot/actions/list-surveys/list-surveys.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| })); | ||
| }, | ||
| }, | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| 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, | ||
| }); | ||
| }, | ||
luancazarine marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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); | ||
| }, | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.