voice-calls-baileys 1.0.4 → 1.0.5
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/lib/demo.js +1 -1
- package/lib/services/transport.model.d.ts +1 -2
- package/lib/services/transport.model.js +54 -26
- package/package.json +1 -1
- package/src/demo.ts +1 -1
- package/src/services/transport.model.ts +150 -69
package/lib/demo.js
CHANGED
|
@@ -39,7 +39,7 @@ async function connectToWhatsApp() {
|
|
|
39
39
|
syncFullHistory: false,
|
|
40
40
|
markOnlineOnConnect: false
|
|
41
41
|
});
|
|
42
|
-
(0, transport_model_1.useVoiceCallsBaileys)("your token", sock, "close",
|
|
42
|
+
(0, transport_model_1.useVoiceCallsBaileys)("your token", sock, "close", true);
|
|
43
43
|
sock.ev.on("creds.update", saveCreds);
|
|
44
44
|
sock.ev.on('connection.update', (update) => {
|
|
45
45
|
var _a, _b;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Socket } from "socket.io-client";
|
|
2
2
|
import { ClientToServerEvents, ServerToClientEvents } from "./transport.type";
|
|
3
3
|
import { WAConnectionState, WASocket } from "baileys";
|
|
4
|
-
|
|
5
|
-
export declare const useVoiceCallsBaileys: (wavoip_token: string, baileys_sock: WASocket, status?: WAConnectionState, logger?: Logger) => Promise<Socket<ServerToClientEvents, ClientToServerEvents>>;
|
|
4
|
+
export declare const useVoiceCallsBaileys: (wavoip_token: string, baileys_sock: WASocket, status?: WAConnectionState, logger?: boolean) => Promise<Socket<ServerToClientEvents, ClientToServerEvents>>;
|
|
@@ -6,103 +6,127 @@ let baileys_connection_state = "close";
|
|
|
6
6
|
const useVoiceCallsBaileys = async (wavoip_token, baileys_sock, status, logger) => {
|
|
7
7
|
baileys_connection_state = status !== null && status !== void 0 ? status : "close";
|
|
8
8
|
const socket = (0, socket_io_client_1.io)("https://devices.wavoip.com/baileys", {
|
|
9
|
-
transports: [
|
|
9
|
+
transports: ["websocket"],
|
|
10
10
|
path: `/${wavoip_token}/websocket`,
|
|
11
|
-
forceNew: true
|
|
11
|
+
forceNew: true,
|
|
12
12
|
});
|
|
13
13
|
socket.on("connect", () => {
|
|
14
|
-
|
|
14
|
+
if (logger)
|
|
15
|
+
console.log("[*] - Wavoip connected", socket.id);
|
|
15
16
|
socket.emit("init", baileys_sock.authState.creds.me, baileys_sock.authState.creds.account, baileys_connection_state);
|
|
16
17
|
});
|
|
17
18
|
socket.on("disconnect", () => {
|
|
18
|
-
|
|
19
|
+
if (logger)
|
|
20
|
+
console.log("[*] - Wavoip disconnect");
|
|
19
21
|
});
|
|
20
22
|
socket.on("connect_error", (error) => {
|
|
21
23
|
if (socket.active) {
|
|
22
|
-
|
|
24
|
+
if (logger)
|
|
25
|
+
console.log("[*] - Wavoip connection error temporary failure, the socket will automatically try to reconnect", error);
|
|
23
26
|
}
|
|
24
27
|
else {
|
|
25
|
-
|
|
28
|
+
if (logger)
|
|
29
|
+
console.log("[*] - Wavoip connection error", error.message);
|
|
26
30
|
}
|
|
27
31
|
});
|
|
28
32
|
socket.on("onWhatsApp", async (jid, callback) => {
|
|
29
33
|
try {
|
|
30
34
|
const response = await baileys_sock.onWhatsApp(jid);
|
|
31
35
|
callback(response);
|
|
32
|
-
|
|
36
|
+
if (logger)
|
|
37
|
+
console.log("[*] Success on call onWhatsApp function", response, jid);
|
|
33
38
|
}
|
|
34
39
|
catch (error) {
|
|
35
|
-
|
|
40
|
+
if (logger)
|
|
41
|
+
console.error("[*] Error on call onWhatsApp function", error);
|
|
36
42
|
}
|
|
37
43
|
});
|
|
38
44
|
socket.on("profilePictureUrl", async (jid, type, timeoutMs, callback) => {
|
|
39
45
|
try {
|
|
40
46
|
const response = await baileys_sock.profilePictureUrl(jid, type, timeoutMs);
|
|
41
47
|
callback(response);
|
|
42
|
-
|
|
48
|
+
if (logger)
|
|
49
|
+
console.log("[*] Success on call profilePictureUrl function", response);
|
|
43
50
|
}
|
|
44
51
|
catch (error) {
|
|
45
|
-
|
|
52
|
+
if (logger)
|
|
53
|
+
console.error("[*] Error on call profilePictureUrl function", error);
|
|
46
54
|
}
|
|
47
55
|
});
|
|
48
56
|
socket.on("assertSessions", async (jids, force, callback) => {
|
|
49
57
|
try {
|
|
50
58
|
const response = await baileys_sock.assertSessions(jids, force);
|
|
51
59
|
callback(response);
|
|
52
|
-
|
|
60
|
+
if (logger)
|
|
61
|
+
console.log("[*] Success on call assertSessions function", response);
|
|
53
62
|
}
|
|
54
63
|
catch (error) {
|
|
55
|
-
|
|
64
|
+
if (logger)
|
|
65
|
+
console.error("[*] Error on call assertSessions function", error);
|
|
56
66
|
}
|
|
57
67
|
});
|
|
58
68
|
socket.on("createParticipantNodes", async (jids, message, extraAttrs, callback) => {
|
|
59
69
|
try {
|
|
60
70
|
const response = await baileys_sock.createParticipantNodes(jids, message, extraAttrs);
|
|
61
71
|
callback(response, true);
|
|
62
|
-
|
|
72
|
+
if (logger)
|
|
73
|
+
console.log("[*] Success on call createParticipantNodes function", response);
|
|
63
74
|
}
|
|
64
75
|
catch (error) {
|
|
65
|
-
|
|
76
|
+
if (logger)
|
|
77
|
+
console.error("[*] Error on call createParticipantNodes function", error);
|
|
66
78
|
}
|
|
67
79
|
});
|
|
68
80
|
socket.on("getUSyncDevices", async (jids, useCache, ignoreZeroDevices, callback) => {
|
|
69
81
|
try {
|
|
70
82
|
const response = await baileys_sock.getUSyncDevices(jids, useCache, ignoreZeroDevices);
|
|
71
83
|
callback(response);
|
|
72
|
-
|
|
84
|
+
if (logger)
|
|
85
|
+
console.log("[*] Success on call getUSyncDevices function", response);
|
|
73
86
|
}
|
|
74
87
|
catch (error) {
|
|
75
|
-
|
|
88
|
+
if (logger)
|
|
89
|
+
console.error("[*] Error on call getUSyncDevices function", error);
|
|
76
90
|
}
|
|
77
91
|
});
|
|
78
92
|
socket.on("generateMessageTag", async (callback) => {
|
|
79
93
|
try {
|
|
80
94
|
const response = await baileys_sock.generateMessageTag();
|
|
81
95
|
callback(response);
|
|
82
|
-
|
|
96
|
+
if (logger)
|
|
97
|
+
console.log("[*] Success on call generateMessageTag function", response);
|
|
83
98
|
}
|
|
84
99
|
catch (error) {
|
|
85
|
-
|
|
100
|
+
if (logger)
|
|
101
|
+
console.error("[*] Error on call generateMessageTag function", error);
|
|
86
102
|
}
|
|
87
103
|
});
|
|
88
104
|
socket.on("sendNode", async (stanza, callback) => {
|
|
89
105
|
try {
|
|
90
106
|
const response = await baileys_sock.sendNode(stanza);
|
|
91
107
|
callback(true);
|
|
92
|
-
|
|
108
|
+
if (logger)
|
|
109
|
+
console.log("[*] Success on call sendNode function", response);
|
|
93
110
|
}
|
|
94
111
|
catch (error) {
|
|
95
|
-
|
|
112
|
+
if (logger)
|
|
113
|
+
console.error("[*] Error on call sendNode function", error);
|
|
96
114
|
}
|
|
97
115
|
});
|
|
98
116
|
socket.on("signalRepository:decryptMessage", async (jid, type, ciphertext, callback) => {
|
|
99
117
|
try {
|
|
100
|
-
const response = await baileys_sock.signalRepository.decryptMessage({
|
|
118
|
+
const response = await baileys_sock.signalRepository.decryptMessage({
|
|
119
|
+
jid: jid,
|
|
120
|
+
type: type,
|
|
121
|
+
ciphertext: ciphertext,
|
|
122
|
+
});
|
|
101
123
|
callback(response);
|
|
102
|
-
|
|
124
|
+
if (logger)
|
|
125
|
+
console.log("[*] Success on call signalRepository:decryptMessage function", response);
|
|
103
126
|
}
|
|
104
127
|
catch (error) {
|
|
105
|
-
|
|
128
|
+
if (logger)
|
|
129
|
+
console.error("[*] Error on call signalRepository:decryptMessage function", error);
|
|
106
130
|
}
|
|
107
131
|
});
|
|
108
132
|
// we only use this connection data to inform the webphone that the device is connected and creeds account to generate e2e whatsapp key for make call packets
|
|
@@ -110,18 +134,22 @@ const useVoiceCallsBaileys = async (wavoip_token, baileys_sock, status, logger)
|
|
|
110
134
|
const { connection } = update;
|
|
111
135
|
if (connection) {
|
|
112
136
|
baileys_connection_state = connection;
|
|
113
|
-
socket
|
|
137
|
+
socket
|
|
138
|
+
.timeout(5000)
|
|
139
|
+
.emit("connection.update:status", baileys_sock.authState.creds.me, baileys_sock.authState.creds.account, connection);
|
|
114
140
|
}
|
|
115
141
|
if (update.qr) {
|
|
116
142
|
socket.timeout(5000).emit("connection.update:qr", update.qr);
|
|
117
143
|
}
|
|
118
144
|
});
|
|
119
145
|
baileys_sock.ws.on("CB:call", (packet) => {
|
|
120
|
-
|
|
146
|
+
if (logger)
|
|
147
|
+
console.log("[*] Signling received");
|
|
121
148
|
socket.volatile.timeout(5000).emit("CB:call", packet);
|
|
122
149
|
});
|
|
123
150
|
baileys_sock.ws.on("CB:ack,class:call", (packet) => {
|
|
124
|
-
|
|
151
|
+
if (logger)
|
|
152
|
+
console.log("[*] Signling ack received");
|
|
125
153
|
socket.volatile.timeout(5000).emit("CB:ack,class:call", packet);
|
|
126
154
|
});
|
|
127
155
|
return socket;
|
package/package.json
CHANGED
package/src/demo.ts
CHANGED
|
@@ -8,30 +8,47 @@ import { Logger } from "pino";
|
|
|
8
8
|
|
|
9
9
|
let baileys_connection_state: WAConnectionState = "close";
|
|
10
10
|
|
|
11
|
-
export const useVoiceCallsBaileys = async (
|
|
11
|
+
export const useVoiceCallsBaileys = async (
|
|
12
|
+
wavoip_token: string,
|
|
13
|
+
baileys_sock: WASocket,
|
|
14
|
+
status?: WAConnectionState,
|
|
15
|
+
logger?: boolean
|
|
16
|
+
) => {
|
|
12
17
|
baileys_connection_state = status ?? "close";
|
|
13
18
|
|
|
14
|
-
const socket: Socket<ServerToClientEvents, ClientToServerEvents> = io(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
const socket: Socket<ServerToClientEvents, ClientToServerEvents> = io(
|
|
20
|
+
"https://devices.wavoip.com/baileys",
|
|
21
|
+
{
|
|
22
|
+
transports: ["websocket"],
|
|
23
|
+
path: `/${wavoip_token}/websocket`,
|
|
24
|
+
forceNew: true,
|
|
25
|
+
}
|
|
26
|
+
);
|
|
19
27
|
|
|
20
28
|
socket.on("connect", () => {
|
|
21
|
-
logger
|
|
22
|
-
|
|
23
|
-
socket.emit(
|
|
29
|
+
if (logger) console.log("[*] - Wavoip connected", socket.id);
|
|
30
|
+
|
|
31
|
+
socket.emit(
|
|
32
|
+
"init",
|
|
33
|
+
baileys_sock.authState.creds.me,
|
|
34
|
+
baileys_sock.authState.creds.account,
|
|
35
|
+
baileys_connection_state
|
|
36
|
+
);
|
|
24
37
|
});
|
|
25
|
-
|
|
38
|
+
|
|
26
39
|
socket.on("disconnect", () => {
|
|
27
|
-
logger
|
|
40
|
+
if (logger) console.log("[*] - Wavoip disconnect");
|
|
28
41
|
});
|
|
29
42
|
|
|
30
43
|
socket.on("connect_error", (error) => {
|
|
31
44
|
if (socket.active) {
|
|
32
|
-
logger
|
|
45
|
+
if (logger)
|
|
46
|
+
console.log(
|
|
47
|
+
"[*] - Wavoip connection error temporary failure, the socket will automatically try to reconnect",
|
|
48
|
+
error
|
|
49
|
+
);
|
|
33
50
|
} else {
|
|
34
|
-
logger
|
|
51
|
+
if (logger) console.log("[*] - Wavoip connection error", error.message);
|
|
35
52
|
}
|
|
36
53
|
});
|
|
37
54
|
|
|
@@ -41,21 +58,28 @@ export const useVoiceCallsBaileys = async ( wavoip_token: string, baileys_sock:
|
|
|
41
58
|
|
|
42
59
|
callback(response);
|
|
43
60
|
|
|
44
|
-
logger
|
|
61
|
+
if (logger)
|
|
62
|
+
console.log("[*] Success on call onWhatsApp function", response, jid);
|
|
45
63
|
} catch (error) {
|
|
46
|
-
logger
|
|
64
|
+
if (logger) console.error("[*] Error on call onWhatsApp function", error);
|
|
47
65
|
}
|
|
48
66
|
});
|
|
49
67
|
|
|
50
68
|
socket.on("profilePictureUrl", async (jid, type, timeoutMs, callback) => {
|
|
51
69
|
try {
|
|
52
|
-
const response = await baileys_sock.profilePictureUrl(
|
|
70
|
+
const response = await baileys_sock.profilePictureUrl(
|
|
71
|
+
jid,
|
|
72
|
+
type,
|
|
73
|
+
timeoutMs
|
|
74
|
+
);
|
|
53
75
|
|
|
54
76
|
callback(response);
|
|
55
77
|
|
|
56
|
-
logger
|
|
78
|
+
if (logger)
|
|
79
|
+
console.log("[*] Success on call profilePictureUrl function", response);
|
|
57
80
|
} catch (error) {
|
|
58
|
-
logger
|
|
81
|
+
if (logger)
|
|
82
|
+
console.error("[*] Error on call profilePictureUrl function", error);
|
|
59
83
|
}
|
|
60
84
|
});
|
|
61
85
|
|
|
@@ -65,35 +89,61 @@ export const useVoiceCallsBaileys = async ( wavoip_token: string, baileys_sock:
|
|
|
65
89
|
|
|
66
90
|
callback(response);
|
|
67
91
|
|
|
68
|
-
logger
|
|
92
|
+
if (logger)
|
|
93
|
+
console.log("[*] Success on call assertSessions function", response);
|
|
69
94
|
} catch (error) {
|
|
70
|
-
logger
|
|
95
|
+
if (logger)
|
|
96
|
+
console.error("[*] Error on call assertSessions function", error);
|
|
71
97
|
}
|
|
72
98
|
});
|
|
73
99
|
|
|
74
|
-
socket.on(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
100
|
+
socket.on(
|
|
101
|
+
"createParticipantNodes",
|
|
102
|
+
async (jids, message, extraAttrs, callback) => {
|
|
103
|
+
try {
|
|
104
|
+
const response = await baileys_sock.createParticipantNodes(
|
|
105
|
+
jids,
|
|
106
|
+
message,
|
|
107
|
+
extraAttrs
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
callback(response, true);
|
|
111
|
+
|
|
112
|
+
if (logger)
|
|
113
|
+
console.log(
|
|
114
|
+
"[*] Success on call createParticipantNodes function",
|
|
115
|
+
response
|
|
116
|
+
);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
if (logger)
|
|
119
|
+
console.error(
|
|
120
|
+
"[*] Error on call createParticipantNodes function",
|
|
121
|
+
error
|
|
122
|
+
);
|
|
123
|
+
}
|
|
83
124
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
socket.on(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
socket.on(
|
|
128
|
+
"getUSyncDevices",
|
|
129
|
+
async (jids, useCache, ignoreZeroDevices, callback) => {
|
|
130
|
+
try {
|
|
131
|
+
const response = await baileys_sock.getUSyncDevices(
|
|
132
|
+
jids,
|
|
133
|
+
useCache,
|
|
134
|
+
ignoreZeroDevices
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
callback(response);
|
|
138
|
+
|
|
139
|
+
if (logger)
|
|
140
|
+
console.log("[*] Success on call getUSyncDevices function", response);
|
|
141
|
+
} catch (error) {
|
|
142
|
+
if (logger)
|
|
143
|
+
console.error("[*] Error on call getUSyncDevices function", error);
|
|
144
|
+
}
|
|
95
145
|
}
|
|
96
|
-
|
|
146
|
+
);
|
|
97
147
|
|
|
98
148
|
socket.on("generateMessageTag", async (callback) => {
|
|
99
149
|
try {
|
|
@@ -101,9 +151,14 @@ export const useVoiceCallsBaileys = async ( wavoip_token: string, baileys_sock:
|
|
|
101
151
|
|
|
102
152
|
callback(response);
|
|
103
153
|
|
|
104
|
-
logger
|
|
154
|
+
if (logger)
|
|
155
|
+
console.log(
|
|
156
|
+
"[*] Success on call generateMessageTag function",
|
|
157
|
+
response
|
|
158
|
+
);
|
|
105
159
|
} catch (error) {
|
|
106
|
-
logger
|
|
160
|
+
if (logger)
|
|
161
|
+
console.error("[*] Error on call generateMessageTag function", error);
|
|
107
162
|
}
|
|
108
163
|
});
|
|
109
164
|
|
|
@@ -113,47 +168,73 @@ export const useVoiceCallsBaileys = async ( wavoip_token: string, baileys_sock:
|
|
|
113
168
|
|
|
114
169
|
callback(true);
|
|
115
170
|
|
|
116
|
-
logger
|
|
171
|
+
if (logger)
|
|
172
|
+
console.log("[*] Success on call sendNode function", response);
|
|
117
173
|
} catch (error) {
|
|
118
|
-
logger
|
|
174
|
+
if (logger) console.error("[*] Error on call sendNode function", error);
|
|
119
175
|
}
|
|
120
176
|
});
|
|
121
177
|
|
|
122
|
-
socket.on(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
178
|
+
socket.on(
|
|
179
|
+
"signalRepository:decryptMessage",
|
|
180
|
+
async (jid, type, ciphertext, callback) => {
|
|
181
|
+
try {
|
|
182
|
+
const response = await baileys_sock.signalRepository.decryptMessage({
|
|
183
|
+
jid: jid,
|
|
184
|
+
type: type,
|
|
185
|
+
ciphertext: ciphertext,
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
callback(response);
|
|
189
|
+
|
|
190
|
+
if (logger)
|
|
191
|
+
console.log(
|
|
192
|
+
"[*] Success on call signalRepository:decryptMessage function",
|
|
193
|
+
response
|
|
194
|
+
);
|
|
195
|
+
} catch (error) {
|
|
196
|
+
if (logger)
|
|
197
|
+
console.error(
|
|
198
|
+
"[*] Error on call signalRepository:decryptMessage function",
|
|
199
|
+
error
|
|
200
|
+
);
|
|
201
|
+
}
|
|
131
202
|
}
|
|
132
|
-
|
|
203
|
+
);
|
|
133
204
|
|
|
134
205
|
// we only use this connection data to inform the webphone that the device is connected and creeds account to generate e2e whatsapp key for make call packets
|
|
135
|
-
baileys_sock.ev.on(
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
206
|
+
baileys_sock.ev.on(
|
|
207
|
+
"connection.update",
|
|
208
|
+
(update: Partial<ConnectionState>) => {
|
|
209
|
+
const { connection } = update;
|
|
210
|
+
|
|
211
|
+
if (connection) {
|
|
212
|
+
baileys_connection_state = connection;
|
|
213
|
+
socket
|
|
214
|
+
.timeout(5000)
|
|
215
|
+
.emit(
|
|
216
|
+
"connection.update:status",
|
|
217
|
+
baileys_sock.authState.creds.me,
|
|
218
|
+
baileys_sock.authState.creds.account,
|
|
219
|
+
connection
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (update.qr) {
|
|
224
|
+
socket.timeout(5000).emit("connection.update:qr", update.qr);
|
|
225
|
+
}
|
|
141
226
|
}
|
|
142
|
-
|
|
143
|
-
if (update.qr) {
|
|
144
|
-
socket.timeout(5000).emit("connection.update:qr", update.qr);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
227
|
+
);
|
|
147
228
|
|
|
148
229
|
baileys_sock.ws.on("CB:call", (packet) => {
|
|
149
|
-
logger
|
|
230
|
+
if (logger) console.log("[*] Signling received");
|
|
150
231
|
socket.volatile.timeout(5000).emit("CB:call", packet);
|
|
151
232
|
});
|
|
152
233
|
|
|
153
234
|
baileys_sock.ws.on("CB:ack,class:call", (packet) => {
|
|
154
|
-
logger
|
|
235
|
+
if (logger) console.log("[*] Signling ack received");
|
|
155
236
|
socket.volatile.timeout(5000).emit("CB:ack,class:call", packet);
|
|
156
237
|
});
|
|
157
238
|
|
|
158
239
|
return socket;
|
|
159
|
-
}
|
|
240
|
+
};
|