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,98 @@
import { ConfigurationError } from "@pipedream/platform";
import surveyMonkey from "../../survey_monkey.app.mjs";
import base from "../common/base-survey.mjs";
import { parseObjectArray } from "../../common/utils.mjs";

export default {
...base,
key: "survey_monkey-add-message-recipients",
name: "Add Message Recipients",
description: "Add recipients to an invite message, from new contacts, existing contact IDs, contact lists, or any combination. Uses the bulk endpoint, so nothing is re-added: a recipient already on the message or collector comes back under `existing`, while `duplicate` reports addresses repeated within this one request. [See the documentation](https://api.surveymonkey.com/v3/docs?javascript#api-endpoints-post-collectors-collector_id-messages-message_id-recipients-bulk)",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: false,
},
type: "action",
props: {
...base.props,
collectorId: {
propDefinition: [
surveyMonkey,
"collectorId",
(c) => ({
surveyId: c.survey,
}),
],
},
messageId: {
propDefinition: [
surveyMonkey,
"messageId",
],
description: "The ID of the invite message to add recipients to. Run **List Invite Messages** to find valid message IDs, or use the `id` returned by **Create Invite Message**.",
},
contacts: {
type: "string[]",
label: "Contacts",
description: "New contacts to add, each a JSON object. Email is required for email collectors and phone number for SMS collectors. **Example:** `{\"email\": \"jane@example.com\", \"first_name\": \"Jane\", \"last_name\": \"Doe\"}` or `{\"phone_number\": \"+1 202 555 0156\"}`. Careful with `custom_fields`: if any one contact supplies them, SurveyMonkey clears the existing custom fields of every other contact in the same call that does not.",
optional: true,
},
contactIds: {
type: "string[]",
label: "Contact IDs",
description: "IDs of existing SurveyMonkey contacts to add as recipients, e.g. `[\"123456\"]`. Contacts live in your SurveyMonkey address book rather than in this action — find their IDs at `GET /v3/contacts`, which returns an `id` per contact, or in the `succeeded[].id` values a previous run of this action returned.",
optional: true,
},
contactListIds: {
type: "string[]",
label: "Contact List IDs",
description: "IDs of existing contact lists whose contacts should be added as recipients, e.g. `[\"123456\"]`. Contact lists are managed in SurveyMonkey rather than here — find their IDs at `GET /v3/contact_lists`, or in the list's URL in the SurveyMonkey UI.",
optional: true,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
},
},
async run({ $ }) {
const {
contactIds, contactListIds,
} = this;
const contacts = parseObjectArray(this.contacts, "Contacts");

if (!contacts?.length && !contactIds?.length && !contactListIds?.length) {
throw new ConfigurationError("Set at least one of **Contacts**, **Contact IDs**, or **Contact List IDs**.");
}

const response = await this.surveyMonkey.addMessageRecipients({
$,
collectorId: this.collectorId,
messageId: this.messageId,
data: {
contacts,
contact_ids: contactIds,
contact_list_ids: contactListIds,
},
});

// The endpoint answers 200 even when every recipient was rejected, sorting
// them into per-reason buckets, so the counts are the only signal that a
// send will actually reach anyone.
const skipped = [
"invalids",
"existing",
"bounced",
"opted_out",
"duplicate",
]
.map((bucket) => response?.[bucket]?.length
? `${response[bucket].length} ${bucket.replace("_", " ")}`
: null)
.filter(Boolean)
.join(", ");

$.export("$summary", `Successfully added ${response?.succeeded?.length ?? 0} recipient(s)${skipped
? `; skipped ${skipped}`
: ""}`);

return response;
},
};
126 changes: 126 additions & 0 deletions components/survey_monkey/actions/create-collector/create-collector.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import base from "../common/base-survey.mjs";
import constants from "../../common/constants.mjs";

