Skip to content

Commit 7cf97b5

Browse files
committed
[Salesforce] Knowledge new action components
1 parent 56c6ec0 commit 7cf97b5

File tree

5 files changed

+299
-60
lines changed

5 files changed

+299
-60
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import app from "../../salesforce_rest_api.app.mjs";
2+
3+
export default {
4+
props: {
5+
app,
6+
// eslint-disable-next-line pipedream/props-label, pipedream/props-description
7+
info: {
8+
type: "alert",
9+
alertType: "info",
10+
content: "Please keep in mind that Salesforce Knowledge is available for an additional cost in: Professional Enterprise, Performance, and Developer Editions. For more information, contact your Salesforce representative. [See the documentation](https://help.salesforce.com/s/articleView?id=service.knowledge_map.htm&type=5)",
11+
},
12+
language: {
13+
type: "string",
14+
label: "Language",
15+
description: "The language code. Defaults to `en-US`.",
16+
optional: true,
17+
},
18+
},
19+
};
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import common from "../common/knowledge.mjs";
2+
3+
export default {
4+
...common,
5+
key: "salesforce_rest_api-get-knowledge-articles",
6+
name: "Get Knowledge Articles",
7+
description: "Get a page of online articles for the given language and category through either search or query. [See the documentation](https://developer.salesforce.com/docs/atlas.en-us.knowledge_dev.meta/knowledge_dev/sforce_api_rest_retrieve_article_list.htm)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
...common.props,
12+
q: {
13+
type: "string",
14+
label: "Search Term",
15+
description: "Performs an SOSL search. If this property is not set, an SOQL query runs. The characters `?` and `*` are used for wildcard searches. The characters `(`, `)`, and `\"` are used for complex search terms. [See the documentation](https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_find.htm).",
16+
optional: true,
17+
},
18+
channel: {
19+
type: "string",
20+
label: "Channel",
21+
description: "Where articles are visible (App, Pkb, Csp, Prm).",
22+
optional: true,
23+
options: [
24+
{
25+
label: "Internal Knowledge App",
26+
value: "App",
27+
},
28+
{
29+
label: "Public Knowledge Base",
30+
value: "Pkb",
31+
},
32+
{
33+
label: "Customer Portal",
34+
value: "Csp",
35+
},
36+
{
37+
label: "Partner Portal",
38+
value: "Prm",
39+
},
40+
],
41+
},
42+
categories: {
43+
type: "string",
44+
label: "Categories",
45+
description: "This should be a map in json format `{\"group1\": \"category1\", \"group2\": \"category2\", ...}`. It must be unique in each group:category pair, otherwise you get `ARGUMENT_OBJECT_PARSE_ERROR`. There is a limit of three data category conditions, otherwise you get `INVALID_FILTER_VALUE`.",
46+
optional: true,
47+
},
48+
queryMethod: {
49+
type: "string",
50+
label: "Query Method",
51+
description: "Only valid when categories are specified, defaults to `ABOVE_OR_BELOW`.",
52+
optional: true,
53+
options: [
54+
"AT",
55+
"BELOW",
56+
"ABOVE",
57+
"ABOVE_OR_BELOW",
58+
],
59+
},
60+
sort: {
61+
type: "string",
62+
label: "Sort By",
63+
description: "Field to sort results by. Defaults to `LastPublishedDate` for query and relevance for search",
64+
optional: true,
65+
options: [
66+
"LastPublishedDate",
67+
"CreatedDate",
68+
"Title",
69+
"ViewScore",
70+
],
71+
},
72+
},
73+
async run({ $ }) {
74+
const {
75+
app,
76+
q,
77+
channel,
78+
language,
79+
categories,
80+
queryMethod,
81+
sort,
82+
} = this;
83+
84+
const items = await app.paginate({
85+
resultsKey: "articles",
86+
requester: app.getKnowledgeArticles,
87+
requesterArgs: {
88+
$,
89+
headers: {
90+
...app._makeRequestHeaders(),
91+
"Accept": "application/json",
92+
"Accept-Language": language || "en-US",
93+
},
94+
params: {
95+
q,
96+
channel,
97+
categories,
98+
queryMethod,
99+
sort,
100+
},
101+
},
102+
});
103+
104+
$.export("$summary", `Successfully fetched \`${items.length}\` articles`);
105+
106+
return items;
107+
},
108+
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import common from "../common/knowledge.mjs";
2+
3+
export default {
4+
...common,
5+
key: "salesforce_rest_api-get-knowledge-data-category-groups",
6+
name: "Get Knowledge Data Category Groups",
7+
description: "Fetch data category groups visible to the current user. [See the documentation](https://developer.salesforce.com/docs/atlas.en-us.knowledge_dev.meta/knowledge_dev/resources_knowledge_support_dcgroups.htm)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
...common.props,
12+
topCategoriesOnly: {
13+
type: "boolean",
14+
label: "Top Categories Only",
15+
description: "Return only top-level categories if `true`, entire tree if `false`.",
16+
optional: true,
17+
},
18+
},
19+
async run({ $ }) {
20+
const {
21+
app,
22+
topCategoriesOnly,
23+
language,
24+
} = this;
25+
26+
const response = await app.getKnowledgeDataCategoryGroups({
27+
$,
28+
params: {
29+
sObjectName: "KnowledgeArticleVersion",
30+
topCategoriesOnly,
31+
},
32+
headers: {
33+
...app._makeRequestHeaders(),
34+
"Accept": "application/json",
35+
"Accept-Language": language || "en-US",
36+
},
37+
});
38+
39+
$.export("$summary", `Successfully fetched \`${response.categoryGroups?.length || 0}\` data category groups`);
40+
return response;
41+
},
42+
};

components/salesforce_rest_api/salesforce_rest_api.app.mjs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,5 +409,49 @@ export default {
409409
url: `${this._baseApiVersionUrl()}/jobs/ingest/${jobId}`,
410410
});
411411
},
412+
getKnowledgeArticles(args = {}) {
413+
return this._makeRequest({
414+
url: `${this._baseApiVersionUrl()}/support/knowledgeArticles`,
415+
...args,
416+
});
417+
},
418+
getKnowledgeDataCategoryGroups(args = {}) {
419+
return this._makeRequest({
420+
url: `${this._baseApiVersionUrl()}/support/dataCategoryGroups`,
421+
...args,
422+
});
423+
},
424+
async paginate({
425+
requester, requesterArgs, resultsKey = "articles",
426+
maxRequests = 3, pageSize = 100,
427+
} = {}) {
428+
let allItems = [];
429+
let currentPage = 1;
430+
let hasMore = true;
431+
432+
while (hasMore && currentPage <= maxRequests) {
433+
const response = await requester({
434+
...requesterArgs,
435+
params: {
436+
...requesterArgs?.params,
437+
pageSize,
438+
pageNumber: currentPage,
439+
},
440+
});
441+
442+
const items = response[resultsKey];
443+
if (items?.length) {
444+
allItems = [
445+
...allItems,
446+
...items,
447+
];
448+
}
449+
450+
hasMore = !!response.nextPageUrl;
451+
currentPage++;
452+
}
453+
454+
return allItems;
455+
},
412456
},
413457
};

0 commit comments

Comments
 (0)