voice-calls-baileys 1.0.0 → 1.0.2
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.d.ts +1 -0
- package/lib/demo.js +60 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +6 -0
- package/lib/services/transport.model.d.ts +5 -0
- package/lib/services/transport.model.js +128 -0
- package/lib/services/transport.type.d.ts +38 -0
- package/lib/services/transport.type.js +2 -0
- package/package.json +5 -3
- package/src/services/transport.model.ts +1 -1
package/lib/demo.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/demo.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const transport_model_1 = require("./services/transport.model");
|
|
30
|
+
const baileys_1 = __importStar(require("baileys"));
|
|
31
|
+
const pino_1 = __importDefault(require("pino"));
|
|
32
|
+
async function connectToWhatsApp() {
|
|
33
|
+
const { state, saveCreds } = await (0, baileys_1.useMultiFileAuthState)("voice_call_baileys");
|
|
34
|
+
const sock = (0, baileys_1.default)({
|
|
35
|
+
printQRInTerminal: true,
|
|
36
|
+
auth: state,
|
|
37
|
+
browser: baileys_1.Browsers.macOS('Desktop'),
|
|
38
|
+
logger: (0, pino_1.default)({ level: "error" }),
|
|
39
|
+
syncFullHistory: false,
|
|
40
|
+
markOnlineOnConnect: false
|
|
41
|
+
});
|
|
42
|
+
(0, transport_model_1.useVoiceCallsBaileys)("your token", sock, (0, pino_1.default)({ level: "debug" }));
|
|
43
|
+
sock.ev.on("creds.update", saveCreds);
|
|
44
|
+
sock.ev.on('connection.update', (update) => {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
const { connection, lastDisconnect } = update;
|
|
47
|
+
if (connection === 'open') {
|
|
48
|
+
console.log('opened connection');
|
|
49
|
+
}
|
|
50
|
+
if (connection === "close") {
|
|
51
|
+
if ([baileys_1.DisconnectReason.loggedOut, baileys_1.DisconnectReason.forbidden].includes((_b = (_a = lastDisconnect === null || lastDisconnect === void 0 ? void 0 : lastDisconnect.error) === null || _a === void 0 ? void 0 : _a.output) === null || _b === void 0 ? void 0 : _b.statusCode)) {
|
|
52
|
+
console.log("Connection close");
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
connectToWhatsApp();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
connectToWhatsApp();
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useVoiceCallsBaileys = void 0;
|
|
4
|
+
const transport_model_1 = require("./services/transport.model");
|
|
5
|
+
Object.defineProperty(exports, "useVoiceCallsBaileys", { enumerable: true, get: function () { return transport_model_1.useVoiceCallsBaileys; } });
|
|
6
|
+
exports.default = transport_model_1.useVoiceCallsBaileys;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Socket } from "socket.io-client";
|
|
2
|
+
import { ClientToServerEvents, ServerToClientEvents } from "./transport.type";
|
|
3
|
+
import { WASocket } from "baileys";
|
|
4
|
+
import { Logger } from "pino";
|
|
5
|
+
export declare const useVoiceCallsBaileys: (wavoip_token: string, baileys_sock: WASocket, logger?: Logger) => Promise<Socket<ServerToClientEvents, ClientToServerEvents>>;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useVoiceCallsBaileys = void 0;
|
|
4
|
+
const socket_io_client_1 = require("socket.io-client");
|
|
5
|
+
let baileys_connection_state = "close";
|
|
6
|
+
const useVoiceCallsBaileys = async (wavoip_token, baileys_sock, logger) => {
|
|
7
|
+
const socket = (0, socket_io_client_1.io)("https://devices.wavoip.com/baileys", {
|
|
8
|
+
transports: ['websocket'],
|
|
9
|
+
path: `/${wavoip_token}/websocket`,
|
|
10
|
+
forceNew: true
|
|
11
|
+
});
|
|
12
|
+
socket.on("connect", () => {
|
|
13
|
+
logger === null || logger === void 0 ? void 0 : logger.debug("[*] - Wavoip connected", socket.id);
|
|
14
|
+
socket.emit("init", baileys_sock.authState.creds.me, baileys_sock.authState.creds.account, baileys_connection_state);
|
|
15
|
+
});
|
|
16
|
+
socket.on("disconnect", () => {
|
|
17
|
+
logger === null || logger === void 0 ? void 0 : logger.debug("[*] - Wavoip disconnect");
|
|
18
|
+
});
|
|
19
|
+
socket.on("connect_error", (error) => {
|
|
20
|
+
if (socket.active) {
|
|
21
|
+
logger === null || logger === void 0 ? void 0 : logger.debug("[*] - Wavoip connection error temporary failure, the socket will automatically try to reconnect", error);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
logger === null || logger === void 0 ? void 0 : logger.debug("[*] - Wavoip connection error", error.message);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
socket.on("onWhatsApp", async (jid, callback) => {
|
|
28
|
+
try {
|
|
29
|
+
const response = await baileys_sock.onWhatsApp(jid);
|
|
30
|
+
callback(response);
|
|
31
|
+
logger === null || logger === void 0 ? void 0 : logger.debug("[*] Success on call onWhatsApp function", response, jid);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
logger === null || logger === void 0 ? void 0 : logger.error("[*] Error on call onWhatsApp function", error);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
socket.on("profilePictureUrl", async (jid, type, timeoutMs, callback) => {
|
|
38
|
+
try {
|
|
39
|
+
const response = await baileys_sock.profilePictureUrl(jid, type, timeoutMs);
|
|
40
|
+
callback(response);
|
|
41
|
+
logger === null || logger === void 0 ? void 0 : logger.debug("[*] Success on call profilePictureUrl function", response);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
logger === null || logger === void 0 ? void 0 : logger.error("[*] Error on call profilePictureUrl function", error);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
socket.on("assertSessions", async (jids, force, callback) => {
|
|
48
|
+
try {
|
|
49
|
+
const response = await baileys_sock.assertSessions(jids, force);
|
|
50
|
+
callback(response);
|
|
51
|
+
logger === null || logger === void 0 ? void 0 : logger.debug("[*] Success on call assertSessions function", response);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
logger === null || logger === void 0 ? void 0 : logger.error("[*] Error on call assertSessions function", error);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
socket.on("createParticipantNodes", async (jids, message, extraAttrs, callback) => {
|
|
58
|
+
try {
|
|
59
|
+
const response = await baileys_sock.createParticipantNodes(jids, message, extraAttrs);
|
|
60
|
+
callback(response, true);
|
|
61
|
+
logger === null || logger === void 0 ? void 0 : logger.debug("[*] Success on call createParticipantNodes function", response);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
logger === null || logger === void 0 ? void 0 : logger.error("[*] Error on call createParticipantNodes function", error);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
socket.on("getUSyncDevices", async (jids, useCache, ignoreZeroDevices, callback) => {
|
|
68
|
+
try {
|
|
69
|
+
const response = await baileys_sock.getUSyncDevices(jids, useCache, ignoreZeroDevices);
|
|
70
|
+
callback(response);
|
|
71
|
+
logger === null || logger === void 0 ? void 0 : logger.debug("[*] Success on call getUSyncDevices function", response);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
logger === null || logger === void 0 ? void 0 : logger.error("[*] Error on call getUSyncDevices function", error);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
socket.on("generateMessageTag", async (callback) => {
|
|
78
|
+
try {
|
|
79
|
+
const response = await baileys_sock.generateMessageTag();
|
|
80
|
+
callback(response);
|
|
81
|
+
logger === null || logger === void 0 ? void 0 : logger.debug("[*] Success on call generateMessageTag function", response);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
logger === null || logger === void 0 ? void 0 : logger.error("[*] Error on call generateMessageTag function", error);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
socket.on("sendNode", async (stanza, callback) => {
|
|
88
|
+
try {
|
|
89
|
+
const response = await baileys_sock.sendNode(stanza);
|
|
90
|
+
callback(true);
|
|
91
|
+
logger === null || logger === void 0 ? void 0 : logger.debug("[*] Success on call sendNode function", response);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
logger === null || logger === void 0 ? void 0 : logger.error("[*] Error on call sendNode function", error);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
socket.on("signalRepository:decryptMessage", async (jid, type, ciphertext, callback) => {
|
|
98
|
+
try {
|
|
99
|
+
const response = await baileys_sock.signalRepository.decryptMessage({ jid: jid, type: type, ciphertext: ciphertext });
|
|
100
|
+
callback(response);
|
|
101
|
+
logger === null || logger === void 0 ? void 0 : logger.debug("[*] Success on call signalRepository:decryptMessage function", response);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
logger === null || logger === void 0 ? void 0 : logger.error("[*] Error on call signalRepository:decryptMessage function", error);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
// 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
|
|
108
|
+
baileys_sock.ev.on("connection.update", (update) => {
|
|
109
|
+
const { connection } = update;
|
|
110
|
+
if (connection) {
|
|
111
|
+
baileys_connection_state = connection;
|
|
112
|
+
socket.timeout(5000).emit("connection.update:status", baileys_sock.authState.creds.me, baileys_sock.authState.creds.account, connection);
|
|
113
|
+
}
|
|
114
|
+
if (update.qr) {
|
|
115
|
+
socket.timeout(5000).emit("connection.update:qr", update.qr);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
baileys_sock.ws.on("CB:call", (packet) => {
|
|
119
|
+
logger === null || logger === void 0 ? void 0 : logger.debug("[*] Signling received");
|
|
120
|
+
socket.volatile.timeout(5000).emit("CB:call", packet);
|
|
121
|
+
});
|
|
122
|
+
baileys_sock.ws.on("CB:ack,class:call", (packet) => {
|
|
123
|
+
logger === null || logger === void 0 ? void 0 : logger.debug("[*] Signling ack received");
|
|
124
|
+
socket.volatile.timeout(5000).emit("CB:ack,class:call", packet);
|
|
125
|
+
});
|
|
126
|
+
return socket;
|
|
127
|
+
};
|
|
128
|
+
exports.useVoiceCallsBaileys = useVoiceCallsBaileys;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { WAConnectionState, JidWithDevice, Contact, BinaryNode, proto } from "baileys";
|
|
2
|
+
export interface ServerToClientEvents {
|
|
3
|
+
withAck: (d: string, callback: (e: number) => void) => void;
|
|
4
|
+
onWhatsApp: onWhatsAppType;
|
|
5
|
+
profilePictureUrl: ProfilePictureUrlType;
|
|
6
|
+
assertSessions: AssertSessionsType;
|
|
7
|
+
createParticipantNodes: CreateParticipantNodesType;
|
|
8
|
+
getUSyncDevices: GetUSyncDevicesType;
|
|
9
|
+
generateMessageTag: GenerateMessageTagType;
|
|
10
|
+
sendNode: SendNodeType;
|
|
11
|
+
"signalRepository:decryptMessage": SignalRepositoryDecryptMessageType;
|
|
12
|
+
}
|
|
13
|
+
export interface ClientToServerEvents {
|
|
14
|
+
"init": (me: Contact | undefined, account: proto.IADVSignedDeviceIdentity | undefined, status: WAConnectionState) => void;
|
|
15
|
+
"CB:call": (packet: any) => void;
|
|
16
|
+
"CB:ack,class:call": (packet: any) => void;
|
|
17
|
+
"connection.update:status": (me: Contact | undefined, account: proto.IADVSignedDeviceIdentity | undefined, status: WAConnectionState) => void;
|
|
18
|
+
"connection.update:qr": (qr: string) => void;
|
|
19
|
+
}
|
|
20
|
+
export type onWhatsAppType = (jid: string, callback: onWhatsAppCallback) => void;
|
|
21
|
+
export type onWhatsAppCallback = (response: {
|
|
22
|
+
exists: boolean;
|
|
23
|
+
jid: string;
|
|
24
|
+
}[]) => void;
|
|
25
|
+
export type ProfilePictureUrlType = (jid: string, type: "image" | "preview", timeoutMs: number | undefined, callback: ProfilePictureUrlCallback) => void;
|
|
26
|
+
export type ProfilePictureUrlCallback = (response: string | undefined) => void;
|
|
27
|
+
export type AssertSessionsType = (jids: string[], force: boolean, callback: AssertSessionsCallback) => void;
|
|
28
|
+
export type AssertSessionsCallback = (response: boolean) => void;
|
|
29
|
+
export type CreateParticipantNodesType = (jids: string[], message: any, extraAttrs: any, callback: CreateParticipantNodesCallback) => void;
|
|
30
|
+
export type CreateParticipantNodesCallback = (nodes: any, shouldIncludeDeviceIdentity: boolean) => void;
|
|
31
|
+
export type GetUSyncDevicesType = (jids: string[], useCache: boolean, ignoreZeroDevices: boolean, callback: GetUSyncDevicesTypeCallback) => void;
|
|
32
|
+
export type GetUSyncDevicesTypeCallback = (jids: JidWithDevice[]) => void;
|
|
33
|
+
export type GenerateMessageTagType = (callback: GenerateMessageTagTypeCallback) => void;
|
|
34
|
+
export type GenerateMessageTagTypeCallback = (response: string) => void;
|
|
35
|
+
export type SendNodeType = (stanza: BinaryNode, callback: SendNodeTypeCallback) => void;
|
|
36
|
+
export type SendNodeTypeCallback = (response: boolean) => void;
|
|
37
|
+
export type SignalRepositoryDecryptMessageType = (jid: string, type: "pkmsg" | "msg", ciphertext: Buffer, callback: SignalRepositoryDecryptMessageCallback) => void;
|
|
38
|
+
export type SignalRepositoryDecryptMessageCallback = (response: any) => void;
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "voice-calls-baileys",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Integração de chamadas de voz a biblioteca baileys",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"dev": "ts-node-dev --inspect --transpile-only --ignore-watch node_modules src/index.ts"
|
|
8
|
+
"dev": "ts-node-dev --inspect --transpile-only --ignore-watch node_modules src/index.ts",
|
|
9
|
+
"build": "tsc"
|
|
8
10
|
},
|
|
9
11
|
"author": "Wavoip",
|
|
10
12
|
"license": "ISC",
|
|
@@ -73,7 +73,7 @@ export const useVoiceCallsBaileys = async ( wavoip_token: string, baileys_sock:
|
|
|
73
73
|
try {
|
|
74
74
|
const response = await baileys_sock.createParticipantNodes(jids, message, extraAttrs);
|
|
75
75
|
|
|
76
|
-
callback(response);
|
|
76
|
+
callback(response, true);
|
|
77
77
|
|
|
78
78
|
logger?.debug("[*] Success on call createParticipantNodes function", response);
|
|
79
79
|
} catch (error) {
|