UNPKG

n8n-nodes-wechat-pad-pro

Version:

n8n node for WeChatPadPro, allowing you to automate WeChat messaging and interactions within your n8n workflows. Support WeChatPadPro0859

82 lines 2.93 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.WeChatPadProTrigger = void 0; const ws_1 = __importDefault(require("ws")); class WeChatPadProTrigger { constructor() { this.description = { displayName: 'WeChatPadPro Trigger', name: 'weChatPadProTrigger', icon: 'file:wechatPadPro.svg', group: ['trigger'], version: 1, description: '当收到微信消息时触发', defaults: { name: 'WeChatPadPro Trigger', }, inputs: [], outputs: ["main"], credentials: [ { name: 'weChatPadProApi', required: true, }, ], properties: [ { displayName: 'Events', name: 'events', type: 'multiOptions', options: [ { name: 'Text Message', value: 'textMessage', description: '当收到文本消息时触发', }, ], default: [], required: true, }, ], }; } async trigger() { const credentials = await this.getCredentials('weChatPadProApi'); const baseUrl = credentials.baseUrl; const authKey = credentials.authKey; const events = this.getNodeParameter('events', []); const wsUrl = `ws://${baseUrl}/ws/GetSyncMsg?key=${authKey}`; const ws = new ws_1.default(wsUrl); ws.on('open', () => { this.logger.info('WebSocket connection established for WeChatPadPro Trigger'); }); ws.on('message', (data) => { try { const message = JSON.parse(data.toString()); if (events.includes('textMessage') && message.msg_type === 1) { this.emit([this.helpers.returnJsonArray(message)]); } } catch (error) { this.logger.error(`Error parsing WebSocket message: ${error.message}`); } }); ws.on('close', () => { this.logger.info('WebSocket connection closed for WeChatPadPro Trigger'); }); ws.on('error', (error) => { this.logger.error(`WebSocket error for WeChatPadPro Trigger: ${error.message}`); }); async function closeFunction() { ws.close(); } return { closeFunction, }; } } exports.WeChatPadProTrigger = WeChatPadProTrigger; //# sourceMappingURL=WeChatPadPro.trigger.js.map