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

66 lines 2.2 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReceiveText = void 0; const ws_1 = __importDefault(require("ws")); class ReceiveText { constructor() { this.description = { displayName: '接收文本消息', name: 'receiveText', icon: 'file:wechatPadPro.svg', group: ['trigger'], version: 1, description: '当收到微信文本消息时触发', defaults: { name: '接收文本消息', }, inputs: [], outputs: ["main"], credentials: [ { name: 'weChatPadProApi', required: true, }, ], properties: [], }; } async trigger() { const credentials = await this.getCredentials('weChatPadProApi'); const baseUrl = credentials.baseUrl; const authKey = credentials.authKey; const wsUrl = `ws://${baseUrl}/ws/GetSyncMsg?key=${authKey}`; const ws = new ws_1.default(wsUrl); ws.on('open', () => { this.logger.info('WebSocket connection established'); }); ws.on('message', (data) => { try { const message = JSON.parse(data.toString()); if (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'); }); ws.on('error', (error) => { this.logger.error(`WebSocket error: ${error.message}`); }); async function closeFunction() { ws.close(); } return { closeFunction, }; } } exports.ReceiveText = ReceiveText; //# sourceMappingURL=ReceiveText.node.js.map