voice-calls-baileys 1.0.3 → 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 +2 -3
- package/lib/services/transport.model.js +56 -27
- 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,
|
|
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
|
-
import { WASocket } from "baileys";
|
|
4
|
-
|
|
5
|
-
export declare const useVoiceCallsBaileys: (wavoip_token: string, baileys_sock: WASocket, logger?: Logger) => Promise<Socket<ServerToClientEvents, ClientToServerEvents>>;
|
|
3
|
+
import { WAConnectionState, WASocket } from "baileys";
|
|
4
|
+
export declare const useVoiceCallsBaileys: (wavoip_token: string, baileys_sock: WASocket, status?: WAConnectionState, logger?: boolean) => Promise<Socket<ServerToClientEvents, ClientToServerEvents>>;
|
|
@@ -3,105 +3,130 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useVoiceCallsBaileys = void 0;
|
|
4
4
|
const socket_io_client_1 = require("socket.io-client");
|
|
5
5
|
let baileys_connection_state = "close";
|
|
6
|
-
const useVoiceCallsBaileys = async (wavoip_token, baileys_sock, logger) => {
|
|
6
|
+
const useVoiceCallsBaileys = async (wavoip_token, baileys_sock, status, logger) => {
|
|
7
|
+
baileys_connection_state = status !== null && status !== void 0 ? status : "close";
|
|
7
8
|
const socket = (0, socket_io_client_1.io)("https://devices.wavoip.com/baileys", {
|
|
8
|
-
transports: [
|
|
9
|
+
transports: ["websocket"],
|
|
9
10
|
path: `/${wavoip_token}/websocket`,
|
|
10
|
-
forceNew: true
|
|
11
|
+
forceNew: true,
|
|
11
12
|
});
|
|
12
13
|
socket.on("connect", () => {
|
|
13
|
-
|
|
14
|
+
if (logger)
|
|
15
|
+
console.log("[*] - Wavoip connected", socket.id);
|
|
14
16
|
socket.emit("init", baileys_sock.authState.creds.me, baileys_sock.authState.creds.account, baileys_connection_state);
|
|
15
17
|
});
|
|
16
18
|
socket.on("disconnect", () => {
|
|
17
|
-
|
|
19
|
+
if (logger)
|
|
20
|
+
console.log("[*] - Wavoip disconnect");
|
|
18
21
|
});
|
|
19
22
|
socket.on("connect_error", (error) => {
|
|
20
23
|
if (socket.active) {
|
|
21
|
-
|
|
24
|
+
if (logger)
|
|
25
|
+
console.log("[*] - Wavoip connection error temporary failure, the socket will automatically try to reconnect", error);
|
|
22
26
|
}
|
|
23
27
|
else {
|
|
24
|
-
|
|
28
|
+
if (logger)
|
|
29
|
+
console.log("[*] - Wavoip connection error", error.message);
|
|
25
30
|
}
|
|
26
31
|
});
|
|
27
32
|
socket.on("onWhatsApp", async (jid, callback) => {
|
|
28
33
|
try {
|
|
29
34
|
const response = await baileys_sock.onWhatsApp(jid);
|
|
30
35
|
callback(response);
|
|
31
|
-
|
|
36
|
+
if (logger)
|
|
37
|
+
console.log("[*] Success on call onWhatsApp function", response, jid);
|
|
32
38
|
}
|
|
33
39
|
catch (error) {
|
|
34
|
-
|
|
40
|
+
if (logger)
|
|
41
|
+
console.error("[*] Error on call onWhatsApp function", error);
|
|
35
42
|
}
|
|
36
43
|
});
|
|
37
44
|
socket.on("profilePictureUrl", async (jid, type, timeoutMs, callback) => {
|
|
38
45
|
try {
|
|
39
46
|
const response = await baileys_sock.profilePictureUrl(jid, type, timeoutMs);
|
|
40
47
|
callback(response);
|
|
41
|
-
|
|
48
|
+
if (logger)
|
|
49
|
+
console.log("[*] Success on call profilePictureUrl function", response);
|
|
42
50
|
}
|
|
43
51
|
catch (error) {
|
|
44
|
-
|
|
52
|
+
if (logger)
|
|
53
|
+
console.error("[*] Error on call profilePictureUrl function", error);
|
|
45
54
|
}
|
|
46
55
|
});
|
|
47
56
|
socket.on("assertSessions", async (jids, force, callback) => {
|
|
48
57
|
try {
|
|
49
58
|
const response = await baileys_sock.assertSessions(jids, force);
|
|
50
59
|
callback(response);
|
|
51
|
-
|
|
60
|
+
if (logger)
|
|
61
|
+
console.log("[*] Success on call assertSessions function", response);
|
|
52
62
|
}
|
|
53
63
|
catch (error) {
|
|
54
|
-
|
|
64
|
+
if (logger)
|
|
65
|
+
console.error("[*] Error on call assertSessions function", error);
|
|
55
66
|
}
|
|
56
67
|
});
|
|
57
68
|
socket.on("createParticipantNodes", async (jids, message, extraAttrs, callback) => {
|
|
58
69
|
try {
|
|
59
70
|
const response = await baileys_sock.createParticipantNodes(jids, message, extraAttrs);
|
|
60
71
|
callback(response, true);
|
|
61
|
-
|
|
72
|
+
if (logger)
|
|
73
|
+
console.log("[*] Success on call createParticipantNodes function", response);
|
|
62
74
|
}
|
|
63
75
|
catch (error) {
|
|
64
|
-
|
|
76
|
+
if (logger)
|
|
77
|
+
console.error("[*] Error on call createParticipantNodes function", error);
|
|
65
78
|
}
|
|
66
79
|
});
|
|
67
80
|
socket.on("getUSyncDevices", async (jids, useCache, ignoreZeroDevices, callback) => {
|
|
68
81
|
try {
|
|
69
82
|
const response = await baileys_sock.getUSyncDevices(jids, useCache, ignoreZeroDevices);
|
|
70
83
|
callback(response);
|
|
71
|
-
|
|
84
|
+
if (logger)
|
|
85
|
+
console.log("[*] Success on call getUSyncDevices function", response);
|
|
72
86
|
}
|
|
73
87
|
catch (error) {
|
|
74
|
-
|
|
88
|
+
if (logger)
|
|
89
|
+
console.error("[*] Error on call getUSyncDevices function", error);
|
|
75
90
|
}
|
|
76
91
|
});
|
|
77
92
|
socket.on("generateMessageTag", async (callback) => {
|
|
78
93
|
try {
|
|
79
94
|
const response = await baileys_sock.generateMessageTag();
|
|
80
95
|
callback(response);
|
|
81
|
-
|
|
96
|
+
if (logger)
|
|
97
|
+
console.log("[*] Success on call generateMessageTag function", response);
|
|
82
98
|
}
|
|
83
99
|
catch (error) {
|
|
84
|
-
|
|
100
|
+
if (logger)
|
|
101
|
+
console.error("[*] Error on call generateMessageTag function", error);
|
|
85
102
|
}
|
|
86
103
|
});
|
|
87
104
|
socket.on("sendNode", async (stanza, callback) => {
|
|
88
105
|
try {
|
|
89
106
|
const response = await baileys_sock.sendNode(stanza);
|
|
90
107
|
callback(true);
|
|
91
|
-
|
|
108
|
+
if (logger)
|
|
109
|
+
console.log("[*] Success on call sendNode function", response);
|
|
92
110
|
}
|
|
93
111
|
catch (error) {
|
|
94
|
-
|
|
112
|
+
if (logger)
|
|
113
|
+
console.error("[*] Error on call sendNode function", error);
|
|
95
114
|
}
|
|
96
115
|
});
|
|
97
116
|
socket.on("signalRepository:decryptMessage", async (jid, type, ciphertext, callback) => {
|
|
98
117
|
try {
|
|
99
|
-
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
|
+
});
|
|
100
123
|
callback(response);
|
|
101
|
-
|
|
124
|
+
if (logger)
|
|
125
|
+
console.log("[*] Success on call signalRepository:decryptMessage function", response);
|
|
102
126
|
}
|
|
103
127
|
catch (error) {
|
|
104
|
-
|
|
128
|
+
if (logger)
|
|
129
|
+
console.error("[*] Error on call signalRepository:decryptMessage function", error);
|
|
105
130
|
}
|
|
106
131
|
});
|
|
107
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
|
|
@@ -109,18 +134,22 @@ const useVoiceCallsBaileys = async (wavoip_token, baileys_sock, logger) => {
|
|
|
109
134
|
const { connection } = update;
|
|
110
135
|
if (connection) {
|
|
111
136
|
baileys_connection_state = connection;
|
|
112
|
-
socket
|
|
137
|
+
socket
|
|
138
|
+
.timeout(5000)
|
|
139
|
+
.emit("connection.update:status", baileys_sock.authState.creds.me, baileys_sock.authState.creds.account, connection);
|
|
113
140
|
}
|
|
114
141
|
if (update.qr) {
|
|
115
142
|
socket.timeout(5000).emit("connection.update:qr", update.qr);
|
|
116
143
|
}
|
|
117
144
|
});
|
|
118
145
|
baileys_sock.ws.on("CB:call", (packet) => {
|
|
119
|
-
|
|
146
|
+
if (logger)
|
|
147
|
+
console.log("[*] Signling received");
|
|
120
148
|
socket.volatile.timeout(5000).emit("CB:call", packet);
|
|
121
149
|
});
|
|
122
150
|
baileys_sock.ws.on("CB:ack,class:call", (packet) => {
|
|
123
|
-
|
|
151
|
+
if (logger)
|
|
152
|
+
console.log("[*] Signling ack received");
|
|
124
153
|
socket.volatile.timeout(5000).emit("CB:ack,class:call", packet);
|
|
125
154
|
});
|
|
126
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
|
+
};
|