Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
65 changes: 65 additions & 0 deletions components/trengo/actions/list-articles/list-articles.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import utils from "../../common/utils.mjs";
import app from "../../trengo.app.mjs";

export default {
type: "action",
key: "trengo-list-articles",
version: "0.0.1",
name: "List Articles",
description: "List articles from a help center according to the specified criteria. [See the docs](https://developers.trengo.com/reference/list-all-articles)",
props: {
app,
helpCenterId: {
propDefinition: [
app,
"helpCenterId",
],
},
localeCode: {
type: "string",
label: "Locale Code",
description: "The article's locale code",
optional: true,
default: "en",
},
filter: {
type: "string",
label: "Filter",
description: "The article's filter. You can choose one of the available options, specify `untranslated_<language_code>` for other language codes, or leave empty for all articles",
optional: true,
options: [
"draft",
"published",
"untranslated_en",
],
},
term: {
type: "string",
label: "Search Term",
description: "The article's search term (if not specified, all articles will be returned)",
optional: true,
},
},
async run({ $ }) {
const articles = [];
const resourcesStream = utils.getResourcesStream({
resourceFn: this.app.getArticles,
resourceFnArgs: {
helpCenterId: this.helpCenterId,
params: {
localeCode: this.localeCode,
filter: this.filter,
term: this.term,
},
},
});
for await (const item of resourcesStream) {
articles.push(item);
}
const length = articles.length;
$.export("$summary", `Successfully retrieved ${length} article${length === 1
? ""
: "s"}`);
return articles;
},
};
2 changes: 1 addition & 1 deletion components/trengo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/trengo",
"version": "0.1.0",
"version": "0.2.0",
"description": "Pipedream Trengo Components",
"main": "trengo.app.mjs",
"keywords": [
Expand Down
29 changes: 29 additions & 0 deletions components/trengo/sources/ticket-closed/ticket-closed.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import common from "../common/common.mjs";

export default {
key: "trengo-ticket-closed",
name: "Ticket Closed (Instant)",

Check warning on line 5 in components/trengo/sources/ticket-closed/ticket-closed.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Source names should start with "New". See https://pipedream.com/docs/components/guidelines/#source-name
description: "Emit new event when a ticket is closed. [See the documentation](https://developers.trengo.com/docs/webhooks)",
version: "0.0.1",
type: "source",
dedupe: "unique",
...common,
methods: {
...common.methods,
getMeta(event) {
const ts = Date.now();
const id = event?.body?.ticket_id ?
parseInt(event.body.ticket_id) :
ts;
const summary = `Ticket closed: #${id} (Status: ${event?.body?.status})`;
return {
id,
ts,
summary,
};
},
getEvent() {
return "TICKET_CLOSED";
},
},
};
29 changes: 29 additions & 0 deletions components/trengo/sources/ticket-reopened/ticket-reopened.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import common from "../common/common.mjs";

export default {
key: "trengo-ticket-reopened",
name: "Ticket Reopened (Instant)",

Check warning on line 5 in components/trengo/sources/ticket-reopened/ticket-reopened.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Source names should start with "New". See https://pipedream.com/docs/components/guidelines/#source-name
description: "Emit new event when a ticket is reopened. [See the documentation](https://developers.trengo.com/docs/webhooks)",
version: "0.0.1",
type: "source",
dedupe: "unique",
...common,
methods: {
...common.methods,
getMeta(event) {
const ts = Date.now();
const id = event?.body?.ticket_id ?
parseInt(event.body.ticket_id) :
ts;
const summary = `Ticket reopened: #${id} (Status: ${event?.body?.status})`;
return {
id,
ts,
summary,
};
},
getEvent() {
return "TICKET_REOPENED";
},
},
};
51 changes: 49 additions & 2 deletions components/trengo/trengo.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,20 @@ export default {
description: "The WhatsApp template ID.",
},
ticketId: {
type: "string",
type: "integer",
label: "Ticket ID",
description: "The ticket ID. Only required if `Recipient Phone Number` is not set.",
description: "Select a ticket or provide an ID",
async options({ page = 0 }) {
const response = await this.getTickets({
params: {
page: page + 1,
},
});
return response.data.map((ticket) => ({
label: `#${ticket.ticket_id} - ${ticket.subject || "No subject"}`,
value: ticket.ticket_id,
}));
},
},
whatsappTemplateParamsKeys: {
type: "string[]",
Expand Down Expand Up @@ -146,6 +157,22 @@ export default {
description: "Search term to find a contact. If not given, all contacts will be returned.",
optional: true,
},
helpCenterId: {
type: "integer",
label: "Help Center ID",
description: "Select a help center or provide an ID",
async options({ page = 0 }) {
const response = await this.getHelpCenters({
params: {
page: page + 1,
},
});
return response.data.map((helpCenter) => ({
label: helpCenter.name || helpCenter.slug,
value: helpCenter.id,
}));
},
},
},
methods: {
_getUrl(path) {
Expand Down Expand Up @@ -241,5 +268,25 @@ export default {
...args,
});
},
async getHelpCenters(args = {}) {
return this._makeRequest({
path: "/help_center",
...args,
});
},
async getArticles({
helpCenterId, ...args
} = {}) {
return this._makeRequest({
path: `/help_center/${helpCenterId}/articles`,
...args,
});
},
async getTickets(args = {}) {
return this._makeRequest({
path: "/tickets",
...args,
});
},
},
};
3 changes: 1 addition & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading