import { ConfigurationError } from "@pipedream/platform";
import { parseObject } from "../../common/utils.mjs";
import robly from "../../robly.app.mjs";
export default {
key: "robly-create-contact",
name: "Create Contact",
description: "Create a new contact in Robly. [See the documentation](https://docs.robly.com/docs/api-v1/441cf0bf51a98-generate-a-signup)",
type: "action",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: false,
},
props: {
robly,
email: {
type: "string",
label: "Email",
description: "Email address of the contact",
},
autogenerateFields: {
type: "boolean",
label: "Autogenerate Fields",
description: "When true, field tags will be autogenerated based on the parameters sent into the request",
optional: true,
},
doubleOptIn: {
type: "boolean",
label: "Double Opt-In",
description: "When true, the welcome email will be sent to the member",
optional: true,
},
fieldTags: {
type: "object",
label: "Field Tags",
description: `The field tags are sent in as parameters based on the name of the field. These fields are configured when your account is setup, and should correspond to fields that already exist in the account configuration.
\nFor example, if you have a custom field for \`color\`, you would send in the parameter \`{"color": "purple"}\` to set the field to purple for the user. Note that all parameter names for fields should be in lower case.
\nInvalid fields will be ignored, and could throw an HTTP 500 server error.`,
optional: true,
},
includeAutomations: {
type: "boolean",
label: "Include Automations",
description: "When true, automations are updated with the new member",
optional: true,
},
includeAutoresponder: {
type: "boolean",
label: "Include Autoresponder",
description: "When true, sends the autoresponder email on the sub_lists that the new member has been subscribed to",
optional: true,
},
subLists: {
propDefinition: [
robly,
"listId",
],
type: "integer[]",
label: "Sub Lists",
description: "Array of sub-list IDs to add the contact to",
optional: true,
},
welcomeEmail: {
type: "boolean",
label: "Welcome Email",
description: "When true, the welcome email for the sign up process is sent",
optional: true,
},
},
async run({ $ }) {
const params = {
...(parseObject(this.fieldTags) || {}),
email: this.email,
autogenerate_fields: this.autogenerateFields,
double_opt_in: this.doubleOptIn,
include_automations: this.includeAutomations,
include_autoresponder: this.includeAutoresponder,
welcome_email: this.welcomeEmail,
sub_lists: parseObject(this.subLists),
return_contact: true,
include_fields: true,
};
const response = await this.robly.createContact({
$,
params,
});
if (response.member) {
$.export("$summary", `Successfully created contact with ID: ${response.member.id}`);
} else {
throw new ConfigurationError(response.message);
}
return response;
},
};