diff --git a/components/zoho_desk/actions/get-article/get-article.mjs b/components/zoho_desk/actions/get-article/get-article.mjs new file mode 100644 index 0000000000000..53f0cc36cd489 --- /dev/null +++ b/components/zoho_desk/actions/get-article/get-article.mjs @@ -0,0 +1,55 @@ +import zohoDesk from "../../zoho_desk.app.mjs"; + +export default { + key: "zoho_desk-get-article", + name: "Get Article", + description: "Retrieves the details of a knowledge base article. [See the docs here](https://desk.zoho.com/portal/APIDocument.do#KnowledgeBase_Getarticle)", + type: "action", + version: "0.0.1", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + props: { + zohoDesk, + orgId: { + propDefinition: [ + zohoDesk, + "orgId", + ], + }, + portalId: { + propDefinition: [ + zohoDesk, + "portalId", + ({ orgId }) => ({ + orgId, + }), + ], + }, + articleId: { + propDefinition: [ + zohoDesk, + "articleId", + ], + }, + }, + async run({ $ }) { + const { + portalId, + articleId, + } = this; + + const article = await this.zohoDesk.getKnowledgeBaseArticle({ + articleId, + params: { + portalId, + }, + }); + + $.export("$summary", `Fetched article ${article.title || articleId}.`); + + return article; + }, +}; diff --git a/components/zoho_desk/actions/list-articles/list-articles.mjs b/components/zoho_desk/actions/list-articles/list-articles.mjs new file mode 100644 index 0000000000000..9188bee393002 --- /dev/null +++ b/components/zoho_desk/actions/list-articles/list-articles.mjs @@ -0,0 +1,97 @@ +import zohoDesk from "../../zoho_desk.app.mjs"; + +export default { + key: "zoho_desk-list-articles", + name: "List Articles", + description: "Lists knowledge base articles for a help center. [See the docs here](https://desk.zoho.com/portal/APIDocument.do#KnowledgeBase#KnowledgeBase_Listarticles)", + type: "action", + version: "0.0.1", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + props: { + zohoDesk, + orgId: { + propDefinition: [ + zohoDesk, + "orgId", + ], + }, + portalId: { + propDefinition: [ + zohoDesk, + "portalId", + ({ orgId }) => ({ + orgId, + }), + ], + }, + categoryId: { + type: "string", + label: "Category ID", + description: "Filter by the ID(s) of the categories the articles belong to. Use comma-separated IDs to include multiple categories.", + optional: true, + }, + sortBy: { + type: "string", + label: "Sort By", + description: "Sort articles by the specified attribute.", + optional: true, + options: [ + "createdTime", + "modifiedTime", + "likeCount", + "viewCount", + "unlikeCount", + ], + default: "createdTime", + }, + tag: { + type: "string", + label: "Tag", + description: "Filter articles by a tag.", + optional: true, + }, + maxResults: { + type: "integer", + label: "Max Results", + description: "Maximum number of articles to return. Leave blank to return all available results.", + optional: true, + }, + }, + async run({ $ }) { + const { + portalId, + categoryId, + sortBy, + tag, + maxResults, + } = this; + + const params = { + portalId, + categoryId, + sortBy, + tag, + }; + + const articles = []; + const stream = this.zohoDesk.listKnowledgeBaseArticlesStream({ + params, + }); + for await (const article of stream) { + articles.push(article); + if (maxResults && articles.length >= maxResults) { + break; + } + } + + $.export("$summary", `Retrieved ${articles.length} article${articles.length === 1 + ? "" + : "s"}.`); + + return articles; + }, +}; diff --git a/components/zoho_desk/actions/list-help-centers/list-help-centers.mjs b/components/zoho_desk/actions/list-help-centers/list-help-centers.mjs new file mode 100644 index 0000000000000..35e18c6051198 --- /dev/null +++ b/components/zoho_desk/actions/list-help-centers/list-help-centers.mjs @@ -0,0 +1,39 @@ +import zohoDesk from "../../zoho_desk.app.mjs"; + +export default { + key: "zoho_desk-list-help-centers", + name: "List Help Centers", + description: "Lists the help centers configured in an organization. [See the docs here](https://desk.zoho.com/portal/APIDocument.do#HelpCenters_Listhelpcenters)", + type: "action", + version: "0.0.1", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + props: { + zohoDesk, + orgId: { + propDefinition: [ + zohoDesk, + "orgId", + ], + }, + }, + async run({ $ }) { + const { orgId } = this; + + const { data: helpCenters = [] } = + await this.zohoDesk.listHelpCenters({ + params: { + orgId, + }, + }); + + $.export("$summary", `Retrieved ${helpCenters.length} help center${helpCenters.length === 1 + ? "" + : "s"}.`); + + return helpCenters; + }, +}; diff --git a/components/zoho_desk/actions/list-root-categories/list-root-categories.mjs b/components/zoho_desk/actions/list-root-categories/list-root-categories.mjs new file mode 100644 index 0000000000000..ad3cb50973c7c --- /dev/null +++ b/components/zoho_desk/actions/list-root-categories/list-root-categories.mjs @@ -0,0 +1,109 @@ +import zohoDesk from "../../zoho_desk.app.mjs"; + +export default { + key: "zoho_desk-list-root-categories", + name: "List Root Categories", + description: "Lists root knowledge base categories for a help center. [See the docs here](https://desk.zoho.com/portal/APIDocument.do#KnowledgeBase_Listallrootcategoriesofthehelpcenter)", + type: "action", + version: "0.0.1", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + props: { + zohoDesk, + orgId: { + propDefinition: [ + zohoDesk, + "orgId", + ], + }, + portalId: { + propDefinition: [ + zohoDesk, + "portalId", + ({ orgId }) => ({ + orgId, + }), + ], + }, + sortBy: { + type: "string", + label: "Sort By", + description: "Sort the categories by the specified attribute.", + optional: true, + options: [ + "name", + "order", + ], + }, + searchValue: { + type: "string", + label: "Search Value", + description: "Filter categories whose names match the provided value.", + optional: true, + }, + visibility: { + type: "string", + label: "Visibility", + description: "Filter categories by visibility (e.g. ALL_USERS).", + optional: true, + }, + departmentId: { + type: "string", + label: "Department ID", + description: "Filter categories associated with the specified department.", + optional: true, + }, + hasArticles: { + type: "boolean", + label: "Has Articles", + description: "Return only categories that contain articles when set to `true`.", + optional: true, + }, + maxResults: { + type: "integer", + label: "Max Results", + description: "Maximum number of categories to return. Leave blank to return all available results.", + optional: true, + }, + }, + async run({ $ }) { + const { + portalId, + sortBy, + searchValue, + visibility, + departmentId, + hasArticles, + maxResults, + } = this; + + const params = { + portalId, + sortBy, + searchValue, + visibility, + departmentId, + hasArticles, + }; + + const categories = []; + const stream = this.zohoDesk.listKnowledgeBaseRootCategoriesStream({ + params, + }); + for await (const category of stream) { + categories.push(category); + if (maxResults && categories.length >= maxResults) { + break; + } + } + + $.export("$summary", `Retrieved ${categories.length} root categor${categories.length === 1 + ? "y" + : "ies"}.`); + + return categories; + }, +}; diff --git a/components/zoho_desk/actions/search-articles/search-articles.mjs b/components/zoho_desk/actions/search-articles/search-articles.mjs new file mode 100644 index 0000000000000..194d60be0fb29 --- /dev/null +++ b/components/zoho_desk/actions/search-articles/search-articles.mjs @@ -0,0 +1,112 @@ +import zohoDesk from "../../zoho_desk.app.mjs"; + +export default { + key: "zoho_desk-search-articles", + name: "Search Articles", + description: "Searches for knowledge base articles. [See the docs here](https://desk.zoho.com/portal/APIDocument.do#KnowledgeBase_Searcharticles)", + type: "action", + version: "0.0.1", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + props: { + zohoDesk, + orgId: { + propDefinition: [ + zohoDesk, + "orgId", + ], + }, + portalId: { + propDefinition: [ + zohoDesk, + "portalId", + ({ orgId }) => ({ + orgId, + }), + ], + }, + searchStr: { + type: "string", + label: "Search String", + description: "The keywords to search for within articles.", + }, + categoryId: { + type: "string", + label: "Category ID", + description: "Filter by articles belonging to the specified category.", + optional: true, + }, + sortBy: { + type: "string", + label: "Sort By", + description: "Sort the results by created time or relevance. Use `-createdTime` for descending order.", + optional: true, + options: [ + "createdTime", + "relevance", + "-createdTime", + ], + default: "relevance", + }, + searchKeyWordMatch: { + type: "string", + label: "Match Type", + description: "Specify how multiple search keywords must be matched in the results.", + optional: true, + options: [ + { + label: "Results matching at least one keyword", + value: "ANY", + }, + { + label: "Only results matching all keywords", + value: "ALL", + }, + ], + }, + maxResults: { + type: "integer", + label: "Max Results", + description: "Maximum number of articles to return. Leave blank to return all available matches.", + optional: true, + }, + }, + async run({ $ }) { + const { + portalId, + searchStr, + categoryId, + sortBy, + searchKeyWordMatch, + maxResults, + } = this; + + const params = { + portalId, + searchStr, + categoryId, + sortBy, + searchKeyWordMatch, + }; + + const articles = []; + const stream = this.zohoDesk.searchKnowledgeBaseArticlesStream({ + params, + }); + for await (const article of stream) { + articles.push(article); + if (maxResults && articles.length >= maxResults) { + break; + } + } + + $.export("$summary", `Found ${articles.length} article${articles.length === 1 + ? "" + : "s"}.`); + + return articles; + }, +}; diff --git a/components/zoho_desk/common/constants.mjs b/components/zoho_desk/common/constants.mjs index 3f304de8fa88c..7447e324781d4 100644 --- a/components/zoho_desk/common/constants.mjs +++ b/components/zoho_desk/common/constants.mjs @@ -8,7 +8,8 @@ const MULTIPART_FORM_DATA_HEADERS = { }; const TOKEN_PREFIX = "Zoho-oauthtoken"; const BASE_PREFIX_URL = "https://desk."; -const VERSION_PATH = "/api/v1"; +const CORE_API_PATH = "/api/v1"; +const PORTAL_API_PATH = "/portal/api"; const FILE_PROP_NAMES = [ "attachment", "uploaddoc", @@ -34,7 +35,8 @@ export default { MULTIPART_FORM_DATA_HEADERS, BASE_PREFIX_URL, TOKEN_PREFIX, - VERSION_PATH, + CORE_API_PATH, + PORTAL_API_PATH, FILE_PROP_NAMES, LAST_CREATED_AT, LAST_UPDATED_AT, diff --git a/components/zoho_desk/package.json b/components/zoho_desk/package.json index 147ab75b48470..cfb91a22e7626 100644 --- a/components/zoho_desk/package.json +++ b/components/zoho_desk/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/zoho_desk", - "version": "0.2.1", + "version": "0.2.2", "description": "Pipedream Zoho_desk Components", "main": "zoho_desk.app.mjs", "keywords": [ diff --git a/components/zoho_desk/zoho_desk.app.mjs b/components/zoho_desk/zoho_desk.app.mjs index a911852d9958a..9f3b4bc90016f 100644 --- a/components/zoho_desk/zoho_desk.app.mjs +++ b/components/zoho_desk/zoho_desk.app.mjs @@ -21,6 +21,29 @@ export default { })); }, }, + portalId: { + type: "string", + label: "Portal ID", + description: "Select the help center portal to target.", + async options({ orgId }) { + if (!orgId) { + return []; + } + const { data: helpCenters = [] } = + await this.listHelpCenters({ + params: { + orgId, + }, + }); + return helpCenters.map(({ + portalId: value, + name: label, + }) => ({ + value, + label: label || value, + })); + }, + }, departmentId: { type: "string", label: "Department ID", @@ -100,11 +123,16 @@ export default { return allowedValues.map(({ value }) => value); }, }, + articleId: { + type: "string", + label: "Article ID", + description: "The ID of the knowledge base article.", + }, }, methods: { - getUrl(url, path, versionPath) { + getUrl(url, path, apiPrefix) { const { region } = this.$auth; - return url || `${constants.BASE_PREFIX_URL}${region}${versionPath}${path}`; + return url || `${constants.BASE_PREFIX_URL}${region}${apiPrefix}${path}`; }, getHeaders(headers) { const { oauth_access_token: oauthAccessToken } = this.$auth; @@ -126,12 +154,12 @@ export default { path, params, headers, - versionPath = constants.VERSION_PATH, + apiPrefix = constants.CORE_API_PATH, withRetries = true, ...args } = {}) { const config = { - url: this.getUrl(url, path, versionPath), + url: this.getUrl(url, path, apiPrefix), params: this.getParams(url, params), headers: this.getHeaders(headers), ...args, @@ -264,6 +292,80 @@ export default { ...args, }); }, + listHelpCenters(args = {}) { + return this.makeRequest({ + path: "/helpCenters", + apiPrefix: constants.PORTAL_API_PATH, + ...args, + }); + }, + listKnowledgeBaseArticles(args = {}) { + return this.makeRequest({ + path: "/kbArticles", + apiPrefix: constants.PORTAL_API_PATH, + ...args, + }); + }, + async *listKnowledgeBaseArticlesStream({ + params, + ...args + } = {}) { + yield* this.getResourcesStream({ + resourceFn: this.listKnowledgeBaseArticles, + resourceFnArgs: { + ...args, + params, + }, + }); + }, + getKnowledgeBaseArticle({ + articleId, + ...args + } = {}) { + return this.makeRequest({ + path: `/kbArticles/${articleId}`, + apiPrefix: constants.PORTAL_API_PATH, + ...args, + }); + }, + searchKnowledgeBaseArticles(args = {}) { + return this.makeRequest({ + path: "/kbArticles/search", + apiPrefix: constants.PORTAL_API_PATH, + ...args, + }); + }, + async *searchKnowledgeBaseArticlesStream({ + params, + ...args + } = {}) { + yield* this.getResourcesStream({ + resourceFn: this.searchKnowledgeBaseArticles, + resourceFnArgs: { + ...args, + params, + }, + }); + }, + listKnowledgeBaseRootCategories(args = {}) { + return this.makeRequest({ + path: "/kbRootCategories", + apiPrefix: constants.PORTAL_API_PATH, + ...args, + }); + }, + async *listKnowledgeBaseRootCategoriesStream({ + params, + ...args + } = {}) { + yield* this.getResourcesStream({ + resourceFn: this.listKnowledgeBaseRootCategories, + resourceFnArgs: { + ...args, + params, + }, + }); + }, sendReply({ ticketId, ...args } = {}) {