-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New Components - acymailing #12377
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
New Components - acymailing #12377
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
77 changes: 77 additions & 0 deletions
77
components/acymailing/actions/add-update-user/add-update-user.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,77 @@ | ||
| import acymailing from "../../acymailing.app.mjs"; | ||
| import { parseObject } from "../../common/utils.mjs"; | ||
|
|
||
| export default { | ||
| key: "acymailing-add-update-user", | ||
| name: "Add or Update User", | ||
| description: "Creates a new user or updates an existing user in AcyMailing. If the user exists, will update the user's data with provided information. [See the documentation](https://docs.acymailing.com/v/rest-api/users#create-or-update-a-user)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| acymailing, | ||
| email: { | ||
| type: "string", | ||
| label: "Email", | ||
| description: "The email address is used when updating an existing user.", | ||
| }, | ||
| name: { | ||
| type: "string", | ||
| label: "Name", | ||
| description: "Any character should be available.", | ||
| optional: true, | ||
| }, | ||
| active: { | ||
| type: "boolean", | ||
| label: "Active", | ||
| description: "Defaults to true.", | ||
| optional: true, | ||
| }, | ||
| confirmed: { | ||
| type: "boolean", | ||
| label: "Confirmed", | ||
| description: "The confirmation is related to the \"Require confirmation\" option in the configuration, tab \"Subscription\".", | ||
| optional: true, | ||
| }, | ||
| cmsId: { | ||
| type: "integer", | ||
| label: "CMS Id", | ||
| description: "The cms_id must match the ID of the corresponding Joomla/WordPress user.", | ||
| optional: true, | ||
| }, | ||
| customFields: { | ||
| type: "object", | ||
| label: "Custom Fields", | ||
| description: "An object of field Ids and values.", | ||
| optional: true, | ||
| }, | ||
| triggers: { | ||
| type: "boolean", | ||
| label: "Triggers", | ||
| description: "Defaults to true. Defines if the saving of the user triggers automated tasks like follow-up campaigns and automations.", | ||
| optional: true, | ||
| }, | ||
| sendConf: { | ||
| type: "boolean", | ||
| label: "Send Conf", | ||
| description: "Defaults to true. Defines if the confirmation email should be sent when a new user is created.", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.acymailing.createUserOrUpdate({ | ||
| $, | ||
| data: { | ||
| email: this.email, | ||
| name: this.name, | ||
| active: this.active, | ||
| confirmed: this.confirmed, | ||
| cmsId: this.cmsId, | ||
| customFields: parseObject(this.customFields), | ||
| triggers: this.triggers, | ||
| sendConf: this.sendConf, | ||
| }, | ||
| }); | ||
| $.export("$summary", `Successfully added or updated user with email with Id: ${response.userId}`); | ||
| return response; | ||
| }, | ||
| }; |
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,55 @@ | ||
| import acymailing from "../../acymailing.app.mjs"; | ||
| import { parseObject } from "../../common/utils.mjs"; | ||
|
|
||
| export default { | ||
| key: "acymailing-email-user", | ||
| name: "Email User", | ||
| description: "Sends an email to a single AcyMailing user. The user must exist in the AcyMailing database. [See the documentation](https://docs.acymailing.com/v/rest-api/emails#send-an-email-to-a-user)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| acymailing, | ||
| email: { | ||
| type: "string", | ||
| label: "Email", | ||
| description: "The email address of the receiver.", | ||
| }, | ||
| autoAddUser: { | ||
| type: "boolean", | ||
| label: "Auto Add User", | ||
| description: "Defaults to false. If the email address doesn't match an existing AcyMailing user, one will be automatically created if this option is set to true.", | ||
| optional: true, | ||
| }, | ||
| emailId: { | ||
| type: "integer", | ||
| label: "Email Id", | ||
| description: "The mail ID to send. This is not a campaign ID but the mail ID of the table xxx_acym_mail in the database, or the mail_id of a campaign.", | ||
| }, | ||
| trackEmail: { | ||
| type: "boolean", | ||
| label: "Track Email", | ||
| description: "Defaults to true. If true, the open/click statistics will be collected for this email.", | ||
| optional: true, | ||
| }, | ||
| params: { | ||
| type: "object", | ||
| label: "Params", | ||
| description: "An object of shortcodes and values to replace in the body of the sent email. Example: { \"shortcode1\": \"value 1\" }. If the body of the sent email contains the text \"{shortcode1}\", it will be replaced by \"value 1\" in the sent version.", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.acymailing.sendEmailToUser({ | ||
| $, | ||
| data: { | ||
| email: this.email, | ||
| autoAddUser: this.autoAddUser, | ||
| emailId: this.emailId, | ||
| trackEmail: this.trackEmail, | ||
| params: parseObject(this.params), | ||
| }, | ||
| }); | ||
| $.export("$summary", `Email successfully sent to ${this.email}`); | ||
| return response; | ||
| }, | ||
| }; |
51 changes: 51 additions & 0 deletions
51
components/acymailing/actions/subscribe-user/subscribe-user.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,51 @@ | ||
| import acymailing from "../../acymailing.app.mjs"; | ||
| import { parseObject } from "../../common/utils.mjs"; | ||
|
|
||
| export default { | ||
| key: "acymailing-subscribe-user", | ||
| name: "Subscribe User to Lists", | ||
| description: "Subscribes a user to one or more specified lists in AcyMailing. [See the documentation](https://docs.acymailing.com/v/rest-api/subscription#subscribe-users-to-lists)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| acymailing, | ||
| emails: { | ||
| propDefinition: [ | ||
| acymailing, | ||
| "emails", | ||
| ], | ||
| }, | ||
| listIds: { | ||
| propDefinition: [ | ||
| acymailing, | ||
| "listIds", | ||
| ], | ||
| }, | ||
| sendWelcomeEmail: { | ||
| type: "boolean", | ||
| label: "Send Welcome Email", | ||
| description: "Defaults to true. If true, the welcome emails will be sent if the lists have one.", | ||
| optional: true, | ||
| }, | ||
| trigger: { | ||
| type: "boolean", | ||
| label: "Trigger", | ||
| description: "Defaults to true. If you want to trigger or not the automation or follow-up when subscribing the user.", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.acymailing.subscribeUserToLists({ | ||
| $, | ||
| data: { | ||
| emails: parseObject(this.emails), | ||
| listIds: parseObject(this.listIds), | ||
| sendWelcomeEmail: this.sendWelcomeEmail, | ||
| trigger: this.trigger, | ||
| }, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully subscribed ${this.emails.length} users to lists ${this.listIds.length} lists`); | ||
| return response; | ||
| }, | ||
| }; | ||
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,146 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
| import { LIMIT } from "./common/constants.mjs"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "acymailing", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| listIds: { | ||
| type: "integer[]", | ||
| label: "List Ids", | ||
| description: "Array of list IDs.", | ||
| async options({ page }) { | ||
| const lists = await this.listLists({ | ||
| params: { | ||
| limit: LIMIT, | ||
| offset: LIMIT * page, | ||
| }, | ||
| }); | ||
|
|
||
| return lists.map(({ | ||
| id: value, name: label, | ||
| }) => ({ | ||
| label, | ||
| value, | ||
| })); | ||
| }, | ||
| }, | ||
| emails: { | ||
| type: "string[]", | ||
| label: "Emails", | ||
| description: "The email addresses of users to subscribe to the lists. These must match already existing AcyMailing users.", | ||
| async options({ page }) { | ||
| const data = await this.listUsers({ | ||
| params: { | ||
| limit: LIMIT, | ||
| offset: LIMIT * page, | ||
| }, | ||
| }); | ||
|
|
||
| return data.map(({ email }) => email); | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return `${this.$auth.url}`; | ||
| }, | ||
| _headers() { | ||
| return { | ||
| "Api-Key": `${this.$auth.api_key}`, | ||
| "Content-Type": "application/json", | ||
| }; | ||
| }, | ||
| _params(params) { | ||
| return { | ||
| page: "acymailing_front", | ||
| option: "com_acym", | ||
| ctrl: "api", | ||
| ...params, | ||
| }; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, params, task, ...opts | ||
| }) { | ||
| return axios($, { | ||
| url: `${this._baseUrl()}`, | ||
| params: this._params({ | ||
| ...params, | ||
| task, | ||
| }), | ||
| headers: this._headers(), | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listUsers(opts = {}) { | ||
| return this._makeRequest({ | ||
| task: "getUsers", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listLists(opts = {}) { | ||
| return this._makeRequest({ | ||
| task: "getLists", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listSubscribersFromLists(opts = {}) { | ||
| return this._makeRequest({ | ||
| task: "getSubscribersFromLists", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listUnsubscribedUsersFromLists(opts = {}) { | ||
| return this._makeRequest({ | ||
| task: "getUnsubscribedUsersFromLists", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| createUserOrUpdate(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| task: "createOrUpdateUser", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| sendEmailToUser(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| task: "sendEmailToSingleUser", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| subscribeUserToLists(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| task: "subscribeUsers", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| async *paginate({ | ||
| fn, params = {}, ...opts | ||
| }) { | ||
| let hasMore = false; | ||
| let page = 0; | ||
|
|
||
| do { | ||
| params.limit = LIMIT; | ||
| params.offset = LIMIT * page; | ||
| page++; | ||
|
|
||
| const data = await fn({ | ||
| params, | ||
| ...opts, | ||
| }); | ||
|
|
||
| for (const d of data) { | ||
| yield d; | ||
| } | ||
|
|
||
| hasMore = data.length; | ||
|
|
||
| } while (hasMore); | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| }; |
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 @@ | ||
| export const LIMIT = 100; |
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,24 @@ | ||
| export const parseObject = (obj) => { | ||
| if (!obj) return undefined; | ||
|
|
||
| if (Array.isArray(obj)) { | ||
| return obj.map((item) => { | ||
| if (typeof item === "string") { | ||
| try { | ||
| return JSON.parse(item); | ||
| } catch (e) { | ||
| return item; | ||
| } | ||
| } | ||
| return item; | ||
| }); | ||
| } | ||
| if (typeof obj === "string") { | ||
| try { | ||
| return JSON.parse(obj); | ||
| } catch (e) { | ||
| return obj; | ||
| } | ||
| } | ||
| return obj; | ||
| }; | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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
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.