Skip to content

Commit

Permalink
[Components] unthread #13686 (#13852)
Browse files Browse the repository at this point in the history
* Added actions

* Update components/unthread/actions/create-customer/create-customer.mjs

Co-authored-by: Guilherme Falcão <[email protected]>

* Update components/unthread/actions/update-customer/update-customer.mjs

Co-authored-by: Guilherme Falcão <[email protected]>

* ESLint

---------

Co-authored-by: Guilherme Falcão <[email protected]>
Co-authored-by: GTFalcao <[email protected]>
  • Loading branch information
3 people authored Sep 10, 2024
1 parent a472ad8 commit 0748914
Show file tree
Hide file tree
Showing 6 changed files with 264 additions and 7 deletions.
43 changes: 43 additions & 0 deletions components/unthread/actions/create-customer/create-customer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import app from "../../unthread.app.mjs";

export default {
key: "unthread-create-customer",
name: "Create Customer",
description: "Create a new Customer. [See the documentation](https://docs.unthread.io/api-introduction/using-api#create-customer)",
version: "0.0.1",
type: "action",
props: {
app,
slackChannelId: {
propDefinition: [
app,
"slackChannelId",
],
},
name: {
propDefinition: [
app,
"name",
],
},
emailDomains: {
propDefinition: [
app,
"emailDomains",
],
},
},
async run({ $ }) {
const {
app, ...data
} = this;
const response = await app.createCustomer({
$,
data,
});

$.export("$summary", `Successfully created Customer with ID '${response.id}'`);

return response;
},
};
28 changes: 28 additions & 0 deletions components/unthread/actions/delete-customer/delete-customer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import app from "../../unthread.app.mjs";

export default {
key: "unthread-delete-customer",
name: "Delete Customer",
description: "Delete a Customer. [See the documentation](https://docs.unthread.io/api-introduction/using-api#delete-customer)",
version: "0.0.1",
type: "action",
props: {
app,
customerId: {
propDefinition: [
app,
"customerId",
],
},
},
async run({ $ }) {
const response = await this.app.deleteCustomer({
$,
customerId: this.customerId,
});

$.export("$summary", `Successfully deleted Customer with ID '${this.customerId}'`);

return response;
},
};
71 changes: 71 additions & 0 deletions components/unthread/actions/update-customer/update-customer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import app from "../../unthread.app.mjs";

export default {
key: "unthread-update-customer",
name: "Update Customer",
description: "Update a Customer. [See the documentation](https://docs.unthread.io/api-introduction/using-api#update-customer)",
version: "0.0.1",
type: "action",
props: {
app,
customerId: {
propDefinition: [
app,
"customerId",
],
},
slackChannelId: {
propDefinition: [
app,
"slackChannelId",
],
optional: true,
},
name: {
propDefinition: [
app,
"name",
],
optional: true,
},
emailDomains: {
propDefinition: [
app,
"emailDomains",
],
optional: true,
},
disableAutomatedTicketing: {
propDefinition: [
app,
"disableAutomatedTicketing",
],
},
slackTeamId: {
propDefinition: [
app,
"slackTeamId",
],
},
defaultTriageChannelId: {
propDefinition: [
app,
"defaultTriageChannelId",
],
},
},
async run({ $ }) {
const {
app, customerId, ...data
} = this;
const response = await app.updateCustomer({
$,
customerId,
data,
});

$.export("$summary", `Successfully updated Customer with ID '${response.id}'`);

return response;
},
};
7 changes: 5 additions & 2 deletions components/unthread/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/unthread",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Unthread Components",
"main": "unthread.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.6.6"
}
}
}
106 changes: 102 additions & 4 deletions components/unthread/unthread.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,109 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "unthread",
propDefinitions: {},
propDefinitions: {
customerId: {
type: "string",
label: "Customer ID",
description: "ID of the Customer",
async options() {
const response = await this.listCustomers();
const customersIds = response.data;
return customersIds.map(({
id, name,
}) => ({
value: id,
label: name,
}));
},
},
slackChannelId: {
type: "string",
label: "Slack Channel ID",
description: "ID the customer's Slack Channel",
},
name: {
type: "string",
label: "Name",
description: "Name of the customer",
},
emailDomains: {
type: "string[]",
label: "Email Domains",
description: "Email Domains of the customer, i.e.: `gmail.com`",
},
defaultTriageChannelId: {
type: "string",
label: "Default Triage Channel",
description: "ID of the default triage Channel of this customer",
optional: true,
},
disableAutomatedTicketing: {
type: "boolean",
label: "Automated Ticketing",
description: "Disable Automated Ticketing for this customer",
optional: true,
},
slackTeamId: {
type: "string",
label: "Slack Team ID",
description: "ID of the Slack Team",
optional: true,
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.unthread.io/api";
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
headers: {
...headers,
"X-Api-Key": `${this.$auth.api_key}`,
},
});
},
async createCustomer(args = {}) {
return this._makeRequest({
method: "post",
path: "/customers",
...args,
});
},
async updateCustomer({
customerId, ...args
}) {
return this._makeRequest({
method: "patch",
path: `/customers/${customerId}`,
...args,
});
},
async deleteCustomer({
customerId, ...args
}) {
return this._makeRequest({
method: "delete",
path: `/customers/${customerId}`,
...args,
});
},
async listCustomers(args = {}) {
return this._makeRequest({
method: "post",
path: "/customers/list",
...args,
});
},
},
};
16 changes: 15 additions & 1 deletion pnpm-lock.yaml

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

0 comments on commit 0748914

Please sign in to comment.