n8n-nodes-discord-dnd 0.1.78 → 0.1.79
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.
@@ -1,5 +1,5 @@
|
|
1
1
|
import { INodeType, ITriggerFunctions, ITriggerResponse, INodeTypeDescription } from "n8n-workflow";
|
2
|
-
export declare class
|
2
|
+
export declare class DiscordTriggerWithSpeech implements INodeType {
|
3
3
|
description: INodeTypeDescription;
|
4
4
|
trigger(this: ITriggerFunctions): Promise<ITriggerResponse>;
|
5
5
|
}
|
@@ -1,36 +1,15 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
-
}) : function(o, v) {
|
16
|
-
o["default"] = v;
|
17
|
-
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
-
if (mod && mod.__esModule) return mod;
|
20
|
-
var result = {};
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
-
__setModuleDefault(result, mod);
|
23
|
-
return result;
|
24
|
-
};
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
4
|
};
|
28
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
-
exports.
|
6
|
+
exports.DiscordTriggerWithSpeech = void 0;
|
30
7
|
const discord_js_1 = require("discord.js");
|
31
8
|
const voice_1 = require("@discordjs/voice");
|
9
|
+
const speech_1 = require("@google-cloud/speech");
|
32
10
|
const prism_media_1 = __importDefault(require("prism-media"));
|
33
11
|
const stream_1 = require("stream");
|
12
|
+
// ----------- Support Classes -----------
|
34
13
|
class BufferStream extends stream_1.Writable {
|
35
14
|
constructor(onDone) {
|
36
15
|
super();
|
@@ -47,19 +26,31 @@ class BufferStream extends stream_1.Writable {
|
|
47
26
|
callback();
|
48
27
|
}
|
49
28
|
}
|
50
|
-
|
29
|
+
// ----------- Main Discord Trigger -----------
|
30
|
+
class DiscordTriggerWithSpeech {
|
51
31
|
constructor() {
|
52
32
|
this.description = {
|
53
|
-
displayName: "Discord Trigger
|
54
|
-
name: "
|
55
|
-
icon: "file
|
33
|
+
displayName: "Discord Trigger With Speech",
|
34
|
+
name: "discordTriggerWithSpeech",
|
35
|
+
icon: "file:discord.svg",
|
56
36
|
group: ["trigger"],
|
57
37
|
version: 1,
|
58
|
-
description: "Trigger when someone speaks in
|
59
|
-
defaults: {
|
38
|
+
description: "Trigger when someone speaks in Discord voice channel",
|
39
|
+
defaults: {
|
40
|
+
name: "Discord Trigger With Speech",
|
41
|
+
},
|
60
42
|
inputs: [],
|
61
43
|
outputs: ["main"],
|
62
|
-
credentials: [
|
44
|
+
credentials: [
|
45
|
+
{
|
46
|
+
name: "discordApi",
|
47
|
+
required: true,
|
48
|
+
},
|
49
|
+
{
|
50
|
+
name: "googleApi",
|
51
|
+
required: true,
|
52
|
+
},
|
53
|
+
],
|
63
54
|
properties: [
|
64
55
|
{
|
65
56
|
displayName: "Voice Channel ID",
|
@@ -72,73 +63,101 @@ class DiscordTrigger2 {
|
|
72
63
|
};
|
73
64
|
}
|
74
65
|
async trigger() {
|
75
|
-
const
|
76
|
-
const
|
66
|
+
const credentialsDiscord = await this.getCredentials("discordApi");
|
67
|
+
const credentialsGoogle = await this.getCredentials("googleApi");
|
77
68
|
const voiceChannelId = this.getNodeParameter("voiceChannelId");
|
78
|
-
|
79
|
-
const
|
69
|
+
// Init Google Speech Client
|
70
|
+
const speechClient = new speech_1.SpeechClient({
|
71
|
+
credentials: {
|
72
|
+
client_email: credentialsGoogle.client_email,
|
73
|
+
private_key: credentialsGoogle.private_key,
|
74
|
+
},
|
75
|
+
projectId: credentialsGoogle.project_id,
|
76
|
+
});
|
77
|
+
// Init Discord Client
|
78
|
+
const client = new discord_js_1.Client({
|
80
79
|
intents: [discord_js_1.GatewayIntentBits.Guilds, discord_js_1.GatewayIntentBits.GuildVoiceStates],
|
81
80
|
partials: [discord_js_1.Partials.Channel],
|
82
|
-
};
|
83
|
-
const client = new Client(clientOptions);
|
81
|
+
});
|
84
82
|
client.once("ready", async () => {
|
83
|
+
console.log("Discord bot ready!");
|
85
84
|
const channel = (await client.channels.fetch(voiceChannelId));
|
86
|
-
if (!
|
85
|
+
if (!channel || !channel.isVoiceBased()) {
|
86
|
+
console.error("Channel not found or not a voice channel");
|
87
87
|
return;
|
88
|
+
}
|
88
89
|
const connection = (0, voice_1.joinVoiceChannel)({
|
89
90
|
channelId: channel.id,
|
90
91
|
guildId: channel.guild.id,
|
91
|
-
adapterCreator: channel.guild
|
92
|
-
.voiceAdapterCreator,
|
92
|
+
adapterCreator: channel.guild.voiceAdapterCreator,
|
93
93
|
});
|
94
|
-
|
95
|
-
console.log("Bot joined voice channel.");
|
96
|
-
});
|
97
|
-
client.on("voiceStateUpdate", (oldState, newState) => {
|
94
|
+
client.on("voiceStateUpdate", async (oldState, newState) => {
|
98
95
|
if (newState.channelId !== voiceChannelId)
|
99
96
|
return;
|
100
|
-
const receiver = connection.receiver;
|
101
97
|
const userId = newState.id;
|
102
|
-
const
|
103
|
-
|
98
|
+
const receiver = connection.receiver;
|
99
|
+
const audioStream = receiver.subscribe(userId, {
|
100
|
+
end: {
|
101
|
+
behavior: voice_1.EndBehaviorType.AfterSilence,
|
102
|
+
duration: 1000, // 1s không có tiếng thì kết thúc ghi âm
|
103
|
+
},
|
104
104
|
});
|
105
105
|
const decoder = new prism_media_1.default.opus.Decoder({
|
106
106
|
rate: 48000,
|
107
107
|
channels: 2,
|
108
108
|
frameSize: 960,
|
109
109
|
});
|
110
|
-
const
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
110
|
+
const memoryStream = new BufferStream(async (buffer) => {
|
111
|
+
var _a;
|
112
|
+
console.log("Received audio buffer, sending to Google Speech...");
|
113
|
+
const request = {
|
114
|
+
audio: {
|
115
|
+
content: buffer.toString("base64"),
|
116
|
+
},
|
117
|
+
config: {
|
118
|
+
encoding: "LINEAR16",
|
119
|
+
sampleRateHertz: 48000,
|
120
|
+
languageCode: "en-US",
|
121
|
+
audioChannelCount: 2,
|
122
|
+
},
|
123
|
+
};
|
124
|
+
try {
|
125
|
+
const [response] = await speechClient.recognize(request);
|
126
|
+
const transcription = ((_a = response.results) === null || _a === void 0 ? void 0 : _a.map((result) => { var _a; return (_a = result.alternatives) === null || _a === void 0 ? void 0 : _a[0].transcript; }).join("\n")) || "";
|
127
|
+
console.log("Google Speech result:", transcription);
|
128
|
+
// Emit về n8n
|
129
|
+
this.emit([
|
130
|
+
[
|
131
|
+
{
|
132
|
+
json: {
|
133
|
+
text: transcription,
|
134
|
+
userId: userId,
|
135
|
+
},
|
122
136
|
},
|
123
|
-
|
124
|
-
]
|
125
|
-
|
137
|
+
],
|
138
|
+
]);
|
139
|
+
}
|
140
|
+
catch (err) {
|
141
|
+
console.error("Error recognizing speech:", err);
|
142
|
+
}
|
126
143
|
});
|
127
|
-
|
144
|
+
audioStream.pipe(decoder).pipe(memoryStream);
|
128
145
|
});
|
129
146
|
});
|
130
|
-
await client.login(
|
147
|
+
await client.login(credentialsDiscord.botToken);
|
131
148
|
const closeFunction = async () => {
|
132
|
-
const
|
133
|
-
if (
|
134
|
-
|
135
|
-
|
149
|
+
const connection = (0, voice_1.getVoiceConnection)(voiceChannelId);
|
150
|
+
if (connection) {
|
151
|
+
connection.destroy();
|
152
|
+
}
|
153
|
+
console.log("Disconnecting bot...");
|
154
|
+
await client.destroy();
|
136
155
|
};
|
137
156
|
return {
|
138
|
-
closeFunction,
|
139
157
|
manualTriggerFunction: async () => { },
|
158
|
+
closeFunction,
|
140
159
|
};
|
141
160
|
}
|
142
161
|
}
|
143
|
-
exports.
|
162
|
+
exports.DiscordTriggerWithSpeech = DiscordTriggerWithSpeech;
|
144
163
|
//# sourceMappingURL=DiscordTrigger2.node.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"DiscordTrigger2.node.js","sourceRoot":"","sources":["../../src/nodes/DiscordTrigger2.node.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"DiscordTrigger2.node.js","sourceRoot":"","sources":["../../src/nodes/DiscordTrigger2.node.ts"],"names":[],"mappings":";;;;;;AAOA,2CAA+E;AAC/E,4CAI0B;AAE1B,iDAAoD;AACpD,8DAAgC;AAChC,mCAAkC;AAElC,0CAA0C;AAC1C,MAAM,YAAa,SAAQ,iBAAQ;IAEjC,YAAoB,MAAgC;QAClD,KAAK,EAAE,CAAC;QADU,WAAM,GAAN,MAAM,CAA0B;QAD5C,WAAM,GAAa,EAAE,CAAC;IAG9B,CAAC;IAED,MAAM,CAAC,KAAU,EAAE,SAAyB,EAAE,QAAoB;QAChE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxB,QAAQ,EAAE,CAAC;IACb,CAAC;IAED,MAAM,CAAC,QAAoB;QACzB,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1C,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpB,QAAQ,EAAE,CAAC;IACb,CAA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AM,CAAC,KAAK,CAAC,kBAAkB,CAAC,QAAkB,CAAC,CAAC;QAE1D,MAAM,aAAa,GAAG,KAAK,IAAI,EAAE;YAC/B,MAAM,UAAU,GAAG,IAAA,0BAAkB,EAAC,cAAc,CAAC,CAAC;YACtD,IAAI,UAAU,EAAE;gBACd,UAAU,CAAC,OAAO,EAAE,CAAC;aACtB;YACD,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;YACpC,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;QACzB,CAAC,CAAC;QAEF,OAAO;YACL,qBAAqB,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC;YACrC,aAAa;SACd,CAAC;IACJ,CAAC;CACF;AAvJD,4DAuJC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "n8n-nodes-discord-dnd",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.79",
|
4
4
|
"description": "n8n node to create triggers for Discord events",
|
5
5
|
"keywords": [
|
6
6
|
"n8n",
|
@@ -52,6 +52,7 @@
|
|
52
52
|
"dependencies": {
|
53
53
|
"@discordjs/opus": "^0.10.0",
|
54
54
|
"@discordjs/voice": "^0.16.1",
|
55
|
+
"@google-cloud/speech": "^7.0.1",
|
55
56
|
"axios": "^1.9.0",
|
56
57
|
"discord.js": "^14.19.2",
|
57
58
|
"ffmpeg-static": "^5.2.0",
|