n8n-nodes-chatwork
Version:
Provides an n8n community node for integrating Chatwork messaging and task APIs into automated workflows.
104 lines • 4.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChatworkTrigger = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const utils_1 = require("./shared/utils");
class ChatworkTrigger {
constructor() {
this.description = {
displayName: 'Chatwork Trigger',
name: 'chatworkTrigger',
icon: 'file:../../icons/Chatwork.svg',
group: ['trigger'],
version: 1,
description: 'Receive events from Chatwork via webhook',
defaults: {
name: 'Chatwork Trigger',
},
inputs: [],
outputs: ["main", "main", "main"],
outputNames: ['Mention To Me', 'Message Created', 'Message Updated'],
usableAsTool: true,
webhooks: [
{
name: 'default',
httpMethod: 'POST',
responseMode: 'onReceived',
responseData: 'noData',
path: '',
isFullPath: true,
},
],
properties: [
{
displayName: 'Verify Webhook Signature',
name: 'verifySignature',
type: 'boolean',
default: true,
description: 'Whether to verify the Chatwork webhook signature',
},
{
displayName: 'Webhook Tokens',
name: 'webhookTokens',
type: 'string',
typeOptions: {
password: true,
multipleValues: true,
multipleValueButtonText: 'Add Token',
},
default: [],
displayOptions: {
show: {
verifySignature: [true],
},
},
description: 'Webhook token from Chatwork webhook settings (used for signature verification). One or more tokens. One token per line.',
},
],
};
}
async webhook() {
const verifySignature = this.getNodeParameter('verifySignature', false);
if (verifySignature) {
const req = this.getRequestObject();
if (req.method !== 'POST') {
throw new n8n_workflow_1.ApplicationError('Invalid HTTP method');
}
const signature = this.getHeaderData()['x-chatworkwebhooksignature'];
if (!signature) {
throw new n8n_workflow_1.ApplicationError('Missing x-chatworkwebhooksignature header');
}
const rawBody = req.rawBody;
if (!rawBody) {
throw new n8n_workflow_1.ApplicationError('Missing raw request body');
}
const tokens = this.getNodeParameter('webhookTokens', []);
if (tokens.length === 0) {
throw new n8n_workflow_1.ApplicationError('No webhook tokens configured');
}
if (!(0, utils_1.verifyChatworkSignature)(rawBody, signature, tokens)) {
throw new n8n_workflow_1.ApplicationError('Invalid Chatwork webhook signature');
}
}
const body = this.getBodyData();
const workflowData = [[], [], []];
switch (body.webhook_event_type) {
case 'mention_to_me':
workflowData[0].push({ json: body });
break;
case 'message_created':
workflowData[1].push({ json: body });
break;
case 'message_updated':
workflowData[2].push({ json: body });
break;
default:
return { noWebhookResponse: true };
}
return {
workflowData,
};
}
}
exports.ChatworkTrigger = ChatworkTrigger;
//# sourceMappingURL=ChatworkTrigger.node.js.map