-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f4d83a8
commit 78fd132
Showing
3 changed files
with
332 additions
and
0 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
src/appmixer/zendesktickets/organizations/WatchOrganizations/WatchOrganizations.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
|
||
async receive(context) { | ||
|
||
if (context.messages.webhook) { | ||
const { data } = context.messages.webhook.content; | ||
await context.log({ step: 'webhook-received', data }); | ||
const orgId = data.detail.id; | ||
const user = await this.showOrganization(context, orgId); | ||
await context.sendJson({ user, data }, 'out'); | ||
return context.response(); | ||
} | ||
}, | ||
|
||
async showOrganization(context, orgId) { | ||
|
||
const url = `https://${context.auth.subdomain}.zendesk.com/api/v2/organizations/${orgId}`; | ||
const headers = { | ||
Authorization: 'Bearer ' + context.auth.accessToken | ||
}; | ||
const req = { | ||
url: url, | ||
method: 'GET', | ||
headers: headers | ||
}; | ||
const { data } = await context.httpRequest(req); | ||
return data.user; | ||
}, | ||
|
||
async createWebhook(context) { | ||
const url = `https://${context.auth.subdomain}.zendesk.com/api/v2/webhooks`; | ||
const headers = { | ||
Authorization: 'Bearer ' + context.auth.accessToken | ||
}; | ||
const requestBody = { | ||
webhook: { | ||
endpoint: context.getWebhookUrl(), | ||
subscriptions: context.properties.eventTypes, | ||
http_method: 'POST', | ||
name: 'WatchOrganizations:webhook:' + context.componentId, | ||
request_format: 'json', | ||
status: 'active' | ||
} | ||
}; | ||
const req = { | ||
url: url, | ||
method: 'POST', | ||
data: requestBody, | ||
headers: headers | ||
}; | ||
const { data } = await context.httpRequest(req); | ||
return data.webhook; | ||
}, | ||
|
||
async start(context) { | ||
|
||
// Create a new webhook. | ||
const webhook = await this.createWebhook(context); | ||
await context.log({ step: 'webhook-created', webhook }); | ||
return context.saveState({ webhook }); | ||
}, | ||
|
||
async stop(context) { | ||
|
||
const webhookId = context.state.webhook.id; | ||
const headers = { | ||
Authorization: 'Bearer ' + context.auth.accessToken | ||
}; | ||
await context.httpRequest({ | ||
url: `https://${context.auth.subdomain}.zendesk.com/api/v2/webhooks/${webhookId}`, | ||
method: 'DELETE', | ||
headers: headers | ||
}); | ||
} | ||
}; |
254 changes: 254 additions & 0 deletions
254
src/appmixer/zendesktickets/organizations/WatchOrganizations/component.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,254 @@ | ||
{ | ||
"name": "appmixer.zendesktickets.organizations.WatchOrganizations", | ||
"author": "Appmixer <[email protected]>", | ||
"description": "Watch for new or updated organizations.", | ||
"icon": "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IS0tIFVwbG9hZGVkIHRvOiBTVkcgUmVwbywgd3d3LnN2Z3JlcG8uY29tLCBHZW5lcmF0b3I6IFNWRyBSZXBvIE1peGVyIFRvb2xzIC0tPgo8c3ZnIGZpbGw9IiMwMDAwMDAiIHdpZHRoPSI4MDBweCIgaGVpZ2h0PSI4MDBweCIgdmlld0JveD0iMCAwIDE0IDE0IiByb2xlPSJpbWciIGZvY3VzYWJsZT0iZmFsc2UiIGFyaWEtaGlkZGVuPSJ0cnVlIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Im0gNi41NDI1LDExLjU0NzUgLTUuNTQyNSwwIDUuNTQyNSwtNi42OTE1IDAsNi42OTE1IHogbSA2LjQ1NzUsMCAtNS41NDI1LDAgYyAwLC0xLjUzMTUgMS4yMzk1LC0yLjc3MTUgMi43NzE1LC0yLjc3MTUgMS41MzE1LDAgMi43NzEsMS4yNDEgMi43NzEsMi43NzE1IHogbSAtNS41NDI1LC0yLjQwMiAwLC02LjY5MyA1LjU0MjUsMCAtNS41NDI1LDYuNjkzIHogTSA2LjU0MjUsMi40NTI1IEMgNi41NDI1LDMuOTgzIDUuMzAyLDUuMjI0NSAzLjc3MSw1LjIyNDUgMi4yNDEsNS4yMjQ1IDEsMy45ODQgMSwyLjQ1MzUgbCA1LjU0MjUsMCAwLC0xMGUtNCB6Ii8+PC9zdmc+", | ||
"webhook": true, | ||
"auth": { | ||
"service": "appmixer:zendesktickets", | ||
"scope": [ | ||
"webhooks:write", | ||
"organizations:read" | ||
] | ||
}, | ||
"properties": { | ||
"schema": { | ||
"type": "object", | ||
"properties": { | ||
"eventTypes": { "type": "array" } | ||
} | ||
}, | ||
"inspector": { | ||
"inputs": { | ||
"eventTypes": { | ||
"type": "multiselect", | ||
"label": "Event Types", | ||
"description": "Select one or more event types to watch for.", | ||
"index": 0, | ||
"options": [ | ||
{ "label": "Organization Created", "value": "zen:event-type:organization.created" }, | ||
{ "label": "Organization Custom Field Changed", "value": "zen:event-type:organization.custom_field_changed" }, | ||
{ "label": "Organization Deleted", "value": "zen:event-type:organization.deleted" }, | ||
{ "label": "Organization External ID Changed", "value": "zen:event-type:organization.external_id_changed" }, | ||
{ "label": "Organization Name Changed", "value": "zen:event-type:organization.name_changed" }, | ||
{ "label": "Organization Tags Changed", "value": "zen:event-type:organization.tags_changed" } | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"outPorts": [ | ||
{ | ||
"name": "out", | ||
"options": [ | ||
{ "label": "Organization", "value": "organization", "schema": { | ||
"type": "object", | ||
"properties": { | ||
"created_at": { | ||
"type": "string", | ||
"description": "The time the organization was created", | ||
"readOnly": true | ||
}, | ||
"details": { | ||
"type": "string", | ||
"description": "Any details obout the organization, such as the address", | ||
"nullable": true | ||
}, | ||
"domain_names": { | ||
"type": "array", | ||
"description": "An array of domain names associated with this organization", | ||
"items": { | ||
"type": "string" | ||
} | ||
}, | ||
"external_id": { | ||
"type": "string", | ||
"description": "A unique external id to associate organizations to an external record. The id is case-insensitive. For example, \"company1\" and \"Company1\" are considered the same", | ||
"nullable": true | ||
}, | ||
"group_id": { | ||
"type": "integer", | ||
"description": "New tickets from users in this organization are automatically put in this group", | ||
"nullable": true | ||
}, | ||
"id": { | ||
"type": "integer", | ||
"description": "Automatically assigned when the organization is created" | ||
}, | ||
"name": { | ||
"type": "string", | ||
"description": "A unique name for the organization" | ||
}, | ||
"notes": { | ||
"type": "string", | ||
"description": "Any notes you have about the organization", | ||
"nullable": true | ||
}, | ||
"organization_fields": { | ||
"type": "object", | ||
"description": "Custom fields for this organization. See [Custom organization fields](/api-reference/ticketing/organizations/organizations/#custom-organization-fields)", | ||
"additionalProperties": { | ||
"oneOf": [ | ||
{ | ||
"type": "string" | ||
}, | ||
{ | ||
"type": "number" | ||
} | ||
] | ||
}, | ||
"nullable": true | ||
}, | ||
"shared_comments": { | ||
"type": "boolean", | ||
"description": "End users in this organization are able to see each other's comments on tickets" | ||
}, | ||
"shared_tickets": { | ||
"type": "boolean", | ||
"description": "End users in this organization are able to see each other's tickets" | ||
}, | ||
"tags": { | ||
"type": "array", | ||
"description": "The tags of the organization", | ||
"items": { | ||
"type": "string" | ||
} | ||
}, | ||
"updated_at": { | ||
"type": "string", | ||
"description": "The time of the last update of the organization", | ||
"readOnly": true | ||
}, | ||
"url": { | ||
"type": "string", | ||
"description": "The API url of this organization" | ||
} | ||
}, | ||
"example": { | ||
"created_at": "2009-07-20T22:55:29Z", | ||
"details": "This is a kind of organization", | ||
"domain_names": [ | ||
"example.com", | ||
"test.com" | ||
], | ||
"external_id": "ABC123", | ||
"group_id": null, | ||
"id": 35436, | ||
"name": "One Organization", | ||
"notes": "", | ||
"organization_fields": { | ||
"org_decimal": 5.2, | ||
"org_dropdown": "option_1" | ||
}, | ||
"shared_comments": true, | ||
"shared_tickets": true, | ||
"tags": [ | ||
"enterprise", | ||
"other_tag" | ||
], | ||
"updated_at": "2011-05-05T10:38:52Z", | ||
"url": "https://company.zendesk.com/api/v2/organizations/35436.json" | ||
} | ||
} | ||
}, { | ||
"label": "Data", "value": "data", "schema": { | ||
|
||
"type": "object", | ||
"properties": { | ||
"account_id": { | ||
"type": "integer", | ||
"description": "Zendesk account id associated with the event." | ||
}, | ||
"id": { | ||
"type": "string", | ||
"description": "Unique id for the event" | ||
}, | ||
"subject": { | ||
"type": "string", | ||
"description": "Contains the event's domain and an id for the resource created or changed by the event." | ||
}, | ||
"time": { | ||
"type": "string", | ||
"description": "Timestamp for when the event occurred." | ||
}, | ||
"type": { | ||
"type": "string", | ||
"description": "Type of activity the event recorded." | ||
}, | ||
"zendesk_event_version": { | ||
"type": "string", | ||
"description": "Event schema version. Possible value is \"2022-06-20\"." | ||
}, | ||
"detail": { | ||
"type": "object", | ||
"description": "Resource created or changed by the event.", | ||
"properties": { | ||
"created_at": { | ||
"type": "string", | ||
"format": "datetime", | ||
"description": "The time the organization was created", | ||
"readOnly": true | ||
}, | ||
"id": { | ||
"type": "string", | ||
"description": "Automatically assigned when creating organizations", | ||
"readOnly": true | ||
}, | ||
"name": { | ||
"type": "string" | ||
}, | ||
"shared_comments": { | ||
"type": "boolean" | ||
}, | ||
"shared_tickets": { | ||
"type": "boolean" | ||
}, | ||
"group_id": { | ||
"type": "string" | ||
}, | ||
"external_id": { | ||
"type": "string", | ||
"description": "A unique identifier from another system. The API treats the id as case insensitive. Example: \"ian1\" and \"IAN1\" are the same value.", | ||
"nullable": true | ||
}, | ||
"updated_at": { | ||
"type": "string", | ||
"format": "datetime", | ||
"description": "The time of the last update of the user", | ||
"readOnly": true | ||
} | ||
} | ||
}, | ||
"event": { | ||
"type": "object", | ||
"description": "Resource created or changed by the event.", | ||
"properties": { | ||
"current": { "type": "object" }, | ||
"previous": { "type": "object" }, | ||
"field": { "type": "object", "properties": { | ||
"id": { "type": "string" }, | ||
"title": { "type": "string" }, | ||
"type": { "type": "string" } | ||
} }, | ||
"custom_field": { "type": "object", "properties": { | ||
"id": { "type": "string" }, | ||
"title": { "type": "string" }, | ||
"type": { "type": "string" } | ||
} }, | ||
"added": { "type": "object", "properties": { | ||
"tags": { "type": "array", "items": { "type": "string" } } | ||
} }, | ||
"removed": { "type": "object", "properties": { | ||
"tags": { "type": "array", "items": { "type": "string" } } | ||
} } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"name": "appmixer.zendesktickets.users.WatchUsers", | ||
"author": "Appmixer <[email protected]>", | ||
"description": "Watch for new or updated users.", | ||
"icon": "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IS0tIFVwbG9hZGVkIHRvOiBTVkcgUmVwbywgd3d3LnN2Z3JlcG8uY29tLCBHZW5lcmF0b3I6IFNWRyBSZXBvIE1peGVyIFRvb2xzIC0tPgo8c3ZnIGZpbGw9IiMwMDAwMDAiIHdpZHRoPSI4MDBweCIgaGVpZ2h0PSI4MDBweCIgdmlld0JveD0iMCAwIDE0IDE0IiByb2xlPSJpbWciIGZvY3VzYWJsZT0iZmFsc2UiIGFyaWEtaGlkZGVuPSJ0cnVlIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Im0gNi41NDI1LDExLjU0NzUgLTUuNTQyNSwwIDUuNTQyNSwtNi42OTE1IDAsNi42OTE1IHogbSA2LjQ1NzUsMCAtNS41NDI1LDAgYyAwLC0xLjUzMTUgMS4yMzk1LC0yLjc3MTUgMi43NzE1LC0yLjc3MTUgMS41MzE1LDAgMi43NzEsMS4yNDEgMi43NzEsMi43NzE1IHogbSAtNS41NDI1LC0yLjQwMiAwLC02LjY5MyA1LjU0MjUsMCAtNS41NDI1LDYuNjkzIHogTSA2LjU0MjUsMi40NTI1IEMgNi41NDI1LDMuOTgzIDUuMzAyLDUuMjI0NSAzLjc3MSw1LjIyNDUgMi4yNDEsNS4yMjQ1IDEsMy45ODQgMSwyLjQ1MzUgbCA1LjU0MjUsMCAwLC0xMGUtNCB6Ii8+PC9zdmc+", | ||
"webhook": true, | ||
"auth": { | ||
|