Skip to content

Commit

Permalink
Merge pull request #872 from activepieces/piece/zendesk
Browse files Browse the repository at this point in the history
feat: zendesk new ticket in view
  • Loading branch information
abuaboud committed Mar 30, 2023
2 parents 1ff1904 + d1a8cc3 commit 9b4e2f7
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/pieces/apps/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { square } from '@activepieces/piece-square';
import { delay } from '@activepieces/piece-delay';
import { dataMapper } from '@activepieces/piece-data-mapper';
import { schedule } from '@activepieces/piece-schedule';
import { zendesk } from '@activepieces/piece-zendesk';
import { mattermost } from '@activepieces/piece-mattermost';
import { mastodon } from '@activepieces/piece-mastodon';
import { shopify } from '@activepieces/piece-shopify';
Expand Down Expand Up @@ -107,6 +108,7 @@ export const pieces: Piece[] = [
dataMapper,
intercom,
schedule,
zendesk,
mattermost,
mastodon,
shopify,
Expand Down
18 changes: 18 additions & 0 deletions packages/pieces/zendesk/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions packages/pieces/zendesk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# pieces-zendesk

This library was generated with [Nx](https://nx.dev).

## Running lint

Run `nx lint pieces-zendesk` to execute the lint via [ESLint](https://eslint.org/).
4 changes: 4 additions & 0 deletions packages/pieces/zendesk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@activepieces/piece-zendesk",
"version": "0.0.1"
}
38 changes: 38 additions & 0 deletions packages/pieces/zendesk/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name":"pieces-zendesk",
"$schema":"../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot":"packages/pieces/zendesk/src",
"projectType":"library",
"targets":{
"build":{
"executor":"@nrwl/js:tsc",
"outputs":[
"{options.outputPath}"
],
"options":{
"outputPath":"dist/packages/pieces/zendesk",
"tsConfig":"packages/pieces/zendesk/tsconfig.lib.json",
"packageJson":"packages/pieces/zendesk/package.json",
"main":"packages/pieces/zendesk/src/index.ts",
"assets":[
"packages/pieces/zendesk/*.md"
],
"buildableProjectDepsInPackageJsonType":"dependencies"
}
},
"lint":{
"executor":"@nrwl/linter:eslint",
"outputs":[
"{options.outputFile}"
],
"options":{
"lintFilePatterns":[
"packages/pieces/zendesk/**/*.ts"
]
}
}
},
"tags":[

]
}
19 changes: 19 additions & 0 deletions packages/pieces/zendesk/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

import { createPiece } from '@activepieces/framework';
import packageJson from '../package.json';
import { newTicketInView } from './lib/trigger/new-ticket-in-view';

export const zendesk = createPiece({
name: 'zendesk',
displayName: 'Zendesk',
logoUrl: 'https://cdn.activepieces.com/pieces/zendesk.png',
version: packageJson.version,
authors: [
"abuaboud"
],
actions: [
],
triggers: [
newTicketInView
],
});
176 changes: 176 additions & 0 deletions packages/pieces/zendesk/src/lib/trigger/new-ticket-in-view.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
import { TriggerStrategy } from "@activepieces/shared";
import { AuthenticationType, createTrigger, DedupeStrategy, httpClient, HttpMethod, Polling, pollingHelper, Property } from "@activepieces/framework";

const markdownProperty = `
**Organization**: The organization name can be found in the URL (e.g https://ORGANIZATION_NAME.zendesk.com).
**Agent Email**: The email you use to log in to Zendesk.
**API Token**: You can find this in the Zendesk Admin Panel under Settings > APIs > Zendesk API.
`

export const newTicketInView = createTrigger({
name: 'new_ticket_in_view',
displayName: 'New ticket in view',
description: 'Triggers when a new ticket is created in a view',
type: TriggerStrategy.POLLING,
props: {
authentication: Property.CustomAuth({
displayName: 'Authentication',
description: markdownProperty,
props: {
email: Property.ShortText({
displayName: 'Agent Email',
description: 'The email address you use to login to Zendesk',
required: true,
}),
token: Property.ShortText({
displayName: 'Token',
description: 'The API token you can generate in Zendesk',
required: true,
}),
subdomain: Property.ShortText({
displayName: 'Organization (e.g activepieceshelp)',
description: 'The subdomain of your Zendesk instance',
required: true,
}),
},
required: true,
}),
view_id: Property.Dropdown({
displayName: 'View',
description: 'The view to monitor for new tickets',
refreshers: ['authentication'],
required: true,
options: async (value) => {
const authentication = value['authentication'] as AuthProps;
if (!authentication?.['email'] || !authentication?.['subdomain'] || !authentication?.['token']) {
return {
placeholder: 'Fill your authentication first',
disabled: true,
options: [],
}
}
const response = await httpClient.sendRequest<{ views: any[] }>({
url: `https://${authentication.subdomain}.zendesk.com/api/v2/views.json`,
method: HttpMethod.GET,
authentication: {
type: AuthenticationType.BASIC,
username: authentication.email + "/token",
password: authentication.token,
}
})
return {
placeholder: 'Select a view',
options: response.body.views.map((view: any) => ({
label: view.title,
value: view.id,
}))
}
}
})

},
sampleData: {
"url": "https://activepieceshelp.zendesk.com/api/v2/tickets/5.json",
"id": 5,
"external_id": null,
"via": {
"channel": "web",
"source": {
"from": {},
"to": {},
"rel": null
}
},
"created_at": "2023-03-25T02:39:41Z",
"updated_at": "2023-03-25T02:39:41Z",
"type": null,
"subject": "Subject",
"raw_subject": "Raw Subject",
"description": "Description",
"priority": null,
"status": "open",
"recipient": null,
"requester_id": 8193592318236,
"submitter_id": 8193592318236,
"assignee_id": 8193592318236,
"organization_id": 8193599387420,
"group_id": 8193569448092,
"collaborator_ids": [],
"follower_ids": [],
"email_cc_ids": [],
"forum_topic_id": null,
"problem_id": null,
"has_incidents": false,
"is_public": true,
"due_at": null,
"tags": [],
"custom_fields": [],
"satisfaction_rating": null,
"sharing_agreement_ids": [],
"custom_status_id": 8193592472348,
"fields": [],
"followup_ids": [],
"ticket_form_id": 8193569410076,
"brand_id": 8193583542300,
"allow_channelback": false,
"allow_attachments": true,
"from_messaging_channel": false
},
onEnable: async (context) => {
await pollingHelper.onEnable(polling, {
store: context.store,
propsValue: context.propsValue,
})
},
onDisable: async (context) => {
await pollingHelper.onDisable(polling, {
store: context.store,
propsValue: context.propsValue,
})
},
run: async (context) => {
return await pollingHelper.poll(polling, {
store: context.store,
propsValue: context.propsValue,
});
},
test: async (context) => {
return await pollingHelper.poll(polling, {
store: context.store,
propsValue: context.propsValue,
});
}
});

type AuthProps = {
email: string;
token: string;
subdomain: string;
}

const polling: Polling<{ authentication: AuthProps, view_id: string }> = {
strategy: DedupeStrategy.LAST_ITEM,
items: async ({ propsValue }) => {
const items = await getTickets(propsValue.authentication, propsValue.view_id);
return items.map((item) => ({
id: item.id,
data: item,
}));
}
}

async function getTickets(authentication: AuthProps, view_id: string) {
const { email, token, subdomain } = authentication;
const response = await httpClient.sendRequest<{ tickets: any[] }>({
url: `https://${subdomain}.zendesk.com/api/v2/views/${view_id}/tickets.json?sort_order=desc&sort_by=created_at&per_page=200`,
method: HttpMethod.GET,
authentication: {
type: AuthenticationType.BASIC,
username: email + "/token",
password: token,
}
})
return response.body.tickets;
}
16 changes: 16 additions & 0 deletions packages/pieces/zendesk/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
}
],
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
}
}
11 changes: 11 additions & 0 deletions packages/pieces/zendesk/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
"include": ["src/**/*.ts"]
}
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"packages/pieces/wordpress/src/index.ts"
],
"@activepieces/piece-youtube": ["packages/pieces/youtube/src/index.ts"],
"@activepieces/piece-zendesk": ["packages/pieces/zendesk/src/index.ts"],
"@activepieces/piece-zoom": ["packages/pieces/zoom/src/index.ts"],
"@activepieces/pieces-apps": ["packages/pieces/apps/src/index.ts"],
"@activepieces/shared": ["packages/shared/src/index.ts"],
Expand Down

0 comments on commit 9b4e2f7

Please sign in to comment.