diff --git a/components/akismet/actions/check-comment/check-comment.mjs b/components/akismet/actions/check-comment/check-comment.mjs new file mode 100644 index 0000000000000..f77d9a9d0d016 --- /dev/null +++ b/components/akismet/actions/check-comment/check-comment.mjs @@ -0,0 +1,92 @@ +import app from "../../akismet.app.mjs"; + +export default { + key: "akismet-check-comment", + name: "Check Comment", + description: "Check if a comment is spam or not. [See the documentation](https://akismet.com/developers/detailed-docs/submit-spam-missed-spam/)", + version: "0.0.1", + type: "action", + props: { + app, + blog: { + propDefinition: [ + app, + "blog", + ], + }, + userIp: { + propDefinition: [ + app, + "userIp", + ], + }, + userAgent: { + propDefinition: [ + app, + "userAgent", + ], + }, + referrer: { + propDefinition: [ + app, + "referrer", + ], + }, + permalink: { + propDefinition: [ + app, + "permalink", + ], + }, + commentType: { + propDefinition: [ + app, + "commentType", + ], + }, + commentAuthor: { + propDefinition: [ + app, + "commentAuthor", + ], + }, + commentAuthorEmail: { + propDefinition: [ + app, + "commentAuthorEmail", + ], + }, + commentAuthorUrl: { + propDefinition: [ + app, + "commentAuthorUrl", + ], + }, + commentContent: { + propDefinition: [ + app, + "commentContent", + ], + }, + + }, + async run({ $ }) { + const response = await this.app.checkComment({ + $, + data: { + blog: this.blog, + user_ip: this.userIp, + user_agent: this.userAgent, + referrer: this.referrer, + permalink: this.permalink, + comment_author: this.commentAuthor, + comment_author_email: this.commentAuthorEmail, + comment_author_url: this.commentAuthorUrl, + comment_content: this.commentContent, + comment_type: this.commentType, + }, + }); + $.export("$summary", "Successfully submited comment to be checked. Akismet spam analysis response: " + response); + return response; + }, +}; diff --git a/components/akismet/actions/submit-ham/submit-ham.mjs b/components/akismet/actions/submit-ham/submit-ham.mjs new file mode 100644 index 0000000000000..39de0a443f878 --- /dev/null +++ b/components/akismet/actions/submit-ham/submit-ham.mjs @@ -0,0 +1,84 @@ +import app from "../../akismet.app.mjs"; + +export default { + key: "akismet-submit-ham", + name: "Submit Ham", + description: "Submit a comment that was incorrectly classified as spam. [See the documentation](https://akismet.com/developers/detailed-docs/submit-ham-false-positives/)", + version: "0.0.1", + type: "action", + props: { + app, + blog: { + propDefinition: [ + app, + "blog", + ], + }, + userIp: { + propDefinition: [ + app, + "userIp", + ], + }, + permalink: { + propDefinition: [ + app, + "permalink", + ], + }, + userAgent: { + propDefinition: [ + app, + "userAgent", + ], + }, + commentAuthor: { + propDefinition: [ + app, + "commentAuthor", + ], + }, + commentAuthorEmail: { + propDefinition: [ + app, + "commentAuthorEmail", + ], + }, + commentAuthorUrl: { + propDefinition: [ + app, + "commentAuthorUrl", + ], + }, + commentContent: { + propDefinition: [ + app, + "commentContent", + ], + }, + commentType: { + propDefinition: [ + app, + "commentType", + ], + }, + }, + async run({ $ }) { + const response = await this.app.submitHam({ + $, + data: { + blog: this.blog, + user_ip: this.userIp, + user_agent: this.userAgent, + permalink: this.permalink, + comment_author: this.commentAuthor, + comment_author_email: this.commentAuthorEmail, + comment_author_url: this.commentAuthorUrl, + comment_content: this.commentContent, + comment_type: this.commentType, + }, + }); + $.export("$summary", "Successfully submited comment as a false positive"); + return response; + }, +}; diff --git a/components/akismet/actions/submit-spam/submit-spam.mjs b/components/akismet/actions/submit-spam/submit-spam.mjs new file mode 100644 index 0000000000000..081c91cbfe06b --- /dev/null +++ b/components/akismet/actions/submit-spam/submit-spam.mjs @@ -0,0 +1,93 @@ +import app from "../../akismet.app.mjs"; + +export default { + key: "akismet-submit-spam", + name: "Submit Spam", + description: "Submit comment that was not marked as spam but should have been. [See the documentation](https://akismet.com/developers/detailed-docs/submit-spam-missed-spam/)", + version: "0.0.1", + type: "action", + props: { + app, + blog: { + propDefinition: [ + app, + "blog", + ], + }, + userIp: { + propDefinition: [ + app, + "userIp", + ], + }, + permalink: { + propDefinition: [ + app, + "permalink", + ], + }, + userAgent: { + propDefinition: [ + app, + "userAgent", + ], + }, + referrer: { + propDefinition: [ + app, + "referrer", + ], + }, + commentAuthor: { + propDefinition: [ + app, + "commentAuthor", + ], + }, + commentAuthorEmail: { + propDefinition: [ + app, + "commentAuthorEmail", + ], + }, + commentAuthorUrl: { + propDefinition: [ + app, + "commentAuthorUrl", + ], + }, + commentContent: { + propDefinition: [ + app, + "commentContent", + ], + }, + commentType: { + propDefinition: [ + app, + "commentType", + ], + }, + }, + async run({ $ }) { + + const response = await this.app.submitSpam({ + $, + data: { + blog: this.blog, + user_ip: this.userIp, + permalink: this.permalink, + user_agent: this.userAgent, + referrer: this.referrer, + comment_author: this.commentAuthor, + comment_author_email: this.commentAuthorEmail, + comment_author_url: this.commentAuthorUrl, + comment_content: this.commentContent, + comment_type: this.commentType, + }, + }); + + $.export("$summary", "Successfully submited comment as spam"); + return response; + }, +}; diff --git a/components/akismet/akismet.app.mjs b/components/akismet/akismet.app.mjs index ef3e3f71f6f20..19c36dadcd514 100644 --- a/components/akismet/akismet.app.mjs +++ b/components/akismet/akismet.app.mjs @@ -1,11 +1,116 @@ +import { axios } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + export default { type: "app", app: "akismet", - propDefinitions: {}, + propDefinitions: { + blog: { + type: "string", + label: "Blog URL", + description: "The URL of the blog where the comment was posted", + }, + userIp: { + type: "string", + label: "User IP", + description: "The IP address of the comment author", + }, + permalink: { + type: "string", + label: "Permalink", + description: "The full permanent URL of the entry the comment was submitted to", + }, + userAgent: { + type: "string", + label: "User Agent", + description: "The user agent string of the web browser used to submit the comment", + optional: true, + }, + referrer: { + type: "string", + label: "Referrer URL", + description: "The URL of the page that submitted the comment", + optional: true, + }, + commentAuthor: { + type: "string", + label: "Comment Author Name", + description: "The name submitted with the comment", + optional: true, + }, + commentAuthorEmail: { + type: "string", + label: "Comment Author Email", + description: "The email address submitted with the comment", + optional: true, + }, + commentAuthorUrl: { + type: "string", + label: "Comment Author URL", + description: "The URL submitted with the comment", + optional: true, + }, + commentContent: { + type: "string", + label: "Comment Content", + description: "The content of the comment itself", + optional: true, + }, + commentType: { + type: "string", + label: "Comment Type", + description: "The type of comment", + optional: true, + options: constants.COMMENT_TYPES, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://rest.akismet.com/1.1"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + data, + ...otherOpts + } = opts; + + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + ...headers, + "Content-Type": "application/x-www-form-urlencoded", + "Accept": "application/json", + }, + data: { + api_key: `${this.$auth.api_key}`, + ...data, + }, + }); + }, + async submitSpam(args = {}) { + return this._makeRequest({ + path: "/submit-spam", + method: "post", + ...args, + }); + }, + async submitHam(args = {}) { + return this._makeRequest({ + path: "/submit-ham", + method: "post", + ...args, + }); + }, + async checkComment(args = {}) { + return this._makeRequest({ + path: "/comment-check", + method: "post", + ...args, + }); }, }, }; diff --git a/components/akismet/common/constants.mjs b/components/akismet/common/constants.mjs new file mode 100644 index 0000000000000..c01caac6d1a38 --- /dev/null +++ b/components/akismet/common/constants.mjs @@ -0,0 +1,7 @@ +export default { + COMMENT_TYPES: [ + "comment", + "trackback", + "pingback", + ], +}; diff --git a/components/akismet/package.json b/components/akismet/package.json index 41876d2725dd0..723dee016f717 100644 --- a/components/akismet/package.json +++ b/components/akismet/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/akismet", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Akismet Components", "main": "akismet.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a815cb339e253..c3dcb56229add 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -615,7 +615,11 @@ importers: specifier: ^4.0.0 version: 4.0.1 - components/akismet: {} + components/akismet: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/akkio: dependencies: