diff --git a/components/zendesk/actions/add-ticket-tags/add-ticket-tags.mjs b/components/zendesk/actions/add-ticket-tags/add-ticket-tags.mjs index 7d8aeb57c2cfe..ed189c086b879 100644 --- a/components/zendesk/actions/add-ticket-tags/add-ticket-tags.mjs +++ b/components/zendesk/actions/add-ticket-tags/add-ticket-tags.mjs @@ -5,7 +5,7 @@ export default { name: "Add Ticket Tags", description: "Add tags to a ticket (appends to existing tags). [See the documentation](https://developer.zendesk.com/api-reference/ticketing/ticket-management/tags/#add-tags).", type: "action", - version: "0.0.6", + version: "0.0.7", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/zendesk/actions/create-ticket/create-ticket.mjs b/components/zendesk/actions/create-ticket/create-ticket.mjs index 1ea3132aa3b81..d73f578e21435 100644 --- a/components/zendesk/actions/create-ticket/create-ticket.mjs +++ b/components/zendesk/actions/create-ticket/create-ticket.mjs @@ -5,7 +5,7 @@ export default { name: "Create Ticket", description: "Creates a ticket. [See the documentation](https://developer.zendesk.com/api-reference/ticketing/tickets/tickets/#create-ticket).", type: "action", - version: "0.1.10", + version: "0.1.11", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/zendesk/actions/delete-ticket/delete-ticket.mjs b/components/zendesk/actions/delete-ticket/delete-ticket.mjs index 7ee6fcc662c25..c181c2daf620b 100644 --- a/components/zendesk/actions/delete-ticket/delete-ticket.mjs +++ b/components/zendesk/actions/delete-ticket/delete-ticket.mjs @@ -5,7 +5,7 @@ export default { name: "Delete Ticket", description: "Deletes a ticket. [See the documentation](https://developer.zendesk.com/api-reference/ticketing/tickets/tickets/#delete-ticket).", type: "action", - version: "0.1.10", + version: "0.1.11", annotations: { destructiveHint: true, openWorldHint: true, diff --git a/components/zendesk/actions/get-article/get-article.mjs b/components/zendesk/actions/get-article/get-article.mjs new file mode 100644 index 0000000000000..7af82169b1548 --- /dev/null +++ b/components/zendesk/actions/get-article/get-article.mjs @@ -0,0 +1,43 @@ +import zendesk from "../../zendesk.app.mjs"; + +export default { + key: "zendesk-get-article", + name: "Get Article", + description: "Retrieves an article by its ID. [See the documentation](https://developer.zendesk.com/api-reference/help_center/help-center-api/articles/#show-article).", + type: "action", + version: "0.0.1", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + props: { + zendesk, + locale: { + propDefinition: [ + zendesk, + "locale", + ], + optional: true, + }, + articleId: { + propDefinition: [ + zendesk, + "articleId", + ({ locale }) => ({ + locale, + }), + ], + }, + }, + async run({ $ }) { + const article = await this.zendesk.getArticle({ + $, + locale: this.locale, + articleId: this.articleId, + }); + + $.export("$summary", `Successfully retrieved article ${this.articleId}`); + return article; + }, +}; diff --git a/components/zendesk/actions/get-macro/get-macro.mjs b/components/zendesk/actions/get-macro/get-macro.mjs new file mode 100644 index 0000000000000..953ecf9feedb7 --- /dev/null +++ b/components/zendesk/actions/get-macro/get-macro.mjs @@ -0,0 +1,32 @@ +import zendesk from "../../zendesk.app.mjs"; + +export default { + key: "zendesk-get-macro", + name: "Get Macro", + description: "Retrieves a macro by its ID. [See the documentation](https://developer.zendesk.com/api-reference/ticketing/business-rules/macros/#show-macro).", + type: "action", + version: "0.0.1", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + props: { + zendesk, + macroId: { + propDefinition: [ + zendesk, + "macroId", + ], + }, + }, + async run({ $ }) { + const macro = await this.zendesk.getMacro({ + $, + macroId: this.macroId, + }); + + $.export("$summary", `Successfully retrieved macro with ID ${this.macroId}`); + return macro; + }, +}; diff --git a/components/zendesk/actions/get-ticket-info/get-ticket-info.mjs b/components/zendesk/actions/get-ticket-info/get-ticket-info.mjs index 9778c9f3c515a..20a9695e8b765 100644 --- a/components/zendesk/actions/get-ticket-info/get-ticket-info.mjs +++ b/components/zendesk/actions/get-ticket-info/get-ticket-info.mjs @@ -5,7 +5,7 @@ export default { name: "Get Ticket Info", description: "Retrieves information about a specific ticket. [See the documentation](https://developer.zendesk.com/api-reference/ticketing/tickets/tickets/#show-ticket).", type: "action", - version: "0.0.8", + version: "0.0.9", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/zendesk/actions/get-user-info/get-user-info.mjs b/components/zendesk/actions/get-user-info/get-user-info.mjs index 568c88e1ae3b2..6e993b1886849 100644 --- a/components/zendesk/actions/get-user-info/get-user-info.mjs +++ b/components/zendesk/actions/get-user-info/get-user-info.mjs @@ -4,7 +4,7 @@ export default { key: "zendesk-get-user-info", name: "Get User Info", description: "Retrieves information about a specific user. [See the documentation](https://developer.zendesk.com/api-reference/ticketing/users/users/#show-user).", - version: "0.0.5", + version: "0.0.6", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/zendesk/actions/list-active-macros/list-active-macros.mjs b/components/zendesk/actions/list-active-macros/list-active-macros.mjs new file mode 100644 index 0000000000000..4f0d241a34ed9 --- /dev/null +++ b/components/zendesk/actions/list-active-macros/list-active-macros.mjs @@ -0,0 +1,77 @@ +import constants from "../../common/constants.mjs"; +import zendesk from "../../zendesk.app.mjs"; + +export default { + key: "zendesk-list-active-macros", + name: "List Active Macros", + description: "Lists all active shared and personal macros available to the current user. [See the documentation](https://developer.zendesk.com/api-reference/ticketing/business-rules/macros/#list-active-macros).", + type: "action", + version: "0.0.1", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + props: { + zendesk, + access: { + type: "string", + label: "Access", + description: "Filter macros by access. The \"agents\" value returns all personal macros for the account's agents and is only available to admins.", + options: constants.ACCESS_OPTIONS, + optional: true, + }, + categoryId: { + propDefinition: [ + zendesk, + "macroCategory", + ], + optional: true, + }, + groupId: { + propDefinition: [ + zendesk, + "groupId", + ], + optional: true, + }, + include: { + type: "string", + label: "Include", + description: "Additional fields to include in the response", + options: constants.INCLUDE_OPTIONS, + optional: true, + }, + sortBy: { + type: "string", + label: "Sort By", + description: "The field to sort the results by", + options: constants.SORT_BY_OPTIONS, + optional: true, + }, + sortOrder: { + propDefinition: [ + zendesk, + "sortOrder", + ], + }, + }, + async run({ $ }) { + const { macros } = await this.zendesk.listActiveMacros({ + $, + params: { + access: this.access, + category: this.categoryId, + group_id: this.groupId, + include: this.include, + sort_by: this.sortBy, + sort_order: this.sortOrder, + }, + }); + + $.export("$summary", `Successfully retrieved ${macros.length} macro${macros.length === 1 + ? "" + : "s"}`); + return macros; + }, +}; diff --git a/components/zendesk/actions/list-articles/list-articles.mjs b/components/zendesk/actions/list-articles/list-articles.mjs new file mode 100644 index 0000000000000..4fec59d9ac2c1 --- /dev/null +++ b/components/zendesk/actions/list-articles/list-articles.mjs @@ -0,0 +1,105 @@ +import { ConfigurationError } from "@pipedream/platform"; +import zendesk from "../../zendesk.app.mjs"; + +export default { + key: "zendesk-list-articles", + name: "List Articles", + description: "Retrieves a list of articles. [See the documentation](https://developer.zendesk.com/api-reference/help_center/help-center-api/articles/#list-articles).", + type: "action", + version: "0.0.1", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + props: { + zendesk, + locale: { + propDefinition: [ + zendesk, + "locale", + ], + optional: true, + }, + categoryId: { + propDefinition: [ + zendesk, + "articleCategoryId", + ({ locale }) => ({ + locale, + }), + ], + optional: true, + }, + sectionId: { + propDefinition: [ + zendesk, + "sectionId", + ({ + locale, categoryId, + }) => ({ + locale, + categoryId, + }), + ], + optional: true, + }, + userId: { + propDefinition: [ + zendesk, + "userId", + ], + optional: true, + reloadProps: true, + }, + limit: { + propDefinition: [ + zendesk, + "limit", + ], + description: "Maximum number of articles to return", + }, + }, + async additionalProps(props) { + props.locale.hidden = false; + props.categoryId.hidden = false; + props.sectionId.hidden = false; + if (this.userId) { + props.locale.hidden = true; + props.categoryId.hidden = true; + props.sectionId.hidden = true; + } + return {}; + }, + async run({ $ }) { + if ((this.categoryId && this.userId) || (this.sectionId && this.userId)) { + throw new ConfigurationError("Providing a User ID, you cannot provide a Category ID or Section ID."); + } + + const results = this.zendesk.paginate({ + fn: this.zendesk.listArticles, + args: { + $, + categoryId: this.categoryId, + sectionId: this.sectionId, + userId: this.userId, + locale: this.userId + ? null + : this.locale, + }, + resourceKey: "articles", + max: this.limit, + }); + + const articles = []; + for await (const article of results) { + articles.push(article); + } + + $.export("$summary", `Successfully retrieved ${articles.length} article${articles.length === 1 + ? "" + : "s"}`); + + return articles; + }, +}; diff --git a/components/zendesk/actions/list-locales/list-locales.mjs b/components/zendesk/actions/list-locales/list-locales.mjs index 0611e19c92fa8..fc496133a29be 100644 --- a/components/zendesk/actions/list-locales/list-locales.mjs +++ b/components/zendesk/actions/list-locales/list-locales.mjs @@ -4,7 +4,7 @@ export default { key: "zendesk-list-locales", name: "List Locales", description: "Retrieves all locales. [See the documentation](https://developer.zendesk.com/api-reference/ticketing/account-configuration/locales/).", - version: "0.0.5", + version: "0.0.6", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/zendesk/actions/list-macros/list-macros.mjs b/components/zendesk/actions/list-macros/list-macros.mjs index e4a60f2372f0e..ae40197ccdab6 100644 --- a/components/zendesk/actions/list-macros/list-macros.mjs +++ b/components/zendesk/actions/list-macros/list-macros.mjs @@ -4,7 +4,7 @@ export default { key: "zendesk-list-macros", name: "List Macros", description: "Retrieves all macros. [See the documentation](https://developer.zendesk.com/api-reference/ticketing/business-rules/macros/#list-macros).", - version: "0.0.5", + version: "0.0.6", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/zendesk/actions/list-ticket-comments/list-ticket-comments.mjs b/components/zendesk/actions/list-ticket-comments/list-ticket-comments.mjs index c3d2e5932bb22..2cc960398b403 100644 --- a/components/zendesk/actions/list-ticket-comments/list-ticket-comments.mjs +++ b/components/zendesk/actions/list-ticket-comments/list-ticket-comments.mjs @@ -4,7 +4,7 @@ export default { key: "zendesk-list-ticket-comments", name: "List Ticket Comments", description: "Retrieves all comments for a specific ticket. [See the documentation](https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_comments/#list-comments).", - version: "0.0.5", + version: "0.0.6", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/zendesk/actions/list-tickets/list-tickets.mjs b/components/zendesk/actions/list-tickets/list-tickets.mjs index 3378cf62a657d..409b0f5701e9a 100644 --- a/components/zendesk/actions/list-tickets/list-tickets.mjs +++ b/components/zendesk/actions/list-tickets/list-tickets.mjs @@ -5,7 +5,7 @@ export default { name: "List Tickets", description: "Retrieves a list of tickets. [See the documentation](https://developer.zendesk.com/api-reference/ticketing/tickets/tickets/#list-tickets).", type: "action", - version: "0.0.8", + version: "0.0.9", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/zendesk/actions/remove-ticket-tags/remove-ticket-tags.mjs b/components/zendesk/actions/remove-ticket-tags/remove-ticket-tags.mjs index a3b15b2ac2640..ce707e9dfbce5 100644 --- a/components/zendesk/actions/remove-ticket-tags/remove-ticket-tags.mjs +++ b/components/zendesk/actions/remove-ticket-tags/remove-ticket-tags.mjs @@ -5,7 +5,7 @@ export default { name: "Remove Ticket Tags", description: "Remove specific tags from a ticket. [See the documentation](https://developer.zendesk.com/api-reference/ticketing/ticket-management/tags/#remove-tags).", type: "action", - version: "0.0.6", + version: "0.0.7", annotations: { destructiveHint: true, openWorldHint: true, diff --git a/components/zendesk/actions/search-tickets/search-tickets.mjs b/components/zendesk/actions/search-tickets/search-tickets.mjs index 6f9788bd0ef1b..3f2bdafd6077f 100644 --- a/components/zendesk/actions/search-tickets/search-tickets.mjs +++ b/components/zendesk/actions/search-tickets/search-tickets.mjs @@ -5,7 +5,7 @@ export default { name: "Search Tickets", description: "Searches for tickets using Zendesk's search API. [See the documentation](https://developer.zendesk.com/api-reference/ticketing/ticket-management/search/#search-tickets).", type: "action", - version: "0.0.9", + version: "0.0.10", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/zendesk/actions/set-custom-ticket-fields/set-custom-ticket-fields.mjs b/components/zendesk/actions/set-custom-ticket-fields/set-custom-ticket-fields.mjs index 8bb281dad0c3a..74d89c5115c4c 100644 --- a/components/zendesk/actions/set-custom-ticket-fields/set-custom-ticket-fields.mjs +++ b/components/zendesk/actions/set-custom-ticket-fields/set-custom-ticket-fields.mjs @@ -1,13 +1,13 @@ -import app from "../../zendesk.app.mjs"; -import { parseObject } from "../../common/utils.mjs"; import { ConfigurationError } from "@pipedream/platform"; +import { parseObject } from "../../common/utils.mjs"; +import app from "../../zendesk.app.mjs"; export default { key: "zendesk-set-custom-ticket-fields", name: "Set Custom Ticket Fields", description: "Sets one or more custom field values on a ticket. [See the documentation](https://developer.zendesk.com/api-reference/ticketing/tickets/tickets/#update-ticket).", type: "action", - version: "0.0.3", + version: "0.0.4", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/zendesk/actions/set-ticket-tags/set-ticket-tags.mjs b/components/zendesk/actions/set-ticket-tags/set-ticket-tags.mjs index 7b0c88b135b92..817d4402dc0d7 100644 --- a/components/zendesk/actions/set-ticket-tags/set-ticket-tags.mjs +++ b/components/zendesk/actions/set-ticket-tags/set-ticket-tags.mjs @@ -5,7 +5,7 @@ export default { name: "Set Ticket Tags", description: "Set tags on a ticket (replaces all existing tags). [See the documentation](https://developer.zendesk.com/api-reference/ticketing/ticket-management/tags/#set-tags).", type: "action", - version: "0.0.6", + version: "0.0.7", annotations: { destructiveHint: true, openWorldHint: true, diff --git a/components/zendesk/actions/update-ticket/update-ticket.mjs b/components/zendesk/actions/update-ticket/update-ticket.mjs index 718de60b356e4..7ed2ab0027e42 100644 --- a/components/zendesk/actions/update-ticket/update-ticket.mjs +++ b/components/zendesk/actions/update-ticket/update-ticket.mjs @@ -5,7 +5,7 @@ export default { name: "Update Ticket", description: "Updates a ticket. [See the documentation](https://developer.zendesk.com/api-reference/ticketing/tickets/tickets/#update-ticket).", type: "action", - version: "0.2.3", + version: "0.2.4", annotations: { destructiveHint: true, openWorldHint: true, diff --git a/components/zendesk/common/constants.mjs b/components/zendesk/common/constants.mjs index 67e1801a4f89b..0e92e5159176d 100644 --- a/components/zendesk/common/constants.mjs +++ b/components/zendesk/common/constants.mjs @@ -235,6 +235,44 @@ const SORT_BY_OPTIONS = [ "updated_at", ]; +const ACCESS_OPTIONS = [ + "personal", + "agents", + "shared", + "account", +]; + +const INCLUDE_OPTIONS = [ + { + label: "The app installation that requires each macro, if present", + value: "app_installation", + }, + { + label: "The macro categories", + value: "categories", + }, + { + label: "The permissions for each macro", + value: "permissions", + }, + { + label: "The number of times each macro has been used in the past hour", + value: "usage_1h", + }, + { + label: "The number of times each macro has been used in the past day", + value: "usage_24h", + }, + { + label: "The number of times each macro has been used in the past week", + value: "usage_7d", + }, + { + label: "The number of times each macro has been used in the past thirty days", + value: "usage_30d", + }, +]; + export default { SUBDOMAIN_PLACEHOLDER, BASE_URL, @@ -256,4 +294,6 @@ export default { TICKET_STATUS_OPTIONS, TICKET_FIELD_OPTIONS, SORT_BY_OPTIONS, + ACCESS_OPTIONS, + INCLUDE_OPTIONS, }; diff --git a/components/zendesk/package.json b/components/zendesk/package.json index a148021db1515..9f626f79e48f5 100644 --- a/components/zendesk/package.json +++ b/components/zendesk/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/zendesk", - "version": "0.10.1", + "version": "0.11.0", "description": "Pipedream Zendesk Components", "main": "zendesk.app.mjs", "keywords": [ diff --git a/components/zendesk/sources/locale-updated/locale-updated.mjs b/components/zendesk/sources/locale-updated/locale-updated.mjs index 1c59c0db70ada..e66189419700c 100644 --- a/components/zendesk/sources/locale-updated/locale-updated.mjs +++ b/components/zendesk/sources/locale-updated/locale-updated.mjs @@ -6,7 +6,7 @@ export default { name: "Locale Updated", type: "source", description: "Emit new event when a locale has been updated", - version: "0.0.4", + version: "0.0.5", dedupe: "unique", async run() { const lastTs = this._getLastTs(); diff --git a/components/zendesk/sources/new-ticket-comment-added/new-ticket-comment-added.mjs b/components/zendesk/sources/new-ticket-comment-added/new-ticket-comment-added.mjs index f16ae13e547de..a267970cde2fd 100644 --- a/components/zendesk/sources/new-ticket-comment-added/new-ticket-comment-added.mjs +++ b/components/zendesk/sources/new-ticket-comment-added/new-ticket-comment-added.mjs @@ -7,7 +7,7 @@ export default { key: "zendesk-new-ticket-comment-added", type: "source", description: "Emit new event when a ticket comment has been added", - version: "0.1.1", + version: "0.1.2", dedupe: "unique", props: { app, diff --git a/components/zendesk/sources/new-ticket/new-ticket.mjs b/components/zendesk/sources/new-ticket/new-ticket.mjs index f66b88908cd25..311cf8a3b65f9 100644 --- a/components/zendesk/sources/new-ticket/new-ticket.mjs +++ b/components/zendesk/sources/new-ticket/new-ticket.mjs @@ -6,7 +6,7 @@ export default { key: "zendesk-new-ticket", type: "source", description: "Emit new event when a ticket is created", - version: "0.2.9", + version: "0.2.10", dedupe: "unique", methods: { ...common.methods, diff --git a/components/zendesk/sources/ticket-added-to-view/ticket-added-to-view.mjs b/components/zendesk/sources/ticket-added-to-view/ticket-added-to-view.mjs index 25d93c6568ec9..d2cbe5f31b50d 100644 --- a/components/zendesk/sources/ticket-added-to-view/ticket-added-to-view.mjs +++ b/components/zendesk/sources/ticket-added-to-view/ticket-added-to-view.mjs @@ -5,7 +5,7 @@ export default { key: "zendesk-ticket-added-to-view", name: "New Ticket Added to View (Instant)", description: "Emit new event when a ticket is added to the specified view", - version: "0.0.9", + version: "0.0.10", type: "source", dedupe: "unique", props: { diff --git a/components/zendesk/sources/ticket-closed/ticket-closed.mjs b/components/zendesk/sources/ticket-closed/ticket-closed.mjs index 5ebfe5181eed9..df007d0af22f8 100644 --- a/components/zendesk/sources/ticket-closed/ticket-closed.mjs +++ b/components/zendesk/sources/ticket-closed/ticket-closed.mjs @@ -6,7 +6,7 @@ export default { key: "zendesk-ticket-closed", type: "source", description: "Emit new event when a ticket has changed to closed status", - version: "0.2.9", + version: "0.2.10", dedupe: "unique", methods: { ...common.methods, diff --git a/components/zendesk/sources/ticket-pended/ticket-pended.mjs b/components/zendesk/sources/ticket-pended/ticket-pended.mjs index 95fa77ae0bbff..5a3e6341b6bf4 100644 --- a/components/zendesk/sources/ticket-pended/ticket-pended.mjs +++ b/components/zendesk/sources/ticket-pended/ticket-pended.mjs @@ -6,7 +6,7 @@ export default { key: "zendesk-ticket-pended", type: "source", description: "Emit new event when a ticket has changed to pending status", - version: "0.2.9", + version: "0.2.10", dedupe: "unique", methods: { ...common.methods, diff --git a/components/zendesk/sources/ticket-solved/ticket-solved.mjs b/components/zendesk/sources/ticket-solved/ticket-solved.mjs index 1f1bc09bb4d9f..aa4b866f793e7 100644 --- a/components/zendesk/sources/ticket-solved/ticket-solved.mjs +++ b/components/zendesk/sources/ticket-solved/ticket-solved.mjs @@ -6,7 +6,7 @@ export default { key: "zendesk-ticket-solved", type: "source", description: "Emit new event when a ticket has changed to solved status", - version: "0.2.9", + version: "0.2.10", dedupe: "unique", methods: { ...common.methods, diff --git a/components/zendesk/sources/ticket-updated/ticket-updated.mjs b/components/zendesk/sources/ticket-updated/ticket-updated.mjs index 003fb21dc6125..99f64367af66a 100644 --- a/components/zendesk/sources/ticket-updated/ticket-updated.mjs +++ b/components/zendesk/sources/ticket-updated/ticket-updated.mjs @@ -6,7 +6,7 @@ export default { key: "zendesk-ticket-updated", type: "source", description: "Emit new event when a ticket has been updated", - version: "0.2.9", + version: "0.2.10", dedupe: "unique", methods: { ...common.methods, diff --git a/components/zendesk/zendesk.app.mjs b/components/zendesk/zendesk.app.mjs index 9acdc06ab3000..08cdb6801eb7a 100644 --- a/components/zendesk/zendesk.app.mjs +++ b/components/zendesk/zendesk.app.mjs @@ -1,7 +1,8 @@ -import { axios } from "@pipedream/platform"; -import constants from "./common/constants.mjs"; -import { getFileStreamAndMetadata } from "@pipedream/platform"; +import { + axios, getFileStreamAndMetadata, +} from "@pipedream/platform"; import path from "path"; +import constants from "./common/constants.mjs"; export default { type: "app", @@ -194,6 +195,134 @@ export default { return fields; }, }, + locale: { + type: "string", + label: "Locale", + description: "The locale of the article", + async options() { + const { locales } = await this.listLocales(); + return locales.map((locale) => locale.locale); + }, + }, + articleCategoryId: { + type: "string", + label: "Article Category ID", + description: "The ID of the article category", + async options({ + locale, prevContext, + }) { + const { afterCursor } = prevContext; + const { + categories, meta, + } = await this.listArticleCategories({ + locale, + params: { + [constants.PAGE_SIZE_PARAM]: constants.DEFAULT_LIMIT, + [constants.PAGE_AFTER_PARAM]: afterCursor, + }, + }); + return { + context: { + afterCursor: meta.after_cursor, + }, + options: categories.map(({ + id: value, name: label, + }) => ({ + value, + label, + })), + }; + }, + }, + sectionId: { + type: "string", + label: "Section ID", + description: "The ID of the section", + async options({ + locale, categoryId, prevContext, + }) { + const { afterCursor } = prevContext; + const { + sections, meta, + } = await this.listSections({ + locale, + categoryId, + params: { + [constants.PAGE_SIZE_PARAM]: constants.DEFAULT_LIMIT, + [constants.PAGE_AFTER_PARAM]: afterCursor, + }, + }); + return { + context: { + afterCursor: meta.after_cursor, + }, + options: sections.map(({ + id: value, name: label, + }) => ({ + value, + label, + })), + }; + }, + }, + articleId: { + type: "string", + label: "Article ID", + description: "The ID of the article. You can use the List Articles action to get the ID of the article.", + async options({ + locale, prevContext, + }) { + const { afterCursor } = prevContext; + const { + articles, meta, + } = await this.listArticles({ + locale, + params: { + [constants.PAGE_SIZE_PARAM]: constants.DEFAULT_LIMIT, + [constants.PAGE_AFTER_PARAM]: afterCursor, + }, + }); + return { + context: { + afterCursor: meta.after_cursor, + }, + options: articles.map(({ + id: value, name: label, + }) => ({ + value, + label, + })), + }; + }, + }, + macroId: { + type: "string", + label: "Macro ID", + description: "The ID of the macro", + async options({ prevContext }) { + const { afterCursor } = prevContext; + const { + macros, meta, + } = await this.listMacros({ + params: { + [constants.PAGE_SIZE_PARAM]: constants.DEFAULT_LIMIT, + [constants.PAGE_AFTER_PARAM]: afterCursor, + }, + }); + + return { + context: { + afterCursor: meta.after_cursor, + }, + options: macros.map(({ + id: value, title: label, + }) => ({ + value, + label, + })), + }; + }, + }, ticketCommentBody: { type: "string", label: "Comment body", @@ -336,13 +465,12 @@ export default { makeRequest({ step = this, url, path, headers, customSubdomain, ...args }) { - const config = { + return axios(step, { headers: this.getHeaders(headers), url: url ?? this.getUrl(path, customSubdomain), timeout: constants.DEFAULT_TIMEOUT, ...args, - }; - return axios(step, config); + }); }, getTicketInfo({ ticketId, ...args @@ -530,6 +658,12 @@ export default { ...args, }); }, + listActiveMacros(args = {}) { + return this.makeRequest({ + path: "/macros/active", + ...args, + }); + }, listMacroCategories(args = {}) { return this.makeRequest({ path: "/macros/categories", @@ -542,6 +676,78 @@ export default { ...args, }); }, + prepareLocalePath({ + locale = null, path, + }) { + return `/help_center${locale + ? `/${locale}` + : ""}${path}`; + }, + listArticleCategories({ + locale, ...args + } = {}) { + return this.makeRequest({ + path: this.prepareLocalePath({ + locale, + path: "/categories", + }), + ...args, + }); + }, + listSections({ + locale, categoryId, ...args + } = {}) { + return this.makeRequest({ + path: this.prepareLocalePath({ + locale, + path: `/${categoryId + ? `/categories/${categoryId}` + : ""}/sections`, + }), + ...args, + }); + }, + listArticles({ + locale, categoryId, sectionId, userId, ...args + } = {}) { + let path = ""; + if (categoryId) { + path = `/categories/${categoryId}`; + } + if (sectionId) { + path = `/sections/${sectionId}`; + } + if (userId) { + path = `/users/${userId}`; + } + + return this.makeRequest({ + path: this.prepareLocalePath({ + locale, + path: `${path}/articles`, + }), + ...args, + }); + }, + getArticle({ + articleId, locale, ...args + } = {}) { + return this.makeRequest({ + path: this.prepareLocalePath({ + locale, + path: `/articles/${articleId}`, + }), + ...args, + }); + }, + getMacro({ + macroId, ...args + }) { + return this.makeRequest({ + path: `/macros/${macroId}`, + ...args, + }); + }, async *paginate({ fn, args, resourceKey, max, }) {