export default {
...base,
key: "survey_monkey-create-collector",
name: "Create Collector",
description: "Create a collector for a survey. A collector is the channel responses come in through — an SMS or email invitation, a web link, or a popup. [See the documentation](https://api.surveymonkey.com/v3/docs?javascript#api-endpoints-post-surveys-survey_id-collectors)",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: false,
},
type: "action",
props: {
...base.props,
type: {
type: "string",
label: "Type",
description: "The kind of collector to create. Every type except **Web link** requires a paid SurveyMonkey plan.",
options: constants.COLLECTOR_TYPES,
},
name: {
type: "string",
label: "Name",
description: "A nickname for the collector.",
},
senderEmail: {
type: "string",
label: "Sender Email",
description: "Sender email for email collectors. The address must be verified in your SurveyMonkey account before invitations will send.",
optional: true,
},
thankYouMessage: {
type: "string",
label: "Thank You Message",
description: "Message shown on the thank you page once a respondent completes the survey. SurveyMonkey treats this as the older form of `thank_you_page` and recommends that object instead — pass it through **Additional Options** to use it.",
optional: true,
},
closedPageMessage: {
type: "string",
label: "Closed Page Message",
description: "Message shown once the survey is closed.",
optional: true,
},
redirectUrl: {
type: "string",
label: "Redirect URL",
description: "Redirect respondents to this URL on survey completion.",
optional: true,
},
closeDate: {
type: "string",
label: "Close Date",
description: "When the collector should close, e.g. `2026-12-03T10:15:30+00:00`.",
optional: true,
},
responseLimit: {
type: "integer",
label: "Response Limit",
description: "Close the collector after this many responses.",
optional: true,
},
anonymousType: {
type: "string",
label: "Anonymous Type",
description: "Turns off IP tracking. For email collectors it also removes the respondent's email address and name from the response.",
options: constants.ANONYMOUS_TYPES,
optional: true,
},
editResponseType: {
type: "string",
label: "Edit Response Type",
description: "When respondents can edit their response.",
options: constants.EDIT_RESPONSE_TYPES,
optional: true,
},
isBrandingEnabled: {
type: "boolean",
label: "Is Branding Enabled",
description: "Whether the popup has SurveyMonkey branding. Only applies to popup collectors.",
optional: true,
},
additionalOptions: {
type: "object",
label: "Additional Options",
description: "Any other collector option to send in the request body, e.g. `{\"thank_you_page\": {\"is_enabled\": true, \"message\": \"Thanks!\"}}` or the popup-only `width`/`height`/`sample_rate` settings. See the documentation for the full list. Note that values typed directly into this field arrive as strings, so pass booleans and numbers from a previous step or an expression when the API expects those types.",
optional: true,
},
},
async run({ $ }) {
const declared = {
type: this.type,
name: this.name,
sender_email: this.senderEmail,
thank_you_message: this.thankYouMessage,
closed_page_message: this.closedPageMessage,
redirect_url: this.redirectUrl,
close_date: this.closeDate,
response_limit: this.responseLimit,
anonymous_type: this.anonymousType,
edit_response_type: this.editResponseType,
is_branding_enabled: this.isBrandingEnabled,
};

const response = await this.surveyMonkey.createCollector({
$,
surveyId: this.survey,
data: {
...this.additionalOptions,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
// Declared props take precedence over Additional Options, but only
// where one was actually set: an unset optional prop is `undefined`,
// and letting that through would drop the matching Additional Options
// key from the serialized body instead of leaving it alone.
...Object.fromEntries(Object.entries(declared).filter(([
,
value,
]) => value !== undefined)),
},
});

$.export("$summary", `Successfully created ${this.type} collector "${this.name}"`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import { ConfigurationError } from "@pipedream/platform";
import surveyMonkey from "../../survey_monkey.app.mjs";
import base from "../common/base-survey.mjs";
import constants from "../../common/constants.mjs";

export default {
...base,
key: "survey_monkey-create-invite-message",
name: "Create Invite Message",
description: "Create an invite message on an email or SMS collector. Add recipients with **Add Message Recipients**, then deliver it with **Send Invite Message**. [See the documentation](https://api.surveymonkey.com/v3/docs?javascript#api-endpoints-post-collectors-collector_id-messages)",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: false,
},
type: "action",
props: {
...base.props,
collectorId: {
propDefinition: [
surveyMonkey,
"collectorId",
(c) => ({
surveyId: c.survey,
}),
],
},
type: {
type: "string",
label: "Type",
description: "The type of message to create. Use `sms` for SMS collectors and `invite` for email collectors.",
options: constants.MESSAGE_TYPES,
default: "invite",
optional: true,
},
subject: {
type: "string",
label: "Subject",
description: "Subject line of the email message. Not used for SMS messages.",
optional: true,
},
bodyText: {
type: "string",
label: "Body Text",
description: "The plain text body of the message, and the only body an SMS message can use. SurveyMonkey advises keeping an SMS body to 30 characters or fewer, including spaces, so the invitation stays a single text. Include the `[SurveyLink]` placeholder, or recipients get an invitation with no way to reach the survey. Per SurveyMonkey's Anti-Spam Policy the `[OptOutLink]` must stay visible and its purpose clearly explained.",
optional: true,
},
bodyHtml: {
type: "string",
label: "Body HTML",
description: "The HTML body of an email message, and email-only — it does not apply to `sms` messages, and it overrides **Body Text** when both are set. The same placeholders apply as for **Body Text** — `[SurveyLink]`, `[OptOutLink]`, `[PrivacyLink]` and `[FooterLink]` — and the Anti-Spam Policy requires that the opt-out link stay visible rather than being hidden in the markup.",
optional: true,
},
fromMessageId: {
propDefinition: [
surveyMonkey,
"messageId",
],
label: "Copy From Message",
description: "The ID of an existing message on this collector to copy the new message from, e.g. to reuse a template. Run **List Invite Messages** to find valid message IDs.",
optional: true,
},
fromCollectorId: {
type: "string",
label: "Copy From Collector ID",
description: "Copy the message from the most recent message on another collector.",
optional: true,
},
includeRecipients: {
type: "boolean",
label: "Include Recipients",
description: "Whether to copy the recipients of the message being copied from.",
optional: true,
},
recipientStatus: {
type: "string",
label: "Recipient Status",
description: "The set of recipients to send to.",
options: [
"reminder",
"thank_you",
],
optional: true,
},
embedFirstQuestion: {
type: "boolean",
label: "Embed First Question",
description: "Whether to embed the survey's first question in an email invitation.",
optional: true,
},
isBrandingEnabled: {
type: "boolean",
label: "Is Branding Enabled",
description: "Whether SurveyMonkey branding is shown in the message.",
optional: true,
},
},
async run({ $ }) {
const {
type, subject, bodyText, bodyHtml, fromMessageId, fromCollectorId,
} = this;

const isCopy = !!(fromMessageId || fromCollectorId);

// `body_html` is documented as the HTML body of the *email* message, so it
// cannot carry an SMS's content — accepting it alone for `sms` would send a
// message with nothing in it.
if (!isCopy && type === "sms" && !bodyText) {
throw new ConfigurationError("An SMS message needs **Body Text** — **Body HTML** applies to email messages only. Alternatively, copy an existing message with **Copy From Message** or **Copy From Collector ID**.");
}

if (!isCopy && type !== "sms" && !bodyText && !bodyHtml) {
throw new ConfigurationError("Set **Body Text** or **Body HTML**, or copy an existing message with **Copy From Message** or **Copy From Collector ID**.");
}

const response = await this.surveyMonkey.createMessage({
$,
collectorId: this.collectorId,
data: {
type,
subject,
body_text: bodyText,
body_html: bodyHtml,
from_message_id: fromMessageId,
from_collector_id: fromCollectorId,
include_recipients: this.includeRecipients,
recipient_status: this.recipientStatus,
embed_first_question: this.embedFirstQuestion,
is_branding_enabled: this.isBrandingEnabled,
},
});

$.export("$summary", `Successfully created ${type} message${response.subject
? ` "${response.subject}"`
: ` #${response.id}`}`);
return response;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "survey_monkey-find-survey",
name: "Get Survey Details",
description: "Get details for a Survey. [See the docs here](https://developer.surveymonkey.com/api/v3/#api-endpoints-get-surveys-id-details)",
version: "0.0.4",
version: "0.0.5",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
name: "Get Collector Details",
description:
"Get details for a Collector. [See the docs here](https://api.surveymonkey.net/v3/docs?javascript#api-endpoints-get-collectors-id-)",
version: "0.0.3",
version: "0.0.4",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
name: "Get My Info",
description:
"Retrieve your account details. [See the docs here](https://api.surveymonkey.net/v3/docs?javascript#api-endpoints-get-users-me)",
version: "0.0.3",
version: "0.0.4",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand Down
Loading
Loading