@theotherwillembotha/node-red-whatsapp 0.0.55 → 0.4.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/README.md +33 -21
- package/build/GenerateNodes.d.ts +2 -0
- package/build/GenerateNodes.d.ts.map +1 -0
- package/build/GenerateNodes.js +5 -7
- package/build/Nodes.html +1522 -538
- package/build/Nodes.js +52261 -14
- package/build/Plugins.html +37 -0
- package/build/Plugins.js +45828 -55
- package/build/index.d.ts +7 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +1 -0
- package/build/runtime/NodeManagerRuntime.js +140 -0
- package/build/whatsapp/node/WhatsappAccountConfigNode.d.ts +14 -0
- package/build/whatsapp/node/WhatsappAccountConfigNode.d.ts.map +1 -0
- package/build/whatsapp/node/WhatsappAccountConfigNode.js +7 -2
- package/build/whatsapp/node/WhatsappDynamicSendMessageNode.d.ts +19 -0
- package/build/whatsapp/node/WhatsappDynamicSendMessageNode.d.ts.map +1 -0
- package/build/whatsapp/node/WhatsappDynamicSendMessageNode.js +112 -0
- package/build/whatsapp/node/WhatsappGroupConfigNode.d.ts +16 -0
- package/build/whatsapp/node/WhatsappGroupConfigNode.d.ts.map +1 -0
- package/build/whatsapp/node/WhatsappGroupConfigNode.js +19 -8
- package/build/whatsapp/node/WhatsappReceiveMessageNode.d.ts +20 -0
- package/build/whatsapp/node/WhatsappReceiveMessageNode.d.ts.map +1 -0
- package/build/whatsapp/node/WhatsappReceiveMessageNode.js +2 -2
- package/build/whatsapp/node/WhatsappSendMessageNode.d.ts +17 -0
- package/build/whatsapp/node/WhatsappSendMessageNode.d.ts.map +1 -0
- package/build/whatsapp/node/WhatsappSendMessageNode.js +55 -33
- package/build/whatsapp/service/WhatsappClient.d.ts +189 -0
- package/build/whatsapp/service/WhatsappClient.d.ts.map +1 -0
- package/build/whatsapp/service/WhatsappClient.js +140 -14
- package/build/whatsapp/service/WhatsappService.d.ts +26 -0
- package/build/whatsapp/service/WhatsappService.d.ts.map +1 -0
- package/build/whatsapp/service/WhatsappService.js +85 -23
- package/build/whatsapp/service/WhatsappStore.d.ts +127 -0
- package/build/whatsapp/service/WhatsappStore.d.ts.map +1 -0
- package/build/whatsapp/service/WhatsappStore.js +10 -7
- package/package.json +11 -8
|
@@ -1,15 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
14
|
+
var WhatsappService_1;
|
|
5
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
16
|
exports.WhatsappService = void 0;
|
|
7
17
|
const node_red_plugincore_1 = require("@theotherwillembotha/node-red-plugincore");
|
|
8
18
|
const WhatsappClient_1 = require("./WhatsappClient");
|
|
9
19
|
const fs_1 = __importDefault(require("fs"));
|
|
10
20
|
const qrcode_1 = __importDefault(require("qrcode"));
|
|
11
|
-
class WhatsappService extends node_red_plugincore_1.BaseService {
|
|
12
|
-
static {
|
|
21
|
+
let WhatsappService = class WhatsappService extends node_red_plugincore_1.BaseService {
|
|
22
|
+
static { WhatsappService_1 = this; }
|
|
23
|
+
// clients is stored in global so that Nodes.js and Plugins.js (which are separate esbuild
|
|
24
|
+
// bundles containing separate copies of this class) share the same runtime map.
|
|
25
|
+
static { this._CLIENTS_KEY = '__wa_service_clients__'; }
|
|
26
|
+
static clients() {
|
|
27
|
+
if (!global[WhatsappService_1._CLIENTS_KEY]) {
|
|
28
|
+
global[WhatsappService_1._CLIENTS_KEY] = {};
|
|
29
|
+
}
|
|
30
|
+
return global[WhatsappService_1._CLIENTS_KEY];
|
|
31
|
+
}
|
|
13
32
|
constructor() {
|
|
14
33
|
super("WhatsappService");
|
|
15
34
|
this.connections = [];
|
|
@@ -20,6 +39,8 @@ class WhatsappService extends node_red_plugincore_1.BaseService {
|
|
|
20
39
|
console.log("STARTING: WhatsappService");
|
|
21
40
|
// whatsapp client commands.
|
|
22
41
|
let writePermission = red.auth.needsPermission("inject.write");
|
|
42
|
+
let readPermission = red.auth.needsPermission("nodes.read");
|
|
43
|
+
red.httpAdmin.get("/whatsapp/accounts", readPermission, (request, response) => this.getAccounts(request, response));
|
|
23
44
|
red.httpAdmin.post("/whatsapp/linkaccount", writePermission, (request, response) => this.linkAccount(request, response));
|
|
24
45
|
red.httpAdmin.post("/whatsapp/unlinkaccount", writePermission, (request, response) => this.unlinkaccount(request, response));
|
|
25
46
|
red.httpAdmin.post("/whatsapp/getgroups", writePermission, (request, response) => this.getGroups(request, response));
|
|
@@ -28,9 +49,6 @@ class WhatsappService extends node_red_plugincore_1.BaseService {
|
|
|
28
49
|
red.httpAdmin.post("/whatsapp/groupupdateuser", writePermission, (request, response) => this.groupUpdateUser(request, response));
|
|
29
50
|
red.httpAdmin.post("/whatsapp/groupremoveuser", writePermission, (request, response) => this.groupRemoveUser(request, response));
|
|
30
51
|
try {
|
|
31
|
-
// TODO: change the way we determine a suitable sorage location for the whatsapp data.
|
|
32
|
-
// if the /data folder exists, then this is probably a custom image and we can safely store the information in /data
|
|
33
|
-
// if it doesnt exist, then just save it to the current working folder.
|
|
34
52
|
if (fs_1.default.existsSync("/data")) {
|
|
35
53
|
console.log("Using /data as storage location");
|
|
36
54
|
this.configDir = "/data/whatsapp";
|
|
@@ -39,7 +57,6 @@ class WhatsappService extends node_red_plugincore_1.BaseService {
|
|
|
39
57
|
this.configDir = "whatsapp";
|
|
40
58
|
}
|
|
41
59
|
this.configFile = this.configDir + "/connections.json";
|
|
42
|
-
// check if the directory exists.
|
|
43
60
|
if (!fs_1.default.existsSync(this.configDir)) {
|
|
44
61
|
fs_1.default.mkdirSync(this.configDir);
|
|
45
62
|
}
|
|
@@ -56,7 +73,9 @@ class WhatsappService extends node_red_plugincore_1.BaseService {
|
|
|
56
73
|
localConnectionId: connection.key,
|
|
57
74
|
fileStorageRoot: this.configDir
|
|
58
75
|
});
|
|
59
|
-
|
|
76
|
+
WhatsappService_1.clients()[connection.key] = client;
|
|
77
|
+
// save account details (name, phone) to connections.json after each reconnect
|
|
78
|
+
client.onConnectionSuccess(() => this.saveConnectionDetails(connection.key));
|
|
60
79
|
return client.start();
|
|
61
80
|
}));
|
|
62
81
|
}
|
|
@@ -64,11 +83,47 @@ class WhatsappService extends node_red_plugincore_1.BaseService {
|
|
|
64
83
|
console.log(error);
|
|
65
84
|
}
|
|
66
85
|
}
|
|
86
|
+
saveConnectionDetails(key) {
|
|
87
|
+
try {
|
|
88
|
+
const client = WhatsappService_1.clients()[key];
|
|
89
|
+
if (!client)
|
|
90
|
+
return;
|
|
91
|
+
const details = client.details();
|
|
92
|
+
if (!details)
|
|
93
|
+
return;
|
|
94
|
+
const conn = this.connections.find(c => c.key === key);
|
|
95
|
+
if (conn) {
|
|
96
|
+
conn.name = details.name;
|
|
97
|
+
conn.phoneNumber = details.msisdn;
|
|
98
|
+
fs_1.default.writeFileSync(this.configFile, JSON.stringify(this.connections, null, 2), { flag: "w+" });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
console.log("saveConnectionDetails failed", e);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
getAccounts(request, response) {
|
|
106
|
+
// collect localConnectionIds claimed by WhatsappAccountConfigNodes in the current flow
|
|
107
|
+
const claimedKeys = new Set();
|
|
108
|
+
this.red.nodes.eachNode((nodeConfig) => {
|
|
109
|
+
if (nodeConfig.type === 'WhatsappAccountConfigNode' && nodeConfig.localConnectionId) {
|
|
110
|
+
claimedKeys.add(nodeConfig.localConnectionId);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
const accounts = this.connections.map(connection => ({
|
|
114
|
+
key: connection.key,
|
|
115
|
+
name: connection.name,
|
|
116
|
+
phoneNumber: connection.phoneNumber,
|
|
117
|
+
connected: !!WhatsappService_1.clients()[connection.key],
|
|
118
|
+
claimed: claimedKeys.has(connection.key),
|
|
119
|
+
}));
|
|
120
|
+
response.send(accounts);
|
|
121
|
+
}
|
|
67
122
|
deinit(red) {
|
|
68
123
|
console.log("STOPPING: WhatsappService");
|
|
69
124
|
}
|
|
70
125
|
static getClient(localConnectionId) {
|
|
71
|
-
return
|
|
126
|
+
return WhatsappService_1.clients()[localConnectionId];
|
|
72
127
|
}
|
|
73
128
|
linkAccount(request, response) {
|
|
74
129
|
let linkRequest = request.body;
|
|
@@ -116,15 +171,16 @@ class WhatsappService extends node_red_plugincore_1.BaseService {
|
|
|
116
171
|
// make sure we havent got this connection already.
|
|
117
172
|
let knownConnection = this.connections.find(connection => connection.key === linkRequest.localConnectionId);
|
|
118
173
|
if (!knownConnection) {
|
|
119
|
-
this.connections.push({
|
|
120
|
-
|
|
121
|
-
});
|
|
174
|
+
this.connections.push({ key: linkRequest.localConnectionId });
|
|
175
|
+
// ensure the new entry exists before saveConnectionDetails tries to update it
|
|
122
176
|
fs_1.default.writeFileSync(this.configFile, JSON.stringify(this.connections, null, 2), { flag: "w+" });
|
|
123
177
|
}
|
|
178
|
+
// save account details (name, phone) to disk
|
|
179
|
+
this.saveConnectionDetails(linkRequest.localConnectionId);
|
|
124
180
|
// stop the timeout timer, and move client from tempclients to clients.
|
|
125
181
|
clearTimeout(timeoutTimer);
|
|
126
182
|
delete this.tempClients[linkRequest.localConnectionId];
|
|
127
|
-
|
|
183
|
+
WhatsappService_1.clients()[linkRequest.localConnectionId] = client;
|
|
128
184
|
// send a notification to the frontend.
|
|
129
185
|
red.events.emit("runtime-event", {
|
|
130
186
|
id: "whatsapp/" + linkRequest.localConnectionId,
|
|
@@ -140,10 +196,10 @@ class WhatsappService extends node_red_plugincore_1.BaseService {
|
|
|
140
196
|
unlinkaccount(request, response) {
|
|
141
197
|
let unlinkAccountRequest = request.body;
|
|
142
198
|
// get an instance of the client and stop it.
|
|
143
|
-
let client =
|
|
199
|
+
let client = WhatsappService_1.clients()[unlinkAccountRequest.localConnectionId];
|
|
144
200
|
let deleteAccountData = () => {
|
|
145
201
|
// after stopping the client, remove it from the clients list, update the connections file, and remove its storage.
|
|
146
|
-
delete
|
|
202
|
+
delete WhatsappService_1.clients()[unlinkAccountRequest.localConnectionId];
|
|
147
203
|
this.connections = this.connections.filter(connection => connection.key !== unlinkAccountRequest.localConnectionId);
|
|
148
204
|
fs_1.default.writeFileSync(this.configFile, JSON.stringify(this.connections, null, 2), { flag: "w+" });
|
|
149
205
|
fs_1.default.rmSync(this.configDir + "/" + unlinkAccountRequest.localConnectionId, { recursive: true });
|
|
@@ -158,7 +214,7 @@ class WhatsappService extends node_red_plugincore_1.BaseService {
|
|
|
158
214
|
}
|
|
159
215
|
}
|
|
160
216
|
async getGroups(request, response) {
|
|
161
|
-
let client =
|
|
217
|
+
let client = WhatsappService_1.clients()[request.body.localConnectionId];
|
|
162
218
|
if (client) {
|
|
163
219
|
response.send(await client.groups().getAll());
|
|
164
220
|
}
|
|
@@ -167,7 +223,7 @@ class WhatsappService extends node_red_plugincore_1.BaseService {
|
|
|
167
223
|
}
|
|
168
224
|
}
|
|
169
225
|
async createGroup(request, response) {
|
|
170
|
-
let client =
|
|
226
|
+
let client = WhatsappService_1.clients()[request.body.localConnectionId];
|
|
171
227
|
if (client) {
|
|
172
228
|
response.send(await client.groups().createGroup(request.body.groupName));
|
|
173
229
|
}
|
|
@@ -176,7 +232,7 @@ class WhatsappService extends node_red_plugincore_1.BaseService {
|
|
|
176
232
|
}
|
|
177
233
|
}
|
|
178
234
|
async groupAddUser(request, response) {
|
|
179
|
-
let client =
|
|
235
|
+
let client = WhatsappService_1.clients()[request.body.localConnectionId];
|
|
180
236
|
if (client) {
|
|
181
237
|
await client.groups().addUserToGroup(request.body.userId, request.body.groupId, request.body.role);
|
|
182
238
|
response.send({ status: "ok" });
|
|
@@ -186,7 +242,7 @@ class WhatsappService extends node_red_plugincore_1.BaseService {
|
|
|
186
242
|
}
|
|
187
243
|
}
|
|
188
244
|
async groupUpdateUser(request, response) {
|
|
189
|
-
let client =
|
|
245
|
+
let client = WhatsappService_1.clients()[request.body.localConnectionId];
|
|
190
246
|
if (client) {
|
|
191
247
|
await client.groups().updateUserRole(request.body.userId, request.body.groupId, request.body.role);
|
|
192
248
|
response.send({ status: "ok" });
|
|
@@ -196,7 +252,7 @@ class WhatsappService extends node_red_plugincore_1.BaseService {
|
|
|
196
252
|
}
|
|
197
253
|
}
|
|
198
254
|
async groupRemoveUser(request, response) {
|
|
199
|
-
let client =
|
|
255
|
+
let client = WhatsappService_1.clients()[request.body.localConnectionId];
|
|
200
256
|
if (client) {
|
|
201
257
|
await client.groups().removeUserFromGroup(request.body.userId, request.body.groupId);
|
|
202
258
|
response.send({ status: "ok" });
|
|
@@ -205,8 +261,14 @@ class WhatsappService extends node_red_plugincore_1.BaseService {
|
|
|
205
261
|
response.status(500).send({ message: "Client not linked" });
|
|
206
262
|
}
|
|
207
263
|
}
|
|
208
|
-
|
|
209
|
-
return new node_red_plugincore_1.ServiceDescriptor("@theotherwillembotha/whatsappservice", "WhatsappService", "integration-plugin", "./whatsapp/service/WhatsappService", WhatsappService);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
264
|
+
};
|
|
212
265
|
exports.WhatsappService = WhatsappService;
|
|
266
|
+
exports.WhatsappService = WhatsappService = WhatsappService_1 = __decorate([
|
|
267
|
+
(0, node_red_plugincore_1.ServiceDescription)({
|
|
268
|
+
id: "@theotherwillembotha/whatsappservice",
|
|
269
|
+
name: "WhatsappService",
|
|
270
|
+
type: "integration-plugin",
|
|
271
|
+
sourceFile: "./whatsapp/service/WhatsappService",
|
|
272
|
+
}),
|
|
273
|
+
__metadata("design:paramtypes", [])
|
|
274
|
+
], WhatsappService);
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { EntityManager } from "typeorm";
|
|
2
|
+
import { ChatType } from "./WhatsappClient";
|
|
3
|
+
export declare class WhatsappStore implements DAOService {
|
|
4
|
+
static createStore(id: string, location: string): Promise<WhatsappStore>;
|
|
5
|
+
private _id;
|
|
6
|
+
private _location;
|
|
7
|
+
private _datasource;
|
|
8
|
+
private _contacts;
|
|
9
|
+
private _chats;
|
|
10
|
+
private _messages;
|
|
11
|
+
private constructor();
|
|
12
|
+
chats(): ChatDAO;
|
|
13
|
+
contacts(): ContactDAO;
|
|
14
|
+
messages(): MessageDAO;
|
|
15
|
+
}
|
|
16
|
+
interface DAOService {
|
|
17
|
+
chats(): ChatDAO;
|
|
18
|
+
contacts(): ContactDAO;
|
|
19
|
+
messages(): MessageDAO;
|
|
20
|
+
}
|
|
21
|
+
declare abstract class DAO<EntityType> {
|
|
22
|
+
private _daos;
|
|
23
|
+
private _em;
|
|
24
|
+
constructor(daos: DAOService, em: EntityManager);
|
|
25
|
+
protected daos(): DAOService;
|
|
26
|
+
protected em(): EntityManager;
|
|
27
|
+
abstract get(id: string): Promise<EntityType | null>;
|
|
28
|
+
abstract all(): Promise<EntityType[]>;
|
|
29
|
+
abstract create(...params: any): Promise<EntityType>;
|
|
30
|
+
}
|
|
31
|
+
declare enum ContactType {
|
|
32
|
+
USER = "USER",
|
|
33
|
+
GROUP = "GROUP"
|
|
34
|
+
}
|
|
35
|
+
declare class Contact {
|
|
36
|
+
/**
|
|
37
|
+
* Account ID of the whatsapp user eg: "<phone>@s.whatsapp.net"
|
|
38
|
+
*/
|
|
39
|
+
id: string;
|
|
40
|
+
type?: ContactType;
|
|
41
|
+
phoneNumber?: string;
|
|
42
|
+
name?: string;
|
|
43
|
+
lid?: string;
|
|
44
|
+
participants: Participant[];
|
|
45
|
+
constructor(id: string);
|
|
46
|
+
getName(): string | undefined;
|
|
47
|
+
}
|
|
48
|
+
declare class ContactDAO extends DAO<Contact> {
|
|
49
|
+
constructor(daos: DAOService, em: EntityManager);
|
|
50
|
+
get(id: string): Promise<Contact>;
|
|
51
|
+
all(): Promise<Contact[]>;
|
|
52
|
+
create(id: string): Promise<Contact>;
|
|
53
|
+
save(contact: Contact): Promise<Contact>;
|
|
54
|
+
getByLid(lid: string): Promise<Contact | null>;
|
|
55
|
+
}
|
|
56
|
+
export declare enum Role {
|
|
57
|
+
Admin = "Admin",
|
|
58
|
+
SuperAdmin = "SuperAdmin",
|
|
59
|
+
Member = "Member"
|
|
60
|
+
}
|
|
61
|
+
declare class Chat {
|
|
62
|
+
id: string;
|
|
63
|
+
type: string;
|
|
64
|
+
lid: string;
|
|
65
|
+
owner: string;
|
|
66
|
+
name: string;
|
|
67
|
+
description: string;
|
|
68
|
+
participants: Participant[];
|
|
69
|
+
messages: Message[];
|
|
70
|
+
constructor(id: string, lid: string, type: ChatType, owner: string, name: string, description: string);
|
|
71
|
+
addParticipant(contact: Contact, role: Role): Chat;
|
|
72
|
+
}
|
|
73
|
+
declare class ChatDAO extends DAO<Chat> {
|
|
74
|
+
constructor(daos: DAOService, em: EntityManager);
|
|
75
|
+
get(id: string): Promise<Chat | null>;
|
|
76
|
+
all(): Promise<Chat[]>;
|
|
77
|
+
create(id: string, lid: string, type: ChatType, owner: string, name: string, description: string): Promise<Chat>;
|
|
78
|
+
getWithParticipants(id: string): Promise<Chat | null>;
|
|
79
|
+
getGroups(): Promise<Chat[]>;
|
|
80
|
+
save(chat: Chat): Promise<Chat>;
|
|
81
|
+
delete(chatId: string): Promise<void>;
|
|
82
|
+
removeParticipants(chatId: string, contactIds: string[]): Promise<void>;
|
|
83
|
+
updateParticipantRole(chatId: string, contactId: string, role: Role): Promise<void>;
|
|
84
|
+
updateParticipantLabel(chatId: string, contactId: string, label: string): Promise<void>;
|
|
85
|
+
}
|
|
86
|
+
declare class Participant {
|
|
87
|
+
id: string;
|
|
88
|
+
chat: Chat;
|
|
89
|
+
contact: Contact;
|
|
90
|
+
role: Role;
|
|
91
|
+
label: string | undefined;
|
|
92
|
+
constructor(chat: Chat, contact: Contact, role: Role);
|
|
93
|
+
}
|
|
94
|
+
declare class Message {
|
|
95
|
+
id: string;
|
|
96
|
+
chat: Chat;
|
|
97
|
+
timestamp: number;
|
|
98
|
+
type: MessageType;
|
|
99
|
+
payload: string;
|
|
100
|
+
constructor(id: string, chat: Chat, timestamp: number, type: MessageType, payload: string);
|
|
101
|
+
}
|
|
102
|
+
declare class MessageDAO extends DAO<Message> {
|
|
103
|
+
constructor(daos: DAOService, em: EntityManager);
|
|
104
|
+
get(id: string): Promise<Message | null>;
|
|
105
|
+
all(): Promise<Message[]>;
|
|
106
|
+
create(chat: Chat, id: string, timestamp: number, type: MessageType, payload: string): Promise<Message>;
|
|
107
|
+
}
|
|
108
|
+
export declare enum MessageType {
|
|
109
|
+
Text = "Text",
|
|
110
|
+
Unknown = "Unknown",
|
|
111
|
+
Image = "Image",
|
|
112
|
+
Video = "Video",
|
|
113
|
+
Document = "Document",
|
|
114
|
+
Template = "Template",
|
|
115
|
+
ExtendedText = "ExtendedText",
|
|
116
|
+
Album = "Album",
|
|
117
|
+
Stub = "Stub",
|
|
118
|
+
Contact = "Contact",
|
|
119
|
+
Interactive = "Interactive",
|
|
120
|
+
Location = "Location",
|
|
121
|
+
LiveLocation = "LiveLocation",
|
|
122
|
+
Event = "Event",
|
|
123
|
+
EventResponse = "EventResponse",
|
|
124
|
+
Sticker = "Sticker"
|
|
125
|
+
}
|
|
126
|
+
export { Contact, Chat, Message };
|
|
127
|
+
//# sourceMappingURL=Whats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AU;IACf,QAAQ,aAAa;IACrB,QAAQ,aAAa;IACrB,YAAY,iBAAiB;IAC7B,KAAK,UAAU;IACf,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,WAAW,gBAAgB;IAC3B,QAAQ,aAAa;IACrB,YAAY,iBAAiB;IAC7B,KAAK,UAAU;IACf,aAAa,kBAAkB;IAC/B,OAAO,YAAY;CACtB;AAGD,OAAO,EACH,OAAO,EAAE,IAAI,EAAE,OAAO,EACzB,CAAA"}
|
|
@@ -233,20 +233,20 @@ class ChatDAO extends DAO {
|
|
|
233
233
|
async getWithParticipants(id) {
|
|
234
234
|
return this.em().findOne(Chat, {
|
|
235
235
|
where: { id },
|
|
236
|
-
relations:
|
|
236
|
+
relations: { participants: { contact: true } }
|
|
237
237
|
});
|
|
238
238
|
}
|
|
239
239
|
async getGroups() {
|
|
240
240
|
return this.em().find(Chat, {
|
|
241
241
|
where: { type: WhatsappClient_1.ChatType.Group },
|
|
242
|
-
relations:
|
|
242
|
+
relations: { participants: { contact: true } }
|
|
243
243
|
});
|
|
244
244
|
}
|
|
245
245
|
async save(chat) {
|
|
246
246
|
return this.em().save(chat);
|
|
247
247
|
}
|
|
248
248
|
async delete(chatId) {
|
|
249
|
-
const chat = await this.em().findOne(Chat, { where: { id: chatId }, relations:
|
|
249
|
+
const chat = await this.em().findOne(Chat, { where: { id: chatId }, relations: { participants: true } });
|
|
250
250
|
if (chat) {
|
|
251
251
|
await this.em().remove(chat);
|
|
252
252
|
}
|
|
@@ -254,7 +254,7 @@ class ChatDAO extends DAO {
|
|
|
254
254
|
async removeParticipants(chatId, contactIds) {
|
|
255
255
|
const chat = await this.em().findOne(Chat, {
|
|
256
256
|
where: { id: chatId },
|
|
257
|
-
relations:
|
|
257
|
+
relations: { participants: { contact: true } }
|
|
258
258
|
});
|
|
259
259
|
if (!chat)
|
|
260
260
|
return;
|
|
@@ -264,7 +264,7 @@ class ChatDAO extends DAO {
|
|
|
264
264
|
async updateParticipantRole(chatId, contactId, role) {
|
|
265
265
|
const chat = await this.em().findOne(Chat, {
|
|
266
266
|
where: { id: chatId },
|
|
267
|
-
relations:
|
|
267
|
+
relations: { participants: { contact: true } }
|
|
268
268
|
});
|
|
269
269
|
if (!chat)
|
|
270
270
|
return;
|
|
@@ -277,7 +277,7 @@ class ChatDAO extends DAO {
|
|
|
277
277
|
async updateParticipantLabel(chatId, contactId, label) {
|
|
278
278
|
const chat = await this.em().findOne(Chat, {
|
|
279
279
|
where: { id: chatId },
|
|
280
|
-
relations:
|
|
280
|
+
relations: { participants: { contact: true } }
|
|
281
281
|
});
|
|
282
282
|
if (!chat)
|
|
283
283
|
return;
|
|
@@ -367,7 +367,7 @@ class MessageDAO extends DAO {
|
|
|
367
367
|
}
|
|
368
368
|
async create(chat, id, timestamp, type, payload) {
|
|
369
369
|
// first check if the client exists.
|
|
370
|
-
let message = await this.em().findOneBy(Message, { id: id, chat: chat });
|
|
370
|
+
let message = await this.em().findOneBy(Message, { id: id, chat: { id: chat.id } });
|
|
371
371
|
if (message) {
|
|
372
372
|
let modified = true;
|
|
373
373
|
if (message.timestamp !== timestamp) {
|
|
@@ -405,4 +405,7 @@ var MessageType;
|
|
|
405
405
|
MessageType["Interactive"] = "Interactive";
|
|
406
406
|
MessageType["Location"] = "Location";
|
|
407
407
|
MessageType["LiveLocation"] = "LiveLocation";
|
|
408
|
+
MessageType["Event"] = "Event";
|
|
409
|
+
MessageType["EventResponse"] = "EventResponse";
|
|
410
|
+
MessageType["Sticker"] = "Sticker";
|
|
408
411
|
})(MessageType || (exports.MessageType = MessageType = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theotherwillembotha/node-red-whatsapp",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Node-RED nodes for WhatsApp messaging via the Baileys library.",
|
|
5
5
|
"author": "Willem Botha (@theotherwillembotha)",
|
|
6
6
|
"license": "ISC",
|
|
@@ -13,12 +13,14 @@
|
|
|
13
13
|
],
|
|
14
14
|
"main": "./build/index.js",
|
|
15
15
|
"exports": "./build/index.js",
|
|
16
|
+
"types": "./build/index.d.ts",
|
|
16
17
|
"scripts": {
|
|
17
18
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
18
|
-
"build": "npm run clean && tsc && npm run generate-nodes && npm run copy-files",
|
|
19
|
+
"build": "npm run clean && tsc && npm run generate-nodes && npm run bundle && npm run copy-files",
|
|
19
20
|
"clean": "rm -rf ./build",
|
|
20
21
|
"typeorm": "typeorm-ts-node-commonjs",
|
|
21
22
|
"generate-nodes": "node build/GenerateNodes.js",
|
|
23
|
+
"bundle": "node esbuild.js",
|
|
22
24
|
"copy-files": "cp -r ./icons ./build/"
|
|
23
25
|
},
|
|
24
26
|
"files": [
|
|
@@ -43,20 +45,21 @@
|
|
|
43
45
|
"nodered": ">=4.0.0"
|
|
44
46
|
},
|
|
45
47
|
"dependencies": {
|
|
46
|
-
"@theotherwillembotha/node-red-plugincore": "^0.
|
|
47
|
-
"baileys": "7.0.0-
|
|
48
|
-
"handlebars": "^4.7.
|
|
48
|
+
"@theotherwillembotha/node-red-plugincore": "^0.4.2",
|
|
49
|
+
"baileys": "7.0.0-rc14",
|
|
50
|
+
"handlebars": "^4.7.9",
|
|
49
51
|
"node-cache": "^5.1.2",
|
|
50
52
|
"qrcode": "^1.5.4",
|
|
51
|
-
"sql.js": "^1.
|
|
52
|
-
"typeorm": "^0.
|
|
53
|
-
"uuid": "^
|
|
53
|
+
"sql.js": "^1.14.1",
|
|
54
|
+
"typeorm": "^1.0.0",
|
|
55
|
+
"uuid": "^14.0.1"
|
|
54
56
|
},
|
|
55
57
|
"devDependencies": {
|
|
56
58
|
"@theotherwillembotha/node-red-plugincore": "../nodered_plugincore",
|
|
57
59
|
"@types/node": "^22.15.16",
|
|
58
60
|
"@types/node-red": "~1.3.5",
|
|
59
61
|
"@types/qrcode": "^1.5.6",
|
|
62
|
+
"esbuild": "^0.25.0",
|
|
60
63
|
"ts-node": "^10.9.2"
|
|
61
64
|
},
|
|
62
65
|
"node-red": {
|