Skip to content

Commit

Permalink
Improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
drudge committed Oct 1, 2022
1 parent acd55ac commit 3da44f3
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 40 deletions.
1 change: 1 addition & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Copyright 2022 Nicholas Penree <nick@penree.com>
Copyright 2022 n8n

Permission is hereby granted, free of charge, to any person obtaining a copy of
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

This trigger node allows you to receive updates in your [n8n](https://www.n8n.io) workflows when significant events happen in your PagerDuty account. For example, when an incident triggers, escalates or resolves. See the `Events Supported` support section below for a full list of events.

![PagerDuty Trigger node screenshot](./images/example.png)
## How to install

### Community Nodes (Recommended)
Expand Down Expand Up @@ -76,6 +77,8 @@ Additional event types may be added to this list over time.

You can define optional headers that will be passed along with the payload to the destination URL. The header values are redacted in GET requests, but are not redacted on the webhook when delivered to trigger node. All header names must be unique.

When sending custom headers, the JSON for the event will have headers and query parameters will always included.

### Include Headers and Query Parameters

By default, you'll receive the event body as your JSON. You can choose whether to return the full details of the request, including headers and query parameters instead of only the body.
Expand Down Expand Up @@ -141,6 +144,14 @@ By default, you'll receive the event body as your JSON. You can choose whether t
</pre>
</details>

## Troubleshooting / Testing

If you're having issues with the webhook subscriptions, you can review the webhook subscriptions in PagerDuty using the **Integrations** > **Generic Webhooks (v3)** menu.

You send also send a test event to your listening trigger node here as well:

![Manage webhook screenshot](./images/manage.png)

## License

MIT License
Expand Down
Binary file added images/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/manage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions nodes/PagerDutyTrigger/PagerDutyTrigger.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"node": "n8n-nodes-pagerduty-trigger.pagerDutyTrigger",
"nodeVersion": "1.0",
"codexVersion": "1.0",
"categories": ["Communication", "Development"],
"resources": {
"credentialDocumentation": [
{
"url": "https://docs.n8n.io/credentials/pagerDuty"
}
],
"primaryDocumentation": [
{
"url": "https://github.com/drudge/n8n-nodes-pagerduty-trigger"
}
],
"generic": [
{
"label": "PagerDuty: Webhook Subscriptions Guide",
"url": "https://support.pagerduty.com/docs/webhooks"
},
{
"label": "PagerDuty: Webhook Subscriptions API",
"url": "https://developer.pagerduty.com/api-reference/b3A6MjkyNDc4NA-create-a-webhook-subscription"
}
]
}
}
83 changes: 46 additions & 37 deletions nodes/PagerDutyTrigger/PagerDutyTrigger.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ import { pagerDutyApiRequest, pagerDutyApiRequestAllItems } from './GenericFunct

const debug = debuglog('n8n-nodes-pagerduty-trigger');

const NODE_NAME = 'PagerDuty Trigger';

