-
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 3 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
70 changes: 70 additions & 0 deletions
70
components/surveybot/sources/new-survey-response/new-survey-response.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,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
89
components/surveybot/sources/new-survey-response/test-event.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,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 | ||
| } |
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.