Skip to content

Commit 82018d8

Browse files
committed
[ACTION] Front - Articles
1 parent 64f3488 commit 82018d8

File tree

11 files changed

+482
-1
lines changed

11 files changed

+482
-1
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import fs from "fs";
2+
import path from "path";
3+
import frontapp from "../../frontapp.app.mjs";
4+
5+
export default {
6+
key: "frontapp-download-article-attachment",
7+
name: "Download Article Attachment",
8+
description: "Downloads the attachment from an article. [See the documentation](https://dev.frontapp.com/reference/download-attachment-from-an-article)",
9+
version: "0.0.1",
10+
annotations: {
11+
destructiveHint: false,
12+
openWorldHint: true,
13+
readOnlyHint: true,
14+
},
15+
type: "action",
16+
props: {
17+
frontapp,
18+
articleId: {
19+
propDefinition: [
20+
frontapp,
21+
"articleId",
22+
],
23+
},
24+
attachmentId: {
25+
type: "string",
26+
label: "Attachment ID",
27+
description: "The ID of the file to download",
28+
},
29+
filename: {
30+
type: "string",
31+
label: "Filename",
32+
description: "The filename to save the file as in the `/tmp` directory",
33+
optional: true,
34+
},
35+
syncDir: {
36+
type: "dir",
37+
accessMode: "write",
38+
sync: true,
39+
},
40+
},
41+
async run({ $ }) {
42+
const response = await this.frontapp.downloadArticleAttachment({
43+
$,
44+
articleId: this.articleId,
45+
attachmentId: this.attachmentId,
46+
responseType: "arraybuffer",
47+
});
48+
49+
// Extract filename from content-disposition header or use provided filename
50+
const contentDisposition = response.headers["content-disposition"];
51+
const headerFileName = contentDisposition?.match(/filename\*?=(?:UTF-8'')?([^;]+)/)?.[1]?.replace(/['"]/g, "");
52+
const fileName = this.filename || headerFileName || this.attachmentId;
53+
const filePath = path.join("/tmp", fileName);
54+
55+
// The response.data contains the binary content of the attachment file
56+
const buffer = Buffer.isBuffer(response.data)
57+
? response.data
58+
: Buffer.from(response.data);
59+
fs.writeFileSync(filePath, buffer);
60+
61+
// Get file size from content-length header or buffer
62+
const fileSize = response.headers["content-length"] || buffer.length;
63+
64+
$.export("$summary", `Successfully downloaded attachment: ${fileName} (${fileSize} bytes)`);
65+
66+
return filePath;
67+
},
68+
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import frontapp from "../../frontapp.app.mjs";
2+
3+
export default {
4+
key: "frontapp-get-knowledge-base-article",
5+
name: "Get Knowledge Base Article",
6+
description: "Fetches a knowledge base article. [See the documentation](https://dev.frontapp.com/reference/get-a-knowledge-base-article)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
frontapp,
16+
knowledgeBaseId: {
17+
propDefinition: [
18+
frontapp,
19+
"knowledgeBaseId",
20+
],
21+
},
22+
articleId: {
23+
propDefinition: [
24+
frontapp,
25+
"articleId",
26+
({ knowledgeBaseId }) => ({
27+
knowledgeBaseId,
28+
}),
29+
],
30+
},
31+
},
32+
async run({ $ }) {
33+
const article = await this.frontapp.getKnowledgeBaseArticle({
34+
$,
35+
articleId: this.articleId,
36+
});
37+
38+
$.export("$summary", `Successfully retrieved knowledge base article with ID: ${this.articleId}`);
39+
40+
return article;
41+
},
42+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import frontapp from "../../frontapp.app.mjs";
2+
3+
export default {
4+
key: "frontapp-get-knowledge-base",
5+
name: "Get Knowledge Base",
6+
description: "Fetches a knowledge base. [See the documentation](https://dev.frontapp.com/reference/get-a-knowledge-base)",
7+
version: "0.0.1",
8+
annotations: {
9+
destructiveHint: false,
10+
openWorldHint: true,
11+
readOnlyHint: true,
12+
},
13+
type: "action",
14+
props: {
15+
frontapp,
16+
knowledgeBaseId: {
17+
propDefinition: [
18+
frontapp,
19+
"knowledgeBaseId",
20+
],
21+
},
22+
},
23+
async run({ $ }) {
24+
const knowledgeBase = await this.frontapp.getKnowledgeBase({
25+
$,
26+
knowledgeBaseId: this.knowledgeBaseId,
27+
});
28+
29+
$.export("$summary", `Successfully retrieved knowledge base with ID: ${this.knowledgeBaseId}`);
30+
31+
return knowledgeBase;
32+
},
33+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import frontapp from "../../frontapp.app.mjs";
2+
3+
export default {
4+
key: "frontapp-get-message-template-folder",
5+
name: "Get Message Template Folder",
6+
description: "Fetch a message template folder. [See the documentation](https://dev.frontapp.com/reference/get-folder)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
frontapp,
16+
folderId: {
17+
propDefinition: [
18+
frontapp,
19+
"folderId",
20+
],
21+
},
22+
},
23+
async run({ $ }) {
24+
const folder = await this.frontapp.getMessageTemplateFolder({
25+
$,
26+
folderId: this.folderId,
27+
});
28+
29+
$.export("$summary", `Successfully retrieved message template folder with ID: ${this.folderId}`);
30+
31+
return folder;
32+
},
33+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import frontapp from "../../frontapp.app.mjs";
2+
3+
export default {
4+
key: "frontapp-get-message-template",
5+
name: "Get Message Template",
6+
description: "Fetch a message template. [See the documentation](https://dev.frontapp.com/reference/get-message-template)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
frontapp,
16+
messageTemplateId: {
17+
propDefinition: [
18+
frontapp,
19+
"messageTemplateId",
20+
],
21+
},
22+
},
23+
async run({ $ }) {
24+
const messageTemplate = await this.frontapp.getMessageTemplate({
25+
$,
26+
messageTemplateId: this.messageTemplateId,
27+
});
28+
29+
$.export("$summary", `Successfully retrieved message template with ID: ${this.messageTemplateId}`);
30+
31+
return messageTemplate;
32+
},
33+
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import frontapp from "../../frontapp.app.mjs";
2+
3+
export default {
4+
key: "frontapp-list-knowledge-base-articles",
5+
name: "List Knowledge Base Articles",
6+
description: "List articles in a knowledge base. [See the documentation](https://dev.frontapp.com/reference/list-articles-in-a-knowledge-base)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
frontapp,
16+
knowledgeBaseId: {
17+
propDefinition: [
18+
frontapp,
19+
"knowledgeBaseId",
20+
],
21+
},
22+
maxResults: {
23+
propDefinition: [
24+
frontapp,
25+
"maxResults",
26+
],
27+
},
28+
},
29+
async run({ $ }) {
30+
const articles = [];
31+
32+
for await (const article of this.frontapp.paginate({
33+
fn: this.frontapp.listKnowledgeBaseArticles,
34+
args: {
35+
knowledgeBaseId: this.knowledgeBaseId,
36+
},
37+
maxResults: this.maxResults,
38+
})) {
39+
articles.push(article);
40+
}
41+
42+
$.export("$summary", `Successfully retrieved ${articles.length} articles from knowledge base ${this.knowledgeBaseId}`);
43+
44+
return articles;
45+
},
46+
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import frontapp from "../../frontapp.app.mjs";
2+
3+
export default {
4+
key: "frontapp-list-knowledge-base-categories",
5+
name: "List Knowledge Base Categories",
6+
description: "List categories in a knowledge base. [See the documentation](https://dev.frontapp.com/reference/list-categories-in-a-knowledge-base)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
frontapp,
16+
knowledgeBaseId: {
17+
propDefinition: [
18+
frontapp,
19+
"knowledgeBaseId",
20+
],
21+
},
22+
maxResults: {
23+
propDefinition: [
24+
frontapp,
25+
"maxResults",
26+
],
27+
},
28+
},
29+
async run({ $ }) {
30+
const categories = [];
31+
32+
for await (const category of this.frontapp.paginate({
33+
fn: this.frontapp.listKnowledgeBaseCategories,
34+
args: {
35+
knowledgeBaseId: this.knowledgeBaseId,
36+
},
37+
maxResults: this.maxResults,
38+
})) {
39+
categories.push(category);
40+
}
41+
42+
$.export("$summary", `Successfully retrieved ${categories.length} categories from knowledge base ${this.knowledgeBaseId}`);
43+
44+
return categories;
45+
},
46+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import frontapp from "../../frontapp.app.mjs";
2+
3+
export default {
4+
key: "frontapp-list-knowledge-bases",
5+
name: "List Knowledge Bases",
6+
description: "List the knowledge bases of the company. [See the documentation](https://dev.frontapp.com/reference/list-knowledge-bases)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
frontapp,
16+
},
17+
async run({ $ }) {
18+
const response = await this.frontapp.listKnowledgeBases({
19+
$,
20+
});
21+
22+
$.export("$summary", `Successfully retrieved ${response._results.length} knowledge bases`);
23+
24+
return response._results;
25+
},
26+
};
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import frontapp from "../../frontapp.app.mjs";
2+
3+
export default {
4+
key: "frontapp-list-message-template-folders",
5+
name: "List Message Template Folders",
6+
description: "List the message template folders. [See the documentation](https://dev.frontapp.com/reference/list-folders)",
7+
version: "0.0.1",
8+
annotations: {
9+
destructiveHint: false,
10+
openWorldHint: true,
11+
readOnlyHint: true,
12+
},
13+
type: "action",
14+
props: {
15+
frontapp,
16+
sortBy: {
17+
type: "string",
18+
label: "Sort By",
19+
description: "Field used to sort the message template folders. Either `created_at` or `updated_at`.",
20+
optional: true,
21+
},
22+
sortOrder: {
23+
type: "string",
24+
label: "Sort Order",
25+
description: "Order by which results should be sorted",
26+
options: [
27+
"asc",
28+
"desc",
29+
],
30+
optional: true,
31+
},
32+
},
33+
async run({ $ }) {
34+
const params = {};
35+
36+
if (this.sortBy) {
37+
params.sort_by = this.sortBy;
38+
}
39+
if (this.sortOrder) {
40+
params.sort_order = this.sortOrder;
41+
}
42+
43+
const response = await this.frontapp.listMessageTemplateFolders({
44+
$,
45+
params,
46+
});
47+
48+
$.export("$summary", `Successfully retrieved ${response._results.length} message template folders`);
49+
50+
return response._results;
51+
},
52+
};

0 commit comments

Comments
 (0)