export class PagerDutyTrigger implements INodeType {
description: INodeTypeDescription = {
displayName: 'PagerDuty Trigger',
displayName: NODE_NAME,
name: 'pagerDutyTrigger',
icon: 'file:pagerDuty.svg',
group: ['trigger'],
version: 1,
description: 'Starts the workflow when PagerDuty events occur',
subtitle: `={{"${NODE_NAME}"}}`,
defaults: {
name: 'PagerDuty Trigger',
name: NODE_NAME,
},
inputs: [],
outputs: ['main'],
Expand Down Expand Up @@ -76,34 +79,37 @@ export class PagerDutyTrigger implements INodeType {
default: 'apiToken',
},
{
displayName: 'Events From',
displayName: 'Scope',
name: 'filter',
type: 'options',
default: 'account_reference',
description: 'Limt the events to a specific service or team',
description: 'Limit the events to a specific service or team. By default, events for the entire account are returned.',
options: [
{
name: 'Service',
value: 'service_reference',
description: 'Limit the events to a specific service',
},
{
name: 'Team',
value: 'team_reference',
description: 'Limit the events to a specific team',
},
{
name: 'Account',
value: 'account_reference',
description: 'Receive events from everything in the account',
},
],
},
{
displayName: 'Team Name or ID',
name: "teamId",
type: "options",
name: 'teamId',
type: 'options',
description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
default: "",
default: '',
typeOptions: {
loadOptionsMethod: "getTeams",
loadOptionsMethod: 'getTeams',
},
required: true,
displayOptions: {
Expand All @@ -114,12 +120,12 @@ export class PagerDutyTrigger implements INodeType {
},
{
displayName: 'Service Name or ID',
name: "serviceId",
type: "options",
name: 'serviceId',
type: 'options',
description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
default: "",
default: '',
typeOptions: {
loadOptionsMethod: "getServices",
loadOptionsMethod: 'getServices',
},
required: true,
displayOptions: {
Expand Down Expand Up @@ -217,42 +223,43 @@ export class PagerDutyTrigger implements INodeType {
],
required: true,
default: [],
description: 'The events to listen to',
description: 'Which event types will trigger the node. A subset of all <a href="https://developer.pagerduty.com/docs/ZG9jOjQ1MTg4ODQ0-overview#event-types">event types</a> may be provided if the destination is only interested in a limited set of events.',
},
{
displayName: "Options",
name: "options",
type: "collection",
placeholder: "Add Option",
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
description: 'Options to set',
default: {},
options: [
{
displayName: "Custom Headers",
name: "customHeaders",
placeholder: "Add Header",
type: "fixedCollection",
displayName: 'Custom Headers',
name: 'customHeaders',
placeholder: 'Add Header',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
description: 'The headers to send',
description: 'Optional headers to be set on the events when sent. The header values are redacted in GET requests, but are not redacted on the event when delivered.',
default: {},
options: [
{
name: "parameter",
displayName: "Header",
name: 'parameter',
displayName: 'Header',
values: [
{
displayName: "Name",
name: "name",
type: "string",
default: "",
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
description: 'Name of the header',
},
{
displayName: "Value",
name: "value",
type: "string",
default: "",
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
description: 'Value to set for the header',
},
],
Expand All @@ -265,7 +272,7 @@ export class PagerDutyTrigger implements INodeType {
type: 'boolean',
default: false,
description:
'Whether to return the full reponse (headers and query parameters) data instead of only the body',
'Whether to return the full request (headers and query parameters) in addition to the body',
},
],
},
Expand Down Expand Up @@ -357,6 +364,7 @@ export class PagerDutyTrigger implements INodeType {
}

const description = this.getNode().name as string;
const workflowName = this.getWorkflow().name as string;
const events = this.getNodeParameter('events', []);
const options = this.getNodeParameter('options', {}) as IDataObject;
const customHeaders = options.customHeaders as IDataObject;
Expand All @@ -378,7 +386,7 @@ export class PagerDutyTrigger implements INodeType {
url: webhookUrl,
custom_headers: customHeaders?.parameter || [],
},
description: `[N8N] ${description}`,
description: `[N8N] ${description} in ${workflowName}`,
events,
filter: {
type: filter,
Expand Down Expand Up @@ -437,6 +445,8 @@ export class PagerDutyTrigger implements INodeType {
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
const bodyData = this.getBodyData();
const options = this.getNodeParameter('options', {}) as IDataObject;
const headersObj = options.customHeaders as IDataObject || {};
const customHeaders = headersObj.parameter as IDataObject[] || [];

// Check if the webhook is only the ping from Github to confirm if it workshook_id
if (bodyData.hook_id !== undefined && bodyData.action === undefined) {
Expand All @@ -449,11 +459,10 @@ export class PagerDutyTrigger implements INodeType {
}

// Is a regular webhook call

// TODO: Add headers & requestPath
const returnData: IDataObject[] = [];
const shouldReturnFullRequest = options.fullRequest as boolean || customHeaders.length > 0;

returnData.push(options.fullRequest ? ({
returnData.push(shouldReturnFullRequest ? ({
body: bodyData,
headers: this.getHeaderData(),
query: this.getQueryData(),
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"name": "n8n-nodes-pagerduty-trigger",
"version": "0.2.0",
"version": "0.3.1",
"description": "n8n Trigger node for PagerDuty",
"keywords": [
"n8n-community-node-package"
"n8n-community-node-package",
"pagerduty",
"incident"
],
"license": "MIT",
"homepage": "",
"homepage": "https://github.com/drudge/n8n-nodes-pagerduty-trigger",
"author": {
"name": "Nicholas Penree",
"email": "nick@penree.com"
Expand Down

0 comments on commit 3da44f3

Please sign in to comment.