Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions components/elevio/actions/create-article/create-article.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import app from "../../elevio.app.mjs";

export default {
key: "elevio-create-article",
name: "Create Article",
description: "Creates a new article in the Elevio knowledge base. [See the documentation](https://api-docs.elevio.help/en/articles/71-rest-api-articles).",
version: "0.0.1",
type: "action",
props: {
app,
categoryId: {
propDefinition: [
app,
"categoryId",
],
},
restriction: {
propDefinition: [
app,
"restriction",
],
},
discoverable: {
propDefinition: [
app,
"discoverable",
],
},
isInternal: {
propDefinition: [
app,
"isInternal",
],
},
notes: {
propDefinition: [
app,
"notes",
],
},
status: {
propDefinition: [
app,
"status",
],
},
title: {
propDefinition: [
app,
"title",
],
},
body: {
propDefinition: [
app,
"body",
],
},
keywords: {
propDefinition: [
app,
"keywords",
],
},
tags: {
propDefinition: [
app,
"tags",
],
},
externalId: {
propDefinition: [
app,
"externalId",
],
},
},
methods: {
createArticle(args = {}) {
return this.app.post({
path: "/articles",
...args,
});
},
},
async run({ $ }) {
const {
createArticle,
externalId,
restriction,
discoverable,
isInternal,
notes,
status,
title,
body,
keywords,
tags,
categoryId,
} = this;
const response = await createArticle({
$,
data: {
article: {
external_id: externalId,
restriction,
discoverable,
is_internal: isInternal,
notes,
status,
category_id: categoryId,
keywords,
tags,
translations: [
{
language_id: "en",
title,
body,
},
],
},
},
});

$.export("$summary", `Successfully created article with ID \`${response.article.id}\`.`);
return response;
},
};
41 changes: 41 additions & 0 deletions components/elevio/actions/delete-article/delete-article.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import app from "../../elevio.app.mjs";

export default {
key: "elevio-delete-article",
name: "Delete Article",
description: "Deletes an existing article from the Elevio knowledge base. [See the documentation](https://api-docs.elevio.help/en/articles/71-rest-api-articles).",
version: "0.0.1",
type: "action",
props: {
app,
articleId: {
propDefinition: [
app,
"articleId",
],
},
},
methods: {
deleteArticle({
articleId, ...args
}) {
return this.app.delete({
path: `/articles/${articleId}`,
...args,
});
},
},
async run({ $ }) {
const {
deleteArticle,
articleId,
} = this;

const response = await deleteArticle({
$,
articleId,
});
$.export("$summary", "Successfully deleted article.");
return response;
},
};
149 changes: 149 additions & 0 deletions components/elevio/actions/update-article/update-article.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import app from "../../elevio.app.mjs";

export default {
key: "elevio-update-article",
name: "Update Article",
description: "Updates an existing article in the Elevio knowledge base. [See the documentation](https://api-docs.elevio.help/en/articles/71-rest-api-articles).",
version: "0.0.1",
type: "action",
props: {
app,
articleId: {
propDefinition: [
app,
"articleId",
],
},
categoryId: {
propDefinition: [
app,
"categoryId",
],
},
restriction: {
optional: true,
propDefinition: [
app,
"restriction",
],
},
discoverable: {
optional: true,
propDefinition: [
app,
"discoverable",
],
},
isInternal: {
optional: true,
propDefinition: [
app,
"isInternal",
],
},
notes: {
optional: true,
propDefinition: [
app,
"notes",
],
},
status: {
optional: true,
propDefinition: [
app,
"status",
],
},
title: {
optional: true,
propDefinition: [
app,
"title",
],
},
body: {
optional: true,
propDefinition: [
app,
"body",
],
},
keywords: {
propDefinition: [
app,
"keywords",
],
},
tags: {
propDefinition: [
app,
"tags",
],
},
externalId: {
propDefinition: [
app,
"externalId",
],
},
},
methods: {
updateArticle({
articleId, ...args
} = {}) {
return this.app.put({
path: `/articles/${articleId}`,
...args,
});
},
},
async run({ $ }) {
const {
updateArticle,
articleId,
externalId,
restriction,
discoverable,
isInternal,
notes,
status,
title,
body,
keywords,
tags,
categoryId,
} = this;
const response = await updateArticle({
$,
articleId,
data: {
article: {
external_id: externalId,
restriction,
discoverable,
is_internal: isInternal,
notes,
status,
keywords,
tags,
category_id: categoryId,
...((title || body)
? {
translations: [
{
language_id: "en",
title,
body,
},
],
}
: {}),
},
},
});

$.export("$summary", `Successfully updated article with ID \`${response.article.id}\`.`);
return response;
},
};
15 changes: 15 additions & 0 deletions components/elevio/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const BASE_URL = "https://api.elev.io";
const VERSION_PATH = "/v1";
const IS_FIRST_RUN = "isFirstRun";
const LAST_DATE_AT = "lastDateAt";
const DEFAULT_LIMIT = 100;
const DEFAULT_MAX = 600;

export default {
BASE_URL,
VERSION_PATH,
IS_FIRST_RUN,
LAST_DATE_AT,
DEFAULT_LIMIT,
DEFAULT_MAX,
};
17 changes: 17 additions & 0 deletions components/elevio/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
async function iterate(iterations) {
const items = [];
for await (const item of iterations) {
items.push(item);
}
return items;
}

function getNestedProperty(obj, propertyString) {
const properties = propertyString.split(".");
return properties.reduce((prev, curr) => prev?.[curr], obj);
}

export default {
iterate,
getNestedProperty,
};
Loading
Loading