n8n-nodes-qq-guild-bot 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +221 -0
- package/dist/credentials/QqGuildBotApi.credentials.d.ts +8 -0
- package/dist/credentials/QqGuildBotApi.credentials.d.ts.map +1 -0
- package/dist/credentials/QqGuildBotApi.credentials.js +41 -0
- package/dist/credentials/QqGuildBotApi.credentials.js.map +1 -0
- package/dist/lib/index.d.ts +29 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +64 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/nodes/QqGuildBot/QqGuildBot.node.d.ts +6 -0
- package/dist/nodes/QqGuildBot/QqGuildBot.node.d.ts.map +1 -0
- package/dist/nodes/QqGuildBot/QqGuildBot.node.js +208 -0
- package/dist/nodes/QqGuildBot/QqGuildBot.node.js.map +1 -0
- package/dist/nodes/QqGuildBotTrigger/QqGuildBotTrigger.node.d.ts +6 -0
- package/dist/nodes/QqGuildBotTrigger/QqGuildBotTrigger.node.d.ts.map +1 -0
- package/dist/nodes/QqGuildBotTrigger/QqGuildBotTrigger.node.js +144 -0
- package/dist/nodes/QqGuildBotTrigger/QqGuildBotTrigger.node.js.map +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 n8n-nodes-qq-guild-bot contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# n8n-nodes-qq-guild-bot
|
|
2
|
+
|
|
3
|
+
QQ频道机器人的n8n节点包,支持发送消息和接收消息触发器。
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/n8n-nodes-qq-guild-bot)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
## 功能特性
|
|
9
|
+
|
|
10
|
+
- ✅ **发送消息节点**:向QQ频道发送文本、Markdown、Embed等多种类型的消息
|
|
11
|
+
- ✅ **接收消息触发器**:监听QQ频道消息事件,自动触发n8n工作流
|
|
12
|
+
- ✅ **完整的类型支持**:基于TypeScript开发,提供完整的类型定义
|
|
13
|
+
- ✅ **易于配置**:简单的凭证配置,快速接入QQ频道机器人
|
|
14
|
+
|
|
15
|
+
## 安装
|
|
16
|
+
|
|
17
|
+
### 在n8n中安装
|
|
18
|
+
|
|
19
|
+
#### 方式1:通过n8n社区节点安装(推荐)
|
|
20
|
+
|
|
21
|
+
1. 打开n8n实例
|
|
22
|
+
2. 进入 **Settings** > **Community Nodes**
|
|
23
|
+
3. 点击 **Install a community node**
|
|
24
|
+
4. 输入 `n8n-nodes-qq-guild-bot`
|
|
25
|
+
5. 点击 **Install**
|
|
26
|
+
|
|
27
|
+
#### 方式2:通过npm安装
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# 进入n8n安装目录
|
|
31
|
+
cd ~/.n8n
|
|
32
|
+
|
|
33
|
+
# 安装节点包
|
|
34
|
+
npm install n8n-nodes-qq-guild-bot
|
|
35
|
+
|
|
36
|
+
# 重启n8n
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 配置
|
|
40
|
+
|
|
41
|
+
### 获取QQ频道机器人凭证
|
|
42
|
+
|
|
43
|
+
1. 访问 [QQ开放平台](https://q.qq.com/qqbot/)
|
|
44
|
+
2. 登录并创建机器人应用
|
|
45
|
+
3. 在应用详情页获取以下信息:
|
|
46
|
+
- **应用ID (AppID)**:机器人的唯一标识
|
|
47
|
+
- **机器人令牌 (Token)**:用于API认证的密钥
|
|
48
|
+
|
|
49
|
+
### 在n8n中配置凭证
|
|
50
|
+
|
|
51
|
+
1. 在n8n工作流编辑器中,添加QQ频道机器人节点
|
|
52
|
+
2. 点击 **Credential to connect with**
|
|
53
|
+
3. 选择 **Create New**
|
|
54
|
+
4. 填写凭证信息:
|
|
55
|
+
- **应用ID**:填入从QQ开放平台获取的AppID
|
|
56
|
+
- **机器人令牌**:填入从QQ开放平台获取的Token
|
|
57
|
+
- **沙箱环境**:开发测试时可勾选,生产环境请取消勾选
|
|
58
|
+
5. 点击 **Save** 保存凭证
|
|
59
|
+
|
|
60
|
+
## 使用
|
|
61
|
+
|
|
62
|
+
### 发送消息节点
|
|
63
|
+
|
|
64
|
+
#### 基本用法
|
|
65
|
+
|
|
66
|
+
1. 在工作流中添加 **QQ频道机器人** 节点
|
|
67
|
+
2. 选择已配置的凭证
|
|
68
|
+
3. 配置参数:
|
|
69
|
+
- **操作**:选择"发送消息"
|
|
70
|
+
- **子频道ID**:要发送消息的子频道ID
|
|
71
|
+
- **消息类型**:选择文本、Markdown或Embed
|
|
72
|
+
- **消息内容**:输入要发送的内容
|
|
73
|
+
|
|
74
|
+
#### 发送文本消息
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"operation": "sendMessage",
|
|
79
|
+
"channelId": "123456789",
|
|
80
|
+
"messageType": "text",
|
|
81
|
+
"content": "Hello from n8n!"
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
#### 发送Markdown消息
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"operation": "sendMessage",
|
|
90
|
+
"channelId": "123456789",
|
|
91
|
+
"messageType": "markdown",
|
|
92
|
+
"content": "# 标题\n\n这是一条**Markdown**消息"
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### 发送Embed消息
|
|
97
|
+
|
|
98
|
+
```json
|
|
99
|
+
{
|
|
100
|
+
"operation": "sendMessage",
|
|
101
|
+
"channelId": "123456789",
|
|
102
|
+
"messageType": "embed",
|
|
103
|
+
"embed": {
|
|
104
|
+
"title": "通知标题",
|
|
105
|
+
"description": "这是一条Embed消息",
|
|
106
|
+
"thumbnail": "https://example.com/image.png"
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 接收消息触发器
|
|
112
|
+
|
|
113
|
+
#### 基本用法
|
|
114
|
+
|
|
115
|
+
1. 在工作流中添加 **QQ频道消息触发器** 节点作为起始节点
|
|
116
|
+
2. 选择已配置的凭证
|
|
117
|
+
3. 配置参数:
|
|
118
|
+
- **事件类型**:选择要监听的消息类型
|
|
119
|
+
- **@消息**:仅接收@机器人的消息
|
|
120
|
+
- **频道消息**:接收所有频道消息(需要权限)
|
|
121
|
+
- **私信消息**:接收私信消息
|
|
122
|
+
|
|
123
|
+
#### 工作流示例
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
QQ频道消息触发器 → 条件判断 → 发送回复消息
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
当接收到消息时,触发器会输出以下数据结构:
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"id": "消息ID",
|
|
134
|
+
"content": "消息内容",
|
|
135
|
+
"author": {
|
|
136
|
+
"id": "用户ID",
|
|
137
|
+
"username": "用户名"
|
|
138
|
+
},
|
|
139
|
+
"channel_id": "子频道ID",
|
|
140
|
+
"guild_id": "频道ID",
|
|
141
|
+
"timestamp": "2024-01-01T00:00:00Z"
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## 常见问题
|
|
146
|
+
|
|
147
|
+
### Q: 如何获取子频道ID?
|
|
148
|
+
|
|
149
|
+
A: 在QQ频道客户端中,右键点击子频道,选择"复制子频道ID"。
|
|
150
|
+
|
|
151
|
+
### Q: 为什么触发器没有接收到消息?
|
|
152
|
+
|
|
153
|
+
A: 请检查以下几点:
|
|
154
|
+
1. 确认机器人已被添加到对应的频道
|
|
155
|
+
2. 确认机器人有相应的权限(如接收消息权限)
|
|
156
|
+
3. 如果选择"频道消息"事件,需要在QQ开放平台开通"消息事件"权限
|
|
157
|
+
4. 检查n8n工作流是否处于激活状态
|
|
158
|
+
|
|
159
|
+
### Q: 发送消息失败,提示认证错误?
|
|
160
|
+
|
|
161
|
+
A: 请检查:
|
|
162
|
+
1. AppID和Token是否正确
|
|
163
|
+
2. Token是否已过期
|
|
164
|
+
3. 是否选择了正确的沙箱环境选项
|
|
165
|
+
|
|
166
|
+
### Q: 支持发送图片吗?
|
|
167
|
+
|
|
168
|
+
A: 支持。可以在消息中添加图片URL,或使用Embed消息类型设置缩略图。
|
|
169
|
+
|
|
170
|
+
## 开发
|
|
171
|
+
|
|
172
|
+
### 本地开发
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
# 克隆仓库
|
|
176
|
+
git clone https://github.com/yourusername/n8n-nodes-qq-guild-bot.git
|
|
177
|
+
cd n8n-nodes-qq-guild-bot
|
|
178
|
+
|
|
179
|
+
# 安装依赖
|
|
180
|
+
npm install
|
|
181
|
+
|
|
182
|
+
# 构建
|
|
183
|
+
npm run build
|
|
184
|
+
|
|
185
|
+
# 监听模式(开发时使用)
|
|
186
|
+
npm run dev
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### 项目结构
|
|
190
|
+
|
|
191
|
+
```
|
|
192
|
+
n8n-nodes-qq-guild-bot/
|
|
193
|
+
├── credentials/ # 凭证定义
|
|
194
|
+
├── nodes/ # 节点定义
|
|
195
|
+
│ ├── QqGuildBot/ # 发送消息节点
|
|
196
|
+
│ └── QqGuildBotTrigger/ # 触发器节点
|
|
197
|
+
├── lib/ # SDK封装层
|
|
198
|
+
└── dist/ # 编译输出
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## 相关链接
|
|
202
|
+
|
|
203
|
+
- [n8n官方文档](https://docs.n8n.io/)
|
|
204
|
+
- [QQ开放平台](https://q.qq.com/qqbot/)
|
|
205
|
+
- [QQ频道机器人开发文档](https://bot.q.qq.com/wiki/)
|
|
206
|
+
|
|
207
|
+
## 许可证
|
|
208
|
+
|
|
209
|
+
[MIT](LICENSE)
|
|
210
|
+
|
|
211
|
+
## 贡献
|
|
212
|
+
|
|
213
|
+
欢迎提交Issue和Pull Request!
|
|
214
|
+
|
|
215
|
+
## 更新日志
|
|
216
|
+
|
|
217
|
+
### 0.1.0 (2024-01-17)
|
|
218
|
+
|
|
219
|
+
- 🎉 初始版本发布
|
|
220
|
+
- ✨ 支持发送文本、Markdown、Embed消息
|
|
221
|
+
- ✨ 支持接收@消息、频道消息、私信消息触发器
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ICredentialType, INodeProperties } from 'n8n-workflow';
|
|
2
|
+
export declare class QqGuildBotApi implements ICredentialType {
|
|
3
|
+
name: string;
|
|
4
|
+
displayName: string;
|
|
5
|
+
documentationUrl: string;
|
|
6
|
+
properties: INodeProperties[];
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=QqGuildBotApi.credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QqGuildBotApi.credentials.d.ts","sourceRoot":"","sources":["../../credentials/QqGuildBotApi.credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,eAAe,EACf,eAAe,EACf,MAAM,cAAc,CAAC;AAEtB,qBAAa,aAAc,YAAW,eAAe;IACpD,IAAI,SAAmB;IAEvB,WAAW,SAAgB;IAE3B,gBAAgB,SAAgC;IAEhD,UAAU,EAAE,eAAe,EAAE,CA4B3B;CACF"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QqGuildBotApi = void 0;
|
|
4
|
+
class QqGuildBotApi {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.name = 'qqGuildBotApi';
|
|
7
|
+
this.displayName = 'QQ频道机器人API';
|
|
8
|
+
this.documentationUrl = 'https://bot.q.qq.com/wiki/';
|
|
9
|
+
this.properties = [
|
|
10
|
+
{
|
|
11
|
+
displayName: '应用ID (AppID)',
|
|
12
|
+
name: 'appId',
|
|
13
|
+
type: 'string',
|
|
14
|
+
default: '',
|
|
15
|
+
required: true,
|
|
16
|
+
description: '从QQ开放平台获取的机器人应用ID',
|
|
17
|
+
placeholder: '123456789',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
displayName: '机器人令牌 (Token)',
|
|
21
|
+
name: 'token',
|
|
22
|
+
type: 'string',
|
|
23
|
+
typeOptions: {
|
|
24
|
+
password: true,
|
|
25
|
+
},
|
|
26
|
+
default: '',
|
|
27
|
+
required: true,
|
|
28
|
+
description: '从QQ开放平台获取的机器人令牌,用于API认证',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
displayName: '沙箱环境',
|
|
32
|
+
name: 'sandbox',
|
|
33
|
+
type: 'boolean',
|
|
34
|
+
default: false,
|
|
35
|
+
description: '是否使用沙箱环境进行开发测试。生产环境请关闭此选项。',
|
|
36
|
+
},
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.QqGuildBotApi = QqGuildBotApi;
|
|
41
|
+
//# sourceMappingURL=QqGuildBotApi.credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QqGuildBotApi.credentials.js","sourceRoot":"","sources":["../../credentials/QqGuildBotApi.credentials.ts"],"names":[],"mappings":";;;AAKA,MAAa,aAAa;IAA1B;QACC,SAAI,GAAG,eAAe,CAAC;QAEvB,gBAAW,GAAG,YAAY,CAAC;QAE3B,qBAAgB,GAAG,4BAA4B,CAAC;QAEhD,eAAU,GAAsB;YAC/B;gBACC,WAAW,EAAE,cAAc;gBAC3B,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,EAAE;gBACX,QAAQ,EAAE,IAAI;gBACd,WAAW,EAAE,mBAAmB;gBAChC,WAAW,EAAE,WAAW;aACxB;YACD;gBACC,WAAW,EAAE,eAAe;gBAC5B,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE;oBACZ,QAAQ,EAAE,IAAI;iBACd;gBACD,OAAO,EAAE,EAAE;gBACX,QAAQ,EAAE,IAAI;gBACd,WAAW,EAAE,yBAAyB;aACtC;YACD;gBACC,WAAW,EAAE,MAAM;gBACnB,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,KAAK;gBACd,WAAW,EAAE,4BAA4B;aACzC;SACD,CAAC;IACH,CAAC;CAAA;AApCD,sCAoCC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Config, GetWsParam, IOpenAPI } from 'qq-guild-bot';
|
|
2
|
+
import { AvailableIntentsEventsEnum } from 'qq-guild-bot';
|
|
3
|
+
export type { Config, GetWsParam, IOpenAPI };
|
|
4
|
+
export { AvailableIntentsEventsEnum };
|
|
5
|
+
/**
|
|
6
|
+
* 凭证接口定义
|
|
7
|
+
*/
|
|
8
|
+
export interface QqGuildBotCredentials {
|
|
9
|
+
appId: string;
|
|
10
|
+
token: string;
|
|
11
|
+
sandbox: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 创建OpenAPI客户端
|
|
15
|
+
*/
|
|
16
|
+
export declare function createOpenApiClient(credentials: QqGuildBotCredentials): IOpenAPI;
|
|
17
|
+
/**
|
|
18
|
+
* 创建WebSocket客户端配置
|
|
19
|
+
*/
|
|
20
|
+
export declare function createWebSocketConfig(credentials: QqGuildBotCredentials, intents: AvailableIntentsEventsEnum[]): GetWsParam;
|
|
21
|
+
/**
|
|
22
|
+
* 根据事件类型计算intents
|
|
23
|
+
*/
|
|
24
|
+
export declare function calculateIntents(eventType: string): AvailableIntentsEventsEnum[];
|
|
25
|
+
/**
|
|
26
|
+
* 格式化API错误信息
|
|
27
|
+
*/
|
|
28
|
+
export declare function formatApiError(error: any): string;
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAG1D,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;AAC7C,OAAO,EAAE,0BAA0B,EAAE,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,qBAAqB,GAAG,QAAQ,CAQhF;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,qBAAqB,EAAE,OAAO,EAAE,0BAA0B,EAAE,GAAG,UAAU,CAO3H;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,0BAA0B,EAAE,CAehF;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM,CAWjD"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AvailableIntentsEventsEnum = void 0;
|
|
4
|
+
exports.createOpenApiClient = createOpenApiClient;
|
|
5
|
+
exports.createWebSocketConfig = createWebSocketConfig;
|
|
6
|
+
exports.calculateIntents = calculateIntents;
|
|
7
|
+
exports.formatApiError = formatApiError;
|
|
8
|
+
const qq_guild_bot_1 = require("qq-guild-bot");
|
|
9
|
+
const qq_guild_bot_2 = require("qq-guild-bot");
|
|
10
|
+
Object.defineProperty(exports, "AvailableIntentsEventsEnum", { enumerable: true, get: function () { return qq_guild_bot_2.AvailableIntentsEventsEnum; } });
|
|
11
|
+
/**
|
|
12
|
+
* 创建OpenAPI客户端
|
|
13
|
+
*/
|
|
14
|
+
function createOpenApiClient(credentials) {
|
|
15
|
+
const config = {
|
|
16
|
+
appID: credentials.appId,
|
|
17
|
+
token: credentials.token,
|
|
18
|
+
sandbox: credentials.sandbox,
|
|
19
|
+
};
|
|
20
|
+
return (0, qq_guild_bot_1.createOpenAPI)(config);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 创建WebSocket客户端配置
|
|
24
|
+
*/
|
|
25
|
+
function createWebSocketConfig(credentials, intents) {
|
|
26
|
+
return {
|
|
27
|
+
appID: credentials.appId,
|
|
28
|
+
token: credentials.token,
|
|
29
|
+
sandbox: credentials.sandbox,
|
|
30
|
+
intents,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 根据事件类型计算intents
|
|
35
|
+
*/
|
|
36
|
+
function calculateIntents(eventType) {
|
|
37
|
+
const intentsMap = {
|
|
38
|
+
atMessage: [
|
|
39
|
+
qq_guild_bot_2.AvailableIntentsEventsEnum.GUILD_MESSAGES,
|
|
40
|
+
qq_guild_bot_2.AvailableIntentsEventsEnum.PUBLIC_GUILD_MESSAGES,
|
|
41
|
+
],
|
|
42
|
+
guildMessage: [
|
|
43
|
+
qq_guild_bot_2.AvailableIntentsEventsEnum.GUILD_MESSAGES,
|
|
44
|
+
],
|
|
45
|
+
directMessage: [
|
|
46
|
+
qq_guild_bot_2.AvailableIntentsEventsEnum.DIRECT_MESSAGE,
|
|
47
|
+
],
|
|
48
|
+
};
|
|
49
|
+
return intentsMap[eventType] || [];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 格式化API错误信息
|
|
53
|
+
*/
|
|
54
|
+
function formatApiError(error) {
|
|
55
|
+
if (error.response) {
|
|
56
|
+
const { status, data } = error.response;
|
|
57
|
+
return `API错误 [${status}]: ${JSON.stringify(data)}`;
|
|
58
|
+
}
|
|
59
|
+
if (error.message) {
|
|
60
|
+
return `错误: ${error.message}`;
|
|
61
|
+
}
|
|
62
|
+
return `未知错误: ${JSON.stringify(error)}`;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":";;;AAoBA,kDAQC;AAKD,sDAOC;AAKD,4CAeC;AAKD,wCAWC;AA5ED,+CAA8D;AAE9D,+CAA0D;AAIjD,2GAJA,yCAA0B,OAIA;AAWnC;;GAEG;AACH,SAAgB,mBAAmB,CAAC,WAAkC;IACrE,MAAM,MAAM,GAAW;QACtB,KAAK,EAAE,WAAW,CAAC,KAAK;QACxB,KAAK,EAAE,WAAW,CAAC,KAAK;QACxB,OAAO,EAAE,WAAW,CAAC,OAAO;KAC5B,CAAC;IAEF,OAAO,IAAA,4BAAa,EAAC,MAAM,CAAC,CAAC;AAC9B,CAAC;AAED;;GAEG;AACH,SAAgB,qBAAqB,CAAC,WAAkC,EAAE,OAAqC;IAC9G,OAAO;QACN,KAAK,EAAE,WAAW,CAAC,KAAK;QACxB,KAAK,EAAE,WAAW,CAAC,KAAK;QACxB,OAAO,EAAE,WAAW,CAAC,OAAO;QAC5B,OAAO;KACP,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,SAAiB;IACjD,MAAM,UAAU,GAAiD;QAChE,SAAS,EAAE;YACV,yCAA0B,CAAC,cAAc;YACzC,yCAA0B,CAAC,qBAAqB;SAChD;QACD,YAAY,EAAE;YACb,yCAA0B,CAAC,cAAc;SACzC;QACD,aAAa,EAAE;YACd,yCAA0B,CAAC,cAAc;SACzC;KACD,CAAC;IAEF,OAAO,UAAU,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,KAAU;IACxC,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QACpB,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC;QACxC,OAAO,UAAU,MAAM,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;IACrD,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC;IAC/B,CAAC;IAED,OAAO,SAAS,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
|
|
2
|
+
export declare class QqGuildBot implements INodeType {
|
|
3
|
+
description: INodeTypeDescription;
|
|
4
|
+
execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=QqGuildBot.node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QqGuildBot.node.d.ts","sourceRoot":"","sources":["../../../nodes/QqGuildBot/QqGuildBot.node.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,iBAAiB,EACjB,kBAAkB,EAClB,SAAS,EACT,oBAAoB,EAEpB,MAAM,cAAc,CAAC;AAItB,qBAAa,UAAW,YAAW,SAAS;IAC3C,WAAW,EAAE,oBAAoB,CAuI/B;IAEI,OAAO,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC;CAyEvE"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QqGuildBot = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
const lib_1 = require("../../lib");
|
|
6
|
+
class QqGuildBot {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.description = {
|
|
9
|
+
displayName: 'QQ频道机器人',
|
|
10
|
+
name: 'qqGuildBot',
|
|
11
|
+
icon: 'file:qqguild.svg',
|
|
12
|
+
group: ['transform'],
|
|
13
|
+
version: 1,
|
|
14
|
+
subtitle: '={{$parameter["operation"]}}',
|
|
15
|
+
description: '发送QQ频道消息',
|
|
16
|
+
defaults: {
|
|
17
|
+
name: 'QQ频道机器人',
|
|
18
|
+
},
|
|
19
|
+
inputs: ['main'],
|
|
20
|
+
outputs: ['main'],
|
|
21
|
+
credentials: [
|
|
22
|
+
{
|
|
23
|
+
name: 'qqGuildBotApi',
|
|
24
|
+
required: true,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
properties: [
|
|
28
|
+
{
|
|
29
|
+
displayName: '操作',
|
|
30
|
+
name: 'operation',
|
|
31
|
+
type: 'options',
|
|
32
|
+
noDataExpression: true,
|
|
33
|
+
options: [
|
|
34
|
+
{
|
|
35
|
+
name: '发送消息',
|
|
36
|
+
value: 'sendMessage',
|
|
37
|
+
description: '向子频道发送消息',
|
|
38
|
+
action: '发送消息',
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
default: 'sendMessage',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
displayName: '子频道ID',
|
|
45
|
+
name: 'channelId',
|
|
46
|
+
type: 'string',
|
|
47
|
+
default: '',
|
|
48
|
+
required: true,
|
|
49
|
+
description: '要发送消息的子频道ID',
|
|
50
|
+
placeholder: '123456789',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
displayName: '消息类型',
|
|
54
|
+
name: 'messageType',
|
|
55
|
+
type: 'options',
|
|
56
|
+
options: [
|
|
57
|
+
{
|
|
58
|
+
name: '文本',
|
|
59
|
+
value: 'text',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: 'Markdown',
|
|
63
|
+
value: 'markdown',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: 'Embed',
|
|
67
|
+
value: 'embed',
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
default: 'text',
|
|
71
|
+
description: '要发送的消息类型',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
displayName: '消息内容',
|
|
75
|
+
name: 'content',
|
|
76
|
+
type: 'string',
|
|
77
|
+
typeOptions: {
|
|
78
|
+
rows: 4,
|
|
79
|
+
},
|
|
80
|
+
default: '',
|
|
81
|
+
required: true,
|
|
82
|
+
displayOptions: {
|
|
83
|
+
show: {
|
|
84
|
+
messageType: ['text', 'markdown'],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
description: '要发送的消息内容',
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
displayName: 'Embed标题',
|
|
91
|
+
name: 'embedTitle',
|
|
92
|
+
type: 'string',
|
|
93
|
+
default: '',
|
|
94
|
+
displayOptions: {
|
|
95
|
+
show: {
|
|
96
|
+
messageType: ['embed'],
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
description: 'Embed消息的标题',
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
displayName: 'Embed描述',
|
|
103
|
+
name: 'embedDescription',
|
|
104
|
+
type: 'string',
|
|
105
|
+
typeOptions: {
|
|
106
|
+
rows: 4,
|
|
107
|
+
},
|
|
108
|
+
default: '',
|
|
109
|
+
displayOptions: {
|
|
110
|
+
show: {
|
|
111
|
+
messageType: ['embed'],
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
description: 'Embed消息的描述内容',
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
displayName: 'Embed缩略图URL',
|
|
118
|
+
name: 'embedThumbnail',
|
|
119
|
+
type: 'string',
|
|
120
|
+
default: '',
|
|
121
|
+
displayOptions: {
|
|
122
|
+
show: {
|
|
123
|
+
messageType: ['embed'],
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
description: 'Embed消息的缩略图URL',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
displayName: '回复消息ID',
|
|
130
|
+
name: 'msgId',
|
|
131
|
+
type: 'string',
|
|
132
|
+
default: '',
|
|
133
|
+
description: '如果要回复某条消息,填入该消息的ID',
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
displayName: '图片URL',
|
|
137
|
+
name: 'imageUrl',
|
|
138
|
+
type: 'string',
|
|
139
|
+
default: '',
|
|
140
|
+
description: '要在消息中显示的图片URL',
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
async execute() {
|
|
146
|
+
const items = this.getInputData();
|
|
147
|
+
const returnData = [];
|
|
148
|
+
// 获取凭证
|
|
149
|
+
const credentials = await this.getCredentials('qqGuildBotApi');
|
|
150
|
+
const client = (0, lib_1.createOpenApiClient)(credentials);
|
|
151
|
+
for (let i = 0; i < items.length; i++) {
|
|
152
|
+
try {
|
|
153
|
+
const operation = this.getNodeParameter('operation', i);
|
|
154
|
+
if (operation === 'sendMessage') {
|
|
155
|
+
const channelId = this.getNodeParameter('channelId', i);
|
|
156
|
+
const messageType = this.getNodeParameter('messageType', i);
|
|
157
|
+
const msgId = this.getNodeParameter('msgId', i, '');
|
|
158
|
+
const imageUrl = this.getNodeParameter('imageUrl', i, '');
|
|
159
|
+
let messagePayload = {
|
|
160
|
+
msg_id: msgId || undefined,
|
|
161
|
+
image: imageUrl || undefined,
|
|
162
|
+
};
|
|
163
|
+
// 根据消息类型构建payload
|
|
164
|
+
if (messageType === 'text' || messageType === 'markdown') {
|
|
165
|
+
const content = this.getNodeParameter('content', i);
|
|
166
|
+
messagePayload.content = content;
|
|
167
|
+
if (messageType === 'markdown') {
|
|
168
|
+
messagePayload.markdown = {
|
|
169
|
+
content,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else if (messageType === 'embed') {
|
|
174
|
+
const embedTitle = this.getNodeParameter('embedTitle', i, '');
|
|
175
|
+
const embedDescription = this.getNodeParameter('embedDescription', i, '');
|
|
176
|
+
const embedThumbnail = this.getNodeParameter('embedThumbnail', i, '');
|
|
177
|
+
messagePayload.embed = {
|
|
178
|
+
title: embedTitle,
|
|
179
|
+
description: embedDescription,
|
|
180
|
+
thumbnail: embedThumbnail ? { url: embedThumbnail } : undefined,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
// 发送消息
|
|
184
|
+
const response = await client.messageApi.postMessage(channelId, messagePayload);
|
|
185
|
+
returnData.push({
|
|
186
|
+
json: response.data,
|
|
187
|
+
pairedItem: { item: i },
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
if (this.continueOnFail()) {
|
|
193
|
+
returnData.push({
|
|
194
|
+
json: {
|
|
195
|
+
error: (0, lib_1.formatApiError)(error),
|
|
196
|
+
},
|
|
197
|
+
pairedItem: { item: i },
|
|
198
|
+
});
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), (0, lib_1.formatApiError)(error), { itemIndex: i });
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return [returnData];
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
exports.QqGuildBot = QqGuildBot;
|
|
208
|
+
//# sourceMappingURL=QqGuildBot.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QqGuildBot.node.js","sourceRoot":"","sources":["../../../nodes/QqGuildBot/QqGuildBot.node.ts"],"names":[],"mappings":";;;AAAA,+CAMsB;AAEtB,mCAAuF;AAEvF,MAAa,UAAU;IAAvB;QACC,gBAAW,GAAyB;YACnC,WAAW,EAAE,SAAS;YACtB,IAAI,EAAE,YAAY;YAClB,IAAI,EAAE,kBAAkB;YACxB,KAAK,EAAE,CAAC,WAAW,CAAC;YACpB,OAAO,EAAE,CAAC;YACV,QAAQ,EAAE,8BAA8B;YACxC,WAAW,EAAE,UAAU;YACvB,QAAQ,EAAE;gBACT,IAAI,EAAE,SAAS;aACf;YACD,MAAM,EAAE,CAAC,MAAM,CAAC;YAChB,OAAO,EAAE,CAAC,MAAM,CAAC;YACjB,WAAW,EAAE;gBACZ;oBACC,IAAI,EAAE,eAAe;oBACrB,QAAQ,EAAE,IAAI;iBACd;aACD;YACD,UAAU,EAAE;gBACX;oBACC,WAAW,EAAE,IAAI;oBACjB,IAAI,EAAE,WAAW;oBACjB,IAAI,EAAE,SAAS;oBACf,gBAAgB,EAAE,IAAI;oBACtB,OAAO,EAAE;wBACR;4BACC,IAAI,EAAE,MAAM;4BACZ,KAAK,EAAE,aAAa;4BACpB,WAAW,EAAE,UAAU;4BACvB,MAAM,EAAE,MAAM;yBACd;qBACD;oBACD,OAAO,EAAE,aAAa;iBACtB;gBACD;oBACC,WAAW,EAAE,OAAO;oBACpB,IAAI,EAAE,WAAW;oB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P,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;oBAEhF,UAAU,CAAC,IAAI,CAAC;wBACf,IAAI,EAAE,QAAQ,CAAC,IAAW;wBAC1B,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;qBACvB,CAAC,CAAC;gBACJ,CAAC;YACF,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,IAAI,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;oBAC3B,UAAU,CAAC,IAAI,CAAC;wBACf,IAAI,EAAE;4BACL,KAAK,EAAE,IAAA,oBAAc,EAAC,KAAK,CAAC;yBAC5B;wBACD,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;qBACvB,CAAC,CAAC;oBACH,SAAS;gBACV,CAAC;gBACD,MAAM,IAAI,iCAAkB,CAC3B,IAAI,CAAC,OAAO,EAAE,EACd,IAAA,oBAAc,EAAC,KAAK,CAAC,EACrB,EAAE,SAAS,EAAE,CAAC,EAAE,CAChB,CAAC;YACH,CAAC;QACF,CAAC;QAED,OAAO,CAAC,UAAU,CAAC,CAAC;IACrB,CAAC;CACD;AAnND,gCAmNC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ITriggerFunctions, INodeType, INodeTypeDescription, ITriggerResponse } from 'n8n-workflow';
|
|
2
|
+
export declare class QqGuildBotTrigger implements INodeType {
|
|
3
|
+
description: INodeTypeDescription;
|
|
4
|
+
trigger(this: ITriggerFunctions): Promise<ITriggerResponse>;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=QqGuildBotTrigger.node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QqGuildBotTrigger.node.d.ts","sourceRoot":"","sources":["../../../nodes/QqGuildBotTrigger/QqGuildBotTrigger.node.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,iBAAiB,EACjB,SAAS,EACT,oBAAoB,EACpB,gBAAgB,EAEhB,MAAM,cAAc,CAAC;AAUtB,qBAAa,iBAAkB,YAAW,SAAS;IAClD,WAAW,EAAE,oBAAoB,CA6C/B;IAEI,OAAO,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC;CA8FjE"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QqGuildBotTrigger = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
const qq_guild_bot_1 = require("qq-guild-bot");
|
|
6
|
+
const lib_1 = require("../../lib");
|
|
7
|
+
class QqGuildBotTrigger {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.description = {
|
|
10
|
+
displayName: 'QQ频道消息触发器',
|
|
11
|
+
name: 'qqGuildBotTrigger',
|
|
12
|
+
icon: 'file:qqguild.svg',
|
|
13
|
+
group: ['trigger'],
|
|
14
|
+
version: 1,
|
|
15
|
+
subtitle: '={{$parameter["eventType"]}}',
|
|
16
|
+
description: '接收QQ频道消息事件',
|
|
17
|
+
defaults: {
|
|
18
|
+
name: 'QQ频道消息触发器',
|
|
19
|
+
},
|
|
20
|
+
inputs: [],
|
|
21
|
+
outputs: ['main'],
|
|
22
|
+
credentials: [
|
|
23
|
+
{
|
|
24
|
+
name: 'qqGuildBotApi',
|
|
25
|
+
required: true,
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
properties: [
|
|
29
|
+
{
|
|
30
|
+
displayName: '事件类型',
|
|
31
|
+
name: 'eventType',
|
|
32
|
+
type: 'options',
|
|
33
|
+
options: [
|
|
34
|
+
{
|
|
35
|
+
name: '@消息',
|
|
36
|
+
value: 'atMessage',
|
|
37
|
+
description: '仅接收@机器人的消息',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: '频道消息',
|
|
41
|
+
value: 'guildMessage',
|
|
42
|
+
description: '接收所有频道消息(需要权限)',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: '私信消息',
|
|
46
|
+
value: 'directMessage',
|
|
47
|
+
description: '接收私信消息',
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
default: 'atMessage',
|
|
51
|
+
description: '要监听的消息事件类型',
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
async trigger() {
|
|
57
|
+
const credentials = await this.getCredentials('qqGuildBotApi');
|
|
58
|
+
const eventType = this.getNodeParameter('eventType');
|
|
59
|
+
// 计算intents
|
|
60
|
+
const intents = (0, lib_1.calculateIntents)(eventType);
|
|
61
|
+
const wsConfig = (0, lib_1.createWebSocketConfig)(credentials, intents);
|
|
62
|
+
let ws;
|
|
63
|
+
let isClosing = false;
|
|
64
|
+
// 创建WebSocket连接
|
|
65
|
+
try {
|
|
66
|
+
ws = await (0, qq_guild_bot_1.createWebsocket)(wsConfig);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `WebSocket连接失败: ${(0, lib_1.formatApiError)(error)}`);
|
|
70
|
+
}
|
|
71
|
+
// 监听消息事件
|
|
72
|
+
ws.on('MESSAGE_CREATE', (data) => {
|
|
73
|
+
if (isClosing)
|
|
74
|
+
return;
|
|
75
|
+
try {
|
|
76
|
+
// 触发工作流
|
|
77
|
+
this.emit([
|
|
78
|
+
this.helpers.returnJsonArray([
|
|
79
|
+
{
|
|
80
|
+
id: data.id,
|
|
81
|
+
content: data.content,
|
|
82
|
+
author: data.author,
|
|
83
|
+
channel_id: data.channel_id,
|
|
84
|
+
guild_id: data.guild_id,
|
|
85
|
+
timestamp: data.timestamp,
|
|
86
|
+
mentions: data.mentions,
|
|
87
|
+
member: data.member,
|
|
88
|
+
attachments: data.attachments,
|
|
89
|
+
},
|
|
90
|
+
]),
|
|
91
|
+
]);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
this.logger.error(`处理消息事件失败: ${(0, lib_1.formatApiError)(error)}`);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
// 监听错误事件
|
|
98
|
+
ws.on('ERROR', (error) => {
|
|
99
|
+
if (isClosing)
|
|
100
|
+
return;
|
|
101
|
+
this.logger.error(`WebSocket错误: ${(0, lib_1.formatApiError)(error)}`);
|
|
102
|
+
});
|
|
103
|
+
// 监听断开连接事件
|
|
104
|
+
ws.on('DISCONNECT', () => {
|
|
105
|
+
if (isClosing)
|
|
106
|
+
return;
|
|
107
|
+
this.logger.warn('WebSocket连接已断开');
|
|
108
|
+
});
|
|
109
|
+
// 关闭函数
|
|
110
|
+
async function closeFunction() {
|
|
111
|
+
isClosing = true;
|
|
112
|
+
if (ws) {
|
|
113
|
+
try {
|
|
114
|
+
ws.disconnect();
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
// 忽略关闭时的错误
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// 手动触发函数
|
|
122
|
+
const manualTriggerFunction = async () => {
|
|
123
|
+
// 返回模拟数据用于测试
|
|
124
|
+
const mockData = {
|
|
125
|
+
id: 'mock-message-id',
|
|
126
|
+
content: '这是一条测试消息',
|
|
127
|
+
author: {
|
|
128
|
+
id: 'mock-user-id',
|
|
129
|
+
username: '测试用户',
|
|
130
|
+
},
|
|
131
|
+
channel_id: 'mock-channel-id',
|
|
132
|
+
guild_id: 'mock-guild-id',
|
|
133
|
+
timestamp: new Date().toISOString(),
|
|
134
|
+
};
|
|
135
|
+
this.emit([this.helpers.returnJsonArray([mockData])]);
|
|
136
|
+
};
|
|
137
|
+
return {
|
|
138
|
+
closeFunction,
|
|
139
|
+
manualTriggerFunction,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.QqGuildBotTrigger = QqGuildBotTrigger;
|
|
144
|
+
//# sourceMappingURL=QqGuildBotTrigger.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QqGuildBotTrigger.node.js","sourceRoot":"","sources":["../../../nodes/QqGuildBotTrigger/QqGuildBotTrigger.node.ts"],"names":[],"mappings":";;;AAAA,+CAMsB;AAEtB,+CAA+C;AAC/C,mCAKmB;AAEnB,MAAa,iBAAiB;IAA9B;QACC,gBAAW,GAAyB;YACnC,WAAW,EAAE,WAAW;YACxB,IAAI,EAAE,mBAAmB;YACzB,IAAI,EAAE,kBAAkB;YACxB,KAAK,EAAE,CAAC,SAAS,CAAC;YAClB,OAAO,EAAE,CAAC;YACV,QAAQ,EAAE,8BAA8B;YACxC,WAAW,EAAE,YAAY;YACzB,QAAQ,EAAE;gBACT,IAAI,EAAE,WAAW;aACjB;YACD,MAAM,EAAE,EAAE;YACV,OAAO,EAAE,CAAC,MAAM,CAAC;YACjB,WAAW,EAAE;gBACZ;oBACC,IAAI,EAAE,eAAe;oBACrB,QAAQ,EAAE,IAAI;iBACd;aACD;YACD,UAAU,EAAE;gBACX;oBACC,WAAW,EAAE,MAAM;oBACnB,IAAI,EAAE,WAAW;oBACjB,IAAI,EAAE,SAAS;oBACf,OAAO,EAAE;wBACR;4BACC,IAAI,EAAE,KAAK;4BACX,KAAK,EAAE,WAAW;4BAClB,WAAW,EAAE,YAAY;yBACzB;wBACD;4BACC,IAAI,EAAE,MAAM;4BACZ,KAAK,EAAE,cAAc;4BACrB,WAAW,EAAE,gBAAgB;yBAC7B;wBACD;4BACC,IAAI,EAAE,MAAM;4BACZ,KAAK,EAAE,eAAe;4BACtB,WAAW,EAAE,QAAQ;yBACrB;qBACD;oBACD,OAAO,EAAE,WAAW;oBACpB,WAAW,EAAE,YAAY;iBACzB;aACD;SACD,CAAC;IAgGH,CAAC;IA9FA,KAAK,CAAC,OAAO;QACZ,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,eAAe,CAA0B,CAAC;QACxF,MAAM,SAAS,GAAG,I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YACb,qBAAqB;SACrB,CAAC;IACH,CAAC;CACD;AA9ID,8CA8IC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "n8n-nodes-qq-guild-bot",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "QQ频道机器人的n8n节点包,支持发送消息和接收消息触发器",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"n8n",
|
|
7
|
+
"n8n-nodes",
|
|
8
|
+
"n8n-community-node-package",
|
|
9
|
+
"qq",
|
|
10
|
+
"bot",
|
|
11
|
+
"tencent"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"homepage": "https://github.com/yourusername/n8n-nodes-qq-guild-bot",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/yourusername/n8n-nodes-qq-guild-bot.git"
|
|
18
|
+
},
|
|
19
|
+
"main": "dist/index.js",
|
|
20
|
+
"types": "dist/index.d.ts",
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc",
|
|
26
|
+
"dev": "tsc --watch",
|
|
27
|
+
"clean": "rimraf dist",
|
|
28
|
+
"prepublishOnly": "npm run build"
|
|
29
|
+
},
|
|
30
|
+
"n8n": {
|
|
31
|
+
"nodes": [
|
|
32
|
+
"dist/nodes/QqGuildBot/QqGuildBot.node.js",
|
|
33
|
+
"dist/nodes/QqGuildBotTrigger/QqGuildBotTrigger.node.js"
|
|
34
|
+
],
|
|
35
|
+
"credentials": [
|
|
36
|
+
"dist/credentials/QqGuildBotApi.credentials.js"
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"qq-guild-bot": "^2.9.5"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "^18.19.130",
|
|
44
|
+
"rimraf": "^5.0.10",
|
|
45
|
+
"typescript": "^5.9.3"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"n8n-workflow": "*",
|
|
49
|
+
"n8n-core": "*"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=18.0.0"
|
|
53
|
+
}
|
|
54
|
+
}
|