diff --git a/components/google_my_business/actions/create-post/create-post.ts b/components/google_my_business/actions/create-post/create-post.ts index f9293d754374b..1fe460b264379 100644 --- a/components/google_my_business/actions/create-post/create-post.ts +++ b/components/google_my_business/actions/create-post/create-post.ts @@ -12,7 +12,7 @@ export default defineAction({ key: "google_my_business-create-post", name: "Create Post", description: `Create a new local post associated with a location. [See the documentation](${DOCS_LINK})`, - version: "0.0.2", + version: "0.0.3", type: "action", props: { app, @@ -95,7 +95,8 @@ export default defineAction({ ? JSON.parse(obj) : obj; } catch (err) { - throw new ConfigurationError(`**Invalid JSON string** for object prop: "${obj}"`); + throw new ConfigurationError(`**Invalid JSON string** for object prop: "${obj}" + Error: ${err}`); } }, }, diff --git a/components/google_my_business/actions/create-update-reply-to-review/create-update-reply-to-review.ts b/components/google_my_business/actions/create-update-reply-to-review/create-update-reply-to-review.ts index 050fe49390854..cc7b7a4289988 100644 --- a/components/google_my_business/actions/create-update-reply-to-review/create-update-reply-to-review.ts +++ b/components/google_my_business/actions/create-update-reply-to-review/create-update-reply-to-review.ts @@ -8,7 +8,7 @@ export default defineAction({ key: "google_my_business-create-update-reply-to-review", name: "Create or Update Reply to Review", description: `Create or update a reply to the specified review. [See the documentation](${DOCS_LINK})`, - version: "0.0.1", + version: "0.0.2", type: "action", props: { app, diff --git a/components/google_my_business/actions/get-reviews-multiple-locations/get-reviews-multiple-locations.ts b/components/google_my_business/actions/get-reviews-multiple-locations/get-reviews-multiple-locations.ts new file mode 100644 index 0000000000000..0b388f4aabdf3 --- /dev/null +++ b/components/google_my_business/actions/get-reviews-multiple-locations/get-reviews-multiple-locations.ts @@ -0,0 +1,84 @@ +import { defineAction } from "@pipedream/types"; +import app from "../../app/google_my_business.app"; +import { BatchGetReviewsParams } from "../../common/requestParams"; + +const DOCS_LINK = "https://developers.google.com/my-business/content/review-data#get_reviews_from_multiple_locations"; + +export default defineAction({ + key: "google_my_business-get-reviews-multiple-locations", + name: "Get Reviews from Multiple Locations", + description: `Get reviews from multiple locations at once. [See the documentation](${DOCS_LINK})`, + version: "0.0.1", + type: "action", + props: { + app, + account: { + propDefinition: [ + app, + "account", + ], + }, + locationNames: { + propDefinition: [ + app, + "location", + ({ account }: { account: string; }) => ({ + account, + }), + ], + type: "string[]", + label: "Location Names", + description: "One or more locations to get reviews from", + }, + pageSize: { + type: "integer", + label: "Page Size", + description: "The number of reviews to return per location (max 50)", + optional: true, + default: 50, + min: 1, + max: 50, + }, + orderBy: { + type: "string", + label: "Order By", + description: "How to order the reviews: by createTime or updateTime, and ascending or descending", + optional: true, + options: [ + "createTime desc", + "createTime asc", + "updateTime desc", + "updateTime asc", + ], + }, + ignoreRatingOnlyReviews: { + type: "boolean", + label: "Ignore Rating Only Reviews", + description: "If true, only return reviews that have textual content", + optional: true, + default: false, + }, + }, + async run({ $ }) { + const { + account, locationNames, pageSize, orderBy, ignoreRatingOnlyReviews, + } = this; + + const params: BatchGetReviewsParams = { + $, + account, + data: { + locationNames: locationNames?.map((locationName: string) => `accounts/${account}/locations/${locationName}`), + pageSize, + orderBy, + ignoreRatingOnlyReviews, + }, + }; + + const response = await this.app.batchGetReviews(params); + + $.export("$summary", `Successfully retrieved reviews from ${locationNames.length} locations`); + + return response; + }, +}); diff --git a/components/google_my_business/actions/get-specific-review/get-specific-review.ts b/components/google_my_business/actions/get-specific-review/get-specific-review.ts new file mode 100644 index 0000000000000..62e9c7f8a06eb --- /dev/null +++ b/components/google_my_business/actions/get-specific-review/get-specific-review.ts @@ -0,0 +1,61 @@ +import { defineAction } from "@pipedream/types"; +import app from "../../app/google_my_business.app"; +import { GetReviewParams } from "../../common/requestParams"; + +const DOCS_LINK = "https://developers.google.com/my-business/content/review-data#get_a_specific_review"; + +export default defineAction({ + key: "google_my_business-get-specific-review", + name: "Get a Specific Review", + description: `Return a specific review by name. [See the documentation](${DOCS_LINK})`, + version: "0.0.1", + type: "action", + props: { + app, + account: { + propDefinition: [ + app, + "account", + ], + }, + location: { + propDefinition: [ + app, + "location", + ({ account }: { account: string; }) => ({ + account, + }), + ], + }, + review: { + propDefinition: [ + app, + "review", + ({ + account, location, + }: Record) => ({ + account, + location, + }), + ], + }, + }, + async run({ $ }) { + const { + account, location, review, + } = this; + + const params: GetReviewParams = { + $, + account, + location, + review, + }; + + const response = await this.app.getReview(params); + + $.export("$summary", `Successfully retrieved review: ${review}`); + + return response; + }, +}); diff --git a/components/google_my_business/actions/list-all-reviews/list-all-reviews.ts b/components/google_my_business/actions/list-all-reviews/list-all-reviews.ts new file mode 100644 index 0000000000000..19133efb9f6e2 --- /dev/null +++ b/components/google_my_business/actions/list-all-reviews/list-all-reviews.ts @@ -0,0 +1,48 @@ +import { defineAction } from "@pipedream/types"; +import app from "../../app/google_my_business.app"; +import { ListReviewsParams } from "../../common/requestParams"; + +const DOCS_LINK = "https://developers.google.com/my-business/content/review-data#list_all_reviews"; + +export default defineAction({ + key: "google_my_business-list-all-reviews", + name: "List All Reviews", + description: `List all reviews of a location to audit reviews in bulk. [See the documentation](${DOCS_LINK})`, + version: "0.0.1", + type: "action", + props: { + app, + account: { + propDefinition: [ + app, + "account", + ], + }, + location: { + propDefinition: [ + app, + "location", + ({ account }: { account: string; }) => ({ + account, + }), + ], + }, + }, + async run({ $ }) { + const { + account, location, + } = this; + + const params: ListReviewsParams = { + $, + account, + location, + }; + + const response = await this.app.listReviews(params); + + $.export("$summary", `Successfully listed ${response.length} reviews`); + + return response; + }, +}); diff --git a/components/google_my_business/actions/list-posts/list-posts.ts b/components/google_my_business/actions/list-posts/list-posts.ts index 48a3077bc15ba..4515931cceb32 100644 --- a/components/google_my_business/actions/list-posts/list-posts.ts +++ b/components/google_my_business/actions/list-posts/list-posts.ts @@ -9,7 +9,7 @@ export default defineAction({ key: "google_my_business-list-posts", name: "List Posts", description: `List local posts associated with a location. [See the documentation](${DOCS_LINK})`, - version: "0.0.1", + version: "0.0.2", type: "action", props: { app, diff --git a/components/google_my_business/app/google_my_business.app.ts b/components/google_my_business/app/google_my_business.app.ts index efeb3c1467bce..2b39fb87d3390 100644 --- a/components/google_my_business/app/google_my_business.app.ts +++ b/components/google_my_business/app/google_my_business.app.ts @@ -2,7 +2,7 @@ import { defineApp } from "@pipedream/types"; import { axios } from "@pipedream/platform"; import { CreatePostParams, - HttpRequestParams, ListPostsParams, ListReviewsParams, PaginatedRequestParams, UpdateReplyParams, + HttpRequestParams, ListPostsParams, ListReviewsParams, PaginatedRequestParams, UpdateReplyParams, GetReviewParams, BatchGetReviewsParams, } from "../common/requestParams"; import { Account, LocalPost, Location, Review, @@ -187,5 +187,22 @@ export default defineApp({ ...args, }); }, + async getReview({ + account, location, review, ...args + }: GetReviewParams): Promise { + return this._httpRequest({ + url: `https://mybusiness.googleapis.com/v4/accounts/${account}/locations/${location}/reviews/${review}`, + ...args, + }); + }, + async batchGetReviews({ + account, ...args + }: BatchGetReviewsParams): Promise { + return this._httpRequest({ + method: "POST", + url: `https://mybusiness.googleapis.com/v4/accounts/${account}/locations:batchGetReviews`, + ...args, + }); + }, }, }); diff --git a/components/google_my_business/common/requestParams.ts b/components/google_my_business/common/requestParams.ts index 45c8ccc7693d1..a0281fc51f69f 100644 --- a/components/google_my_business/common/requestParams.ts +++ b/components/google_my_business/common/requestParams.ts @@ -50,3 +50,18 @@ export interface UpdateReplyParams extends PdAxiosRequest, AccountLocation { comment: string; }; } + +export interface GetReviewParams extends PdAxiosRequest, AccountLocation { + review: string; +} + +export interface BatchGetReviewsParams extends PdAxiosRequest { + account: string; + data: { + locationNames: string[]; + pageSize?: number; + pageToken?: string; + orderBy?: string; + ignoreRatingOnlyReviews?: boolean; + }; +} diff --git a/components/google_my_business/common/responseSchemas.ts b/components/google_my_business/common/responseSchemas.ts index 3d0954d0b01a9..6d9d3e97c76b0 100644 --- a/components/google_my_business/common/responseSchemas.ts +++ b/components/google_my_business/common/responseSchemas.ts @@ -22,3 +22,9 @@ export interface Review extends EntityWithCreateTime { export interface LocalPost extends EntityWithCreateTime { summary: string; } + +export interface BatchGetReviewsResponse { + locationReviews: { + review: Review + }[]; +} diff --git a/components/google_my_business/package.json b/components/google_my_business/package.json index a190f098b78c1..b908cad8359c4 100644 --- a/components/google_my_business/package.json +++ b/components/google_my_business/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/google_my_business", - "version": "0.1.4", + "version": "0.2.0", "description": "Pipedream Google My Business Components", "main": "dist/app/google_my_business.app.mjs", "keywords": [ diff --git a/components/google_my_business/sources/common.ts b/components/google_my_business/sources/common.ts index a547db8101bb9..0ab25a5f159ce 100644 --- a/components/google_my_business/sources/common.ts +++ b/components/google_my_business/sources/common.ts @@ -55,9 +55,9 @@ export default { const items: EntityWithCreateTime[] = await this.getItems(); this.setLastRun(currentRun); - const filteredItems = lastRun - ? items.filter(({ createTime }) => new Date(createTime) >= lastRun) - : items.slice(-10); + const filteredItems = (lastRun + ? items?.filter(({ createTime }) => new Date(createTime) >= lastRun) + : items?.slice(-10)) ?? []; filteredItems.reverse().forEach((item) => { this.$emit(item, { diff --git a/components/google_my_business/sources/new-post-created/new-post-created.ts b/components/google_my_business/sources/new-post-created/new-post-created.ts index 493e55e46102e..bfceee27b090d 100644 --- a/components/google_my_business/sources/new-post-created/new-post-created.ts +++ b/components/google_my_business/sources/new-post-created/new-post-created.ts @@ -10,7 +10,7 @@ export default defineSource({ key: "google_my_business-new-post-created", name: "New Post Created", description: `Emit new event for each new local post on a location [See the documentation](${DOCS_LINK})`, - version: "0.0.3", + version: "0.0.4", type: "source", dedupe: "unique", methods: { diff --git a/components/google_my_business/sources/new-review-created-multiple-locations/new-review-created-multiple-locations.ts b/components/google_my_business/sources/new-review-created-multiple-locations/new-review-created-multiple-locations.ts new file mode 100644 index 0000000000000..11ceeaa0a2e26 --- /dev/null +++ b/components/google_my_business/sources/new-review-created-multiple-locations/new-review-created-multiple-locations.ts @@ -0,0 +1,65 @@ +import { defineSource } from "@pipedream/types"; +import { BatchGetReviewsParams } from "../../common/requestParams"; +import { + BatchGetReviewsResponse, Review, +} from "../../common/responseSchemas"; +import app from "../../app/google_my_business.app"; +import common from "../common"; + +const DOCS_LINK = "https://developers.google.com/my-business/content/review-data#get_reviews_from_multiple_locations"; + +export default defineSource({ + ...common, + key: "google_my_business-new-review-created-multiple-locations", + name: "New Review Created (Multiple Locations)", + description: `Emit new event for each new review on any of the selected locations [See the documentation](${DOCS_LINK})`, + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + ...common.props, + location: { + propDefinition: [ + app, + "location", + ({ account }: { account: string; }) => ({ + account, + }), + ], + type: "string[]", + label: "Location Names", + description: "One or more locations to monitor for new reviews", + }, + }, + hooks: { + async deploy() { + await this.getAndProcessData(); + }, + }, + methods: { + ...common.methods, + async getItems(): Promise { + const { + account, location, + } = this; + + const params: BatchGetReviewsParams = { + account, + data: { + locationNames: location?.map((locationName: string) => `accounts/${account}/locations/${locationName}`), + }, + }; + + const response: BatchGetReviewsResponse = await this.app.batchGetReviews(params); + + return response?.locationReviews?.map((item) => item.review); + }, + getSummary({ comment }: Review) { + return `New Review${comment + ? `: "${comment.length > 50 + ? comment.slice(0, 45) + "[...]" + : comment}"` + : ""}`; + }, + }, +}); diff --git a/components/google_my_business/sources/new-review-created/new-review-created.ts b/components/google_my_business/sources/new-review-created/new-review-created.ts index d3ef0376156ec..e40fd6f8c5c26 100644 --- a/components/google_my_business/sources/new-review-created/new-review-created.ts +++ b/components/google_my_business/sources/new-review-created/new-review-created.ts @@ -10,7 +10,7 @@ export default defineSource({ key: "google_my_business-new-review-created", name: "New Review Created", description: `Emit new event for each new review on a location [See the documentation](${DOCS_LINK})`, - version: "0.0.3", + version: "0.0.4", type: "source", dedupe: "unique", methods: { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index af111effa0004..880ebe1f50564 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -13014,8 +13014,7 @@ importers: specifier: ^1.4.0 version: 1.6.6 - components/siteglide: - specifiers: {} + components/siteglide: {} components/siteleaf: dependencies: