trompot 1.0.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/LICENSE +21 -0
- package/README.md +560 -0
- package/lib/bot/BotBase.d.ts +82 -0
- package/lib/bot/BotBase.js +144 -0
- package/lib/bot/BotBase.js.map +1 -0
- package/lib/bot/BotEvents.d.ts +87 -0
- package/lib/bot/BotEvents.js +51 -0
- package/lib/bot/BotEvents.js.map +1 -0
- package/lib/bot/BotServer.d.ts +34 -0
- package/lib/bot/BotServer.js +118 -0
- package/lib/bot/BotServer.js.map +1 -0
- package/lib/bot/BotStatus.d.ts +4 -0
- package/lib/bot/BotStatus.js +9 -0
- package/lib/bot/BotStatus.js.map +1 -0
- package/lib/bot/IBot.d.ts +292 -0
- package/lib/bot/IBot.js +3 -0
- package/lib/bot/IBot.js.map +1 -0
- package/lib/bot/index.d.ts +5 -0
- package/lib/bot/index.js +13 -0
- package/lib/bot/index.js.map +1 -0
- package/lib/client/Client.d.ts +120 -0
- package/lib/client/Client.js +687 -0
- package/lib/client/Client.js.map +1 -0
- package/lib/client/ClientEvents.d.ts +147 -0
- package/lib/client/ClientEvents.js +93 -0
- package/lib/client/ClientEvents.js.map +1 -0
- package/lib/client/ClientFunctionHandler.d.ts +15 -0
- package/lib/client/ClientFunctionHandler.js +70 -0
- package/lib/client/ClientFunctionHandler.js.map +1 -0
- package/lib/client/ConnectionType.d.ts +4 -0
- package/lib/client/ConnectionType.js +3 -0
- package/lib/client/ConnectionType.js.map +1 -0
- package/lib/client/IAuth.d.ts +9 -0
- package/lib/client/IAuth.js +3 -0
- package/lib/client/IAuth.js.map +1 -0
- package/lib/client/IClient.d.ts +358 -0
- package/lib/client/IClient.js +3 -0
- package/lib/client/IClient.js.map +1 -0
- package/lib/client/index.d.ts +7 -0
- package/lib/client/index.js +13 -0
- package/lib/client/index.js.map +1 -0
- package/lib/cluster/ClientCluster.d.ts +428 -0
- package/lib/cluster/ClientCluster.js +1746 -0
- package/lib/cluster/ClientCluster.js.map +1 -0
- package/lib/cluster/WorkerMessage.d.ts +99 -0
- package/lib/cluster/WorkerMessage.js +84 -0
- package/lib/cluster/WorkerMessage.js.map +1 -0
- package/lib/cluster/index.d.ts +5 -0
- package/lib/cluster/index.js +27 -0
- package/lib/cluster/index.js.map +1 -0
- package/lib/configs/ConnectionConfig.d.ts +22 -0
- package/lib/configs/ConnectionConfig.js +3 -0
- package/lib/configs/ConnectionConfig.js.map +1 -0
- package/lib/configs/Defaults.d.ts +2 -0
- package/lib/configs/Defaults.js +16 -0
- package/lib/configs/Defaults.js.map +1 -0
- package/lib/configs/WAConfigs.d.ts +1 -0
- package/lib/configs/WAConfigs.js +5 -0
- package/lib/configs/WAConfigs.js.map +1 -0
- package/lib/configs/index.d.ts +3 -0
- package/lib/configs/index.js +18 -0
- package/lib/configs/index.js.map +1 -0
- package/lib/errors/ChatNotDefinedError.d.ts +4 -0
- package/lib/errors/ChatNotDefinedError.js +9 -0
- package/lib/errors/ChatNotDefinedError.js.map +1 -0
- package/lib/errors/ClientNotDefinedError.d.ts +4 -0
- package/lib/errors/ClientNotDefinedError.js +9 -0
- package/lib/errors/ClientNotDefinedError.js.map +1 -0
- package/lib/errors/UserNotDefinedError.d.ts +4 -0
- package/lib/errors/UserNotDefinedError.js +9 -0
- package/lib/errors/UserNotDefinedError.js.map +1 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.js +60 -0
- package/lib/index.js.map +1 -0
- package/lib/messages/AudioMessage.d.ts +42 -0
- package/lib/messages/AudioMessage.js +66 -0
- package/lib/messages/AudioMessage.js.map +1 -0
- package/lib/messages/ButtonMessage.d.ts +88 -0
- package/lib/messages/ButtonMessage.js +137 -0
- package/lib/messages/ButtonMessage.js.map +1 -0
- package/lib/messages/ContactMessage.d.ts +37 -0
- package/lib/messages/ContactMessage.js +93 -0
- package/lib/messages/ContactMessage.js.map +1 -0
- package/lib/messages/CustomMessage.d.ts +35 -0
- package/lib/messages/CustomMessage.js +88 -0
- package/lib/messages/CustomMessage.js.map +1 -0
- package/lib/messages/EmptyMessage.d.ts +25 -0
- package/lib/messages/EmptyMessage.js +78 -0
- package/lib/messages/EmptyMessage.js.map +1 -0
- package/lib/messages/ErrorMessage.d.ts +35 -0
- package/lib/messages/ErrorMessage.js +86 -0
- package/lib/messages/ErrorMessage.js.map +1 -0
- package/lib/messages/FileMessage.d.ts +36 -0
- package/lib/messages/FileMessage.js +60 -0
- package/lib/messages/FileMessage.js.map +1 -0
- package/lib/messages/ImageMessage.d.ts +41 -0
- package/lib/messages/ImageMessage.js +65 -0
- package/lib/messages/ImageMessage.js.map +1 -0
- package/lib/messages/ListMessage.d.ts +91 -0
- package/lib/messages/ListMessage.js +126 -0
- package/lib/messages/ListMessage.js.map +1 -0
- package/lib/messages/LocationMessage.d.ts +48 -0
- package/lib/messages/LocationMessage.js +107 -0
- package/lib/messages/LocationMessage.js.map +1 -0
- package/lib/messages/MediaMessage.d.ts +54 -0
- package/lib/messages/MediaMessage.js +113 -0
- package/lib/messages/MediaMessage.js.map +1 -0
- package/lib/messages/Message.d.ts +144 -0
- package/lib/messages/Message.js +223 -0
- package/lib/messages/Message.js.map +1 -0
- package/lib/messages/PollMessage.d.ts +87 -0
- package/lib/messages/PollMessage.js +145 -0
- package/lib/messages/PollMessage.js.map +1 -0
- package/lib/messages/PollUpdateMessage.d.ts +40 -0
- package/lib/messages/PollUpdateMessage.js +98 -0
- package/lib/messages/PollUpdateMessage.js.map +1 -0
- package/lib/messages/ReactionMessage.d.ts +36 -0
- package/lib/messages/ReactionMessage.js +91 -0
- package/lib/messages/ReactionMessage.js.map +1 -0
- package/lib/messages/StickerMessage.d.ts +49 -0
- package/lib/messages/StickerMessage.js +73 -0
- package/lib/messages/StickerMessage.js.map +1 -0
- package/lib/messages/TextMessage.d.ts +33 -0
- package/lib/messages/TextMessage.js +84 -0
- package/lib/messages/TextMessage.js.map +1 -0
- package/lib/messages/VideoMessage.d.ts +42 -0
- package/lib/messages/VideoMessage.js +66 -0
- package/lib/messages/VideoMessage.js.map +1 -0
- package/lib/messages/index.d.ts +19 -0
- package/lib/messages/index.js +81 -0
- package/lib/messages/index.js.map +1 -0
- package/lib/models/Address.d.ts +11 -0
- package/lib/models/Address.js +18 -0
- package/lib/models/Address.js.map +1 -0
- package/lib/models/Call.d.ts +68 -0
- package/lib/models/Call.js +127 -0
- package/lib/models/Call.js.map +1 -0
- package/lib/modules/chat/Chat.d.ts +142 -0
- package/lib/modules/chat/Chat.js +246 -0
- package/lib/modules/chat/Chat.js.map +1 -0
- package/lib/modules/chat/ChatAction.d.ts +3 -0
- package/lib/modules/chat/ChatAction.js +3 -0
- package/lib/modules/chat/ChatAction.js.map +1 -0
- package/lib/modules/chat/ChatStatus.d.ts +9 -0
- package/lib/modules/chat/ChatStatus.js +13 -0
- package/lib/modules/chat/ChatStatus.js.map +1 -0
- package/lib/modules/chat/ChatType.d.ts +7 -0
- package/lib/modules/chat/ChatType.js +11 -0
- package/lib/modules/chat/ChatType.js.map +1 -0
- package/lib/modules/chat/index.d.ts +5 -0
- package/lib/modules/chat/index.js +13 -0
- package/lib/modules/chat/index.js.map +1 -0
- package/lib/modules/command/Command.d.ts +67 -0
- package/lib/modules/command/Command.js +139 -0
- package/lib/modules/command/Command.js.map +1 -0
- package/lib/modules/command/CommandController.d.ts +50 -0
- package/lib/modules/command/CommandController.js +119 -0
- package/lib/modules/command/CommandController.js.map +1 -0
- package/lib/modules/command/CommandControllerEvent.d.ts +9 -0
- package/lib/modules/command/CommandControllerEvent.js +25 -0
- package/lib/modules/command/CommandControllerEvent.js.map +1 -0
- package/lib/modules/command/CommandEnums.d.ts +14 -0
- package/lib/modules/command/CommandEnums.js +20 -0
- package/lib/modules/command/CommandEnums.js.map +1 -0
- package/lib/modules/command/CommandKey.d.ts +17 -0
- package/lib/modules/command/CommandKey.js +67 -0
- package/lib/modules/command/CommandKey.js.map +1 -0
- package/lib/modules/command/CommandPermission.d.ts +9 -0
- package/lib/modules/command/CommandPermission.js +35 -0
- package/lib/modules/command/CommandPermission.js.map +1 -0
- package/lib/modules/command/ICommandControllerConfig.d.ts +7 -0
- package/lib/modules/command/ICommandControllerConfig.js +3 -0
- package/lib/modules/command/ICommandControllerConfig.js.map +1 -0
- package/lib/modules/command/advanced/AdvancedCommand.d.ts +23 -0
- package/lib/modules/command/advanced/AdvancedCommand.js +131 -0
- package/lib/modules/command/advanced/AdvancedCommand.js.map +1 -0
- package/lib/modules/command/advanced/AdvancedCommandContext.d.ts +10 -0
- package/lib/modules/command/advanced/AdvancedCommandContext.js +3 -0
- package/lib/modules/command/advanced/AdvancedCommandContext.js.map +1 -0
- package/lib/modules/command/advanced/AdvancedCommandController.d.ts +29 -0
- package/lib/modules/command/advanced/AdvancedCommandController.js +118 -0
- package/lib/modules/command/advanced/AdvancedCommandController.js.map +1 -0
- package/lib/modules/command/advanced/AdvancedCommandData.d.ts +6 -0
- package/lib/modules/command/advanced/AdvancedCommandData.js +3 -0
- package/lib/modules/command/advanced/AdvancedCommandData.js.map +1 -0
- package/lib/modules/command/advanced/AdvancedCommandJob.d.ts +12 -0
- package/lib/modules/command/advanced/AdvancedCommandJob.js +3 -0
- package/lib/modules/command/advanced/AdvancedCommandJob.js.map +1 -0
- package/lib/modules/command/advanced/AdvancedCommandNext.d.ts +4 -0
- package/lib/modules/command/advanced/AdvancedCommandNext.js +3 -0
- package/lib/modules/command/advanced/AdvancedCommandNext.js.map +1 -0
- package/lib/modules/command/advanced/AdvancedCommandOptions.d.ts +8 -0
- package/lib/modules/command/advanced/AdvancedCommandOptions.js +3 -0
- package/lib/modules/command/advanced/AdvancedCommandOptions.js.map +1 -0
- package/lib/modules/command/advanced/AdvancedCommandStart.d.ts +11 -0
- package/lib/modules/command/advanced/AdvancedCommandStart.js +3 -0
- package/lib/modules/command/advanced/AdvancedCommandStart.js.map +1 -0
- package/lib/modules/command/advanced/AdvancedCommandStop.d.ts +3 -0
- package/lib/modules/command/advanced/AdvancedCommandStop.js +3 -0
- package/lib/modules/command/advanced/AdvancedCommandStop.js.map +1 -0
- package/lib/modules/command/advanced/AdvancedCommandTask.d.ts +2 -0
- package/lib/modules/command/advanced/AdvancedCommandTask.js +3 -0
- package/lib/modules/command/advanced/AdvancedCommandTask.js.map +1 -0
- package/lib/modules/command/defaults.d.ts +2 -0
- package/lib/modules/command/defaults.js +8 -0
- package/lib/modules/command/defaults.js.map +1 -0
- package/lib/modules/command/index.d.ts +12 -0
- package/lib/modules/command/index.js +36 -0
- package/lib/modules/command/index.js.map +1 -0
- package/lib/modules/command/keys.d.ts +9 -0
- package/lib/modules/command/keys.js +27 -0
- package/lib/modules/command/keys.js.map +1 -0
- package/lib/modules/command/perms.d.ts +2 -0
- package/lib/modules/command/perms.js +11 -0
- package/lib/modules/command/perms.js.map +1 -0
- package/lib/modules/quickResponse/QuickResponse.d.ts +49 -0
- package/lib/modules/quickResponse/QuickResponse.js +64 -0
- package/lib/modules/quickResponse/QuickResponse.js.map +1 -0
- package/lib/modules/quickResponse/QuickResponseController.d.ts +55 -0
- package/lib/modules/quickResponse/QuickResponseController.js +125 -0
- package/lib/modules/quickResponse/QuickResponseController.js.map +1 -0
- package/lib/modules/quickResponse/QuickResponseOptions.d.ts +56 -0
- package/lib/modules/quickResponse/QuickResponseOptions.js +76 -0
- package/lib/modules/quickResponse/QuickResponseOptions.js.map +1 -0
- package/lib/modules/quickResponse/QuickResponsePattern.d.ts +28 -0
- package/lib/modules/quickResponse/QuickResponsePattern.js +3 -0
- package/lib/modules/quickResponse/QuickResponsePattern.js.map +1 -0
- package/lib/modules/quickResponse/QuickResponseReply.d.ts +6 -0
- package/lib/modules/quickResponse/QuickResponseReply.js +3 -0
- package/lib/modules/quickResponse/QuickResponseReply.js.map +1 -0
- package/lib/modules/quickResponse/index.d.ts +6 -0
- package/lib/modules/quickResponse/index.js +13 -0
- package/lib/modules/quickResponse/index.js.map +1 -0
- package/lib/modules/user/User.d.ts +91 -0
- package/lib/modules/user/User.js +173 -0
- package/lib/modules/user/User.js.map +1 -0
- package/lib/modules/user/UserAction.d.ts +4 -0
- package/lib/modules/user/UserAction.js +3 -0
- package/lib/modules/user/UserAction.js.map +1 -0
- package/lib/modules/user/UserEvent.d.ts +3 -0
- package/lib/modules/user/UserEvent.js +3 -0
- package/lib/modules/user/UserEvent.js.map +1 -0
- package/lib/modules/user/index.d.ts +4 -0
- package/lib/modules/user/index.js +9 -0
- package/lib/modules/user/index.js.map +1 -0
- package/lib/routes/botServer/api/v1/emitEvent.d.ts +3 -0
- package/lib/routes/botServer/api/v1/emitEvent.js +17 -0
- package/lib/routes/botServer/api/v1/emitEvent.js.map +1 -0
- package/lib/routes/botServer/api/v1/function.d.ts +3 -0
- package/lib/routes/botServer/api/v1/function.js +22 -0
- package/lib/routes/botServer/api/v1/function.js.map +1 -0
- package/lib/routes/botServer/api/v1/ping.d.ts +3 -0
- package/lib/routes/botServer/api/v1/ping.js +12 -0
- package/lib/routes/botServer/api/v1/ping.js.map +1 -0
- package/lib/routes/botServer/api/v1/register.d.ts +3 -0
- package/lib/routes/botServer/api/v1/register.js +23 -0
- package/lib/routes/botServer/api/v1/register.js.map +1 -0
- package/lib/routes/botServer/api/v1/setValue.d.ts +3 -0
- package/lib/routes/botServer/api/v1/setValue.js +18 -0
- package/lib/routes/botServer/api/v1/setValue.js.map +1 -0
- package/lib/routes/botServer/api/v1/unregister.d.ts +3 -0
- package/lib/routes/botServer/api/v1/unregister.js +22 -0
- package/lib/routes/botServer/api/v1/unregister.js.map +1 -0
- package/lib/routes/botServer/middlewares/setBotServer.d.ts +4 -0
- package/lib/routes/botServer/middlewares/setBotServer.js +16 -0
- package/lib/routes/botServer/middlewares/setBotServer.js.map +1 -0
- package/lib/routes/botServer/routes.d.ts +8 -0
- package/lib/routes/botServer/routes.js +33 -0
- package/lib/routes/botServer/routes.js.map +1 -0
- package/lib/services/AddressService.d.ts +12 -0
- package/lib/services/AddressService.js +51 -0
- package/lib/services/AddressService.js.map +1 -0
- package/lib/services/BaseService.d.ts +5 -0
- package/lib/services/BaseService.js +19 -0
- package/lib/services/BaseService.js.map +1 -0
- package/lib/services/index.d.ts +3 -0
- package/lib/services/index.js +11 -0
- package/lib/services/index.js.map +1 -0
- package/lib/telegram/TelegramAuth.d.ts +17 -0
- package/lib/telegram/TelegramAuth.js +96 -0
- package/lib/telegram/TelegramAuth.js.map +1 -0
- package/lib/telegram/TelegramBot.d.ts +88 -0
- package/lib/telegram/TelegramBot.js +345 -0
- package/lib/telegram/TelegramBot.js.map +1 -0
- package/lib/telegram/TelegramEvents.d.ts +13 -0
- package/lib/telegram/TelegramEvents.js +131 -0
- package/lib/telegram/TelegramEvents.js.map +1 -0
- package/lib/telegram/TelegramSendingController.d.ts +36 -0
- package/lib/telegram/TelegramSendingController.js +213 -0
- package/lib/telegram/TelegramSendingController.js.map +1 -0
- package/lib/telegram/TelegramToRompotConverter.d.ts +22 -0
- package/lib/telegram/TelegramToRompotConverter.js +226 -0
- package/lib/telegram/TelegramToRompotConverter.js.map +1 -0
- package/lib/telegram/TelegramUtils.d.ts +14 -0
- package/lib/telegram/TelegramUtils.js +98 -0
- package/lib/telegram/TelegramUtils.js.map +1 -0
- package/lib/telegram/index.d.ts +7 -0
- package/lib/telegram/index.js +19 -0
- package/lib/telegram/index.js.map +1 -0
- package/lib/utils/ClientUtils.d.ts +27 -0
- package/lib/utils/ClientUtils.js +62 -0
- package/lib/utils/ClientUtils.js.map +1 -0
- package/lib/utils/Generic.d.ts +47 -0
- package/lib/utils/Generic.js +173 -0
- package/lib/utils/Generic.js.map +1 -0
- package/lib/utils/Libs.d.ts +10 -0
- package/lib/utils/Libs.js +55 -0
- package/lib/utils/Libs.js.map +1 -0
- package/lib/utils/MessageHandler.d.ts +54 -0
- package/lib/utils/MessageHandler.js +81 -0
- package/lib/utils/MessageHandler.js.map +1 -0
- package/lib/utils/MessageUtils.d.ts +3 -0
- package/lib/utils/MessageUtils.js +114 -0
- package/lib/utils/MessageUtils.js.map +1 -0
- package/lib/utils/index.d.ts +6 -0
- package/lib/utils/index.js +27 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/nonce.d.ts +1 -0
- package/lib/utils/nonce.js +16 -0
- package/lib/utils/nonce.js.map +1 -0
- package/lib/utils/server.d.ts +33 -0
- package/lib/utils/server.js +75 -0
- package/lib/utils/server.js.map +1 -0
- package/lib/wa/Auth.d.ts +19 -0
- package/lib/wa/Auth.js +123 -0
- package/lib/wa/Auth.js.map +1 -0
- package/lib/wa/ConfigWAEvents.d.ts +22 -0
- package/lib/wa/ConfigWAEvents.js +526 -0
- package/lib/wa/ConfigWAEvents.js.map +1 -0
- package/lib/wa/ConvertToWAMessage.d.ts +67 -0
- package/lib/wa/ConvertToWAMessage.js +403 -0
- package/lib/wa/ConvertToWAMessage.js.map +1 -0
- package/lib/wa/ConvertWAMessage.d.ts +108 -0
- package/lib/wa/ConvertWAMessage.js +527 -0
- package/lib/wa/ConvertWAMessage.js.map +1 -0
- package/lib/wa/ID.d.ts +4 -0
- package/lib/wa/ID.js +19 -0
- package/lib/wa/ID.js.map +1 -0
- package/lib/wa/WAMessage.d.ts +3 -0
- package/lib/wa/WAMessage.js +8 -0
- package/lib/wa/WAMessage.js.map +1 -0
- package/lib/wa/WAModule.d.ts +3 -0
- package/lib/wa/WAModule.js +3 -0
- package/lib/wa/WAModule.js.map +1 -0
- package/lib/wa/WAStatus.d.ts +3 -0
- package/lib/wa/WAStatus.js +15 -0
- package/lib/wa/WAStatus.js.map +1 -0
- package/lib/wa/WhatsAppBot.d.ts +188 -0
- package/lib/wa/WhatsAppBot.js +980 -0
- package/lib/wa/WhatsAppBot.js.map +1 -0
- package/lib/wa/index.d.ts +12 -0
- package/lib/wa/index.js +37 -0
- package/lib/wa/index.js.map +1 -0
- package/lib/wa/makeInMemoryStore.d.ts +43 -0
- package/lib/wa/makeInMemoryStore.js +430 -0
- package/lib/wa/makeInMemoryStore.js.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,980 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const baileys_1 = __importStar(require("@whiskeysockets/baileys"));
|
|
40
|
+
const node_cache_1 = __importDefault(require("node-cache"));
|
|
41
|
+
const pino_1 = __importDefault(require("pino"));
|
|
42
|
+
const long_1 = __importDefault(require("long"));
|
|
43
|
+
const messages_1 = require("../messages");
|
|
44
|
+
const Generic_1 = require("../utils/Generic");
|
|
45
|
+
const Auth_1 = require("./Auth");
|
|
46
|
+
const Message_1 = require("../messages/Message");
|
|
47
|
+
const ConvertToWAMessage_1 = __importDefault(require("./ConvertToWAMessage"));
|
|
48
|
+
const makeInMemoryStore_1 = __importDefault(require("./makeInMemoryStore"));
|
|
49
|
+
const ConfigWAEvents_1 = __importDefault(require("./ConfigWAEvents"));
|
|
50
|
+
const ID_1 = require("./ID");
|
|
51
|
+
const BotStatus_1 = require("../bot/BotStatus");
|
|
52
|
+
const ChatType_1 = __importDefault(require("../modules/chat/ChatType"));
|
|
53
|
+
const BotEvents_1 = __importDefault(require("../bot/BotEvents"));
|
|
54
|
+
const WAStatus_1 = require("./WAStatus");
|
|
55
|
+
const User_1 = __importDefault(require("../modules/user/User"));
|
|
56
|
+
const Chat_1 = __importDefault(require("../modules/chat/Chat"));
|
|
57
|
+
class WhatsAppBot extends BotEvents_1.default {
|
|
58
|
+
constructor(config) {
|
|
59
|
+
super();
|
|
60
|
+
//@ts-ignore
|
|
61
|
+
this.sock = {};
|
|
62
|
+
this.auth = new Auth_1.MultiFileAuthState('./session', undefined, false);
|
|
63
|
+
this.messagesCached = [];
|
|
64
|
+
this.msgRetryCountercache = new node_cache_1.default({
|
|
65
|
+
stdTTL: baileys_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
|
|
66
|
+
useClones: false,
|
|
67
|
+
});
|
|
68
|
+
this.saveCreds = (creds) => new Promise((res) => res);
|
|
69
|
+
this.connectionListeners = [];
|
|
70
|
+
this.DisconnectReason = baileys_1.DisconnectReason;
|
|
71
|
+
this.logger = (0, pino_1.default)({ level: 'silent' });
|
|
72
|
+
this.id = '';
|
|
73
|
+
this.status = BotStatus_1.BotStatus.Offline;
|
|
74
|
+
this.phoneNumber = '';
|
|
75
|
+
this.name = '';
|
|
76
|
+
this.profileUrl = '';
|
|
77
|
+
this.lastConnectionUpdateDate = Date.now();
|
|
78
|
+
this.checkConnectionInterval = null;
|
|
79
|
+
this.configEvents = new ConfigWAEvents_1.default(this);
|
|
80
|
+
this.groupMetadataCache = new node_cache_1.default();
|
|
81
|
+
const store = (0, makeInMemoryStore_1.default)({ logger: this.logger });
|
|
82
|
+
this.store = store;
|
|
83
|
+
const waBot = this;
|
|
84
|
+
this.config = {
|
|
85
|
+
...baileys_1.DEFAULT_CONNECTION_CONFIG,
|
|
86
|
+
logger: this.logger,
|
|
87
|
+
qrTimeout: 60000,
|
|
88
|
+
defaultQueryTimeoutMs: 10000,
|
|
89
|
+
retryRequestDelayMs: 500,
|
|
90
|
+
maxMsgRetryCount: 5,
|
|
91
|
+
readAllFailedMessages: false,
|
|
92
|
+
msgRetryCounterCache: this.msgRetryCountercache,
|
|
93
|
+
autoRestartInterval: 1000 * 60 * 30, // 30 minutes (recommended)
|
|
94
|
+
useExperimentalServers: false,
|
|
95
|
+
autoSyncHistory: false,
|
|
96
|
+
autoLoadContactInfo: false,
|
|
97
|
+
autoLoadGroupInfo: false,
|
|
98
|
+
shouldIgnoreJid: () => false,
|
|
99
|
+
async patchMessageBeforeSending(msg) {
|
|
100
|
+
var _a, _b, _c, _d;
|
|
101
|
+
if (((_c = (_b = (_a = msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.listMessage) === null || _c === void 0 ? void 0 : _c.listType) ==
|
|
102
|
+
baileys_1.proto.Message.ListMessage.ListType.PRODUCT_LIST) {
|
|
103
|
+
msg = JSON.parse(JSON.stringify(msg));
|
|
104
|
+
msg.deviceSentMessage.message.listMessage.listType =
|
|
105
|
+
baileys_1.proto.Message.ListMessage.ListType.SINGLE_SELECT;
|
|
106
|
+
}
|
|
107
|
+
if (((_d = msg.listMessage) === null || _d === void 0 ? void 0 : _d.listType) ==
|
|
108
|
+
baileys_1.proto.Message.ListMessage.ListType.PRODUCT_LIST) {
|
|
109
|
+
msg = JSON.parse(JSON.stringify(msg));
|
|
110
|
+
msg.listMessage.listType =
|
|
111
|
+
baileys_1.proto.Message.ListMessage.ListType.SINGLE_SELECT;
|
|
112
|
+
}
|
|
113
|
+
return msg;
|
|
114
|
+
},
|
|
115
|
+
async getMessage(key) {
|
|
116
|
+
var _a;
|
|
117
|
+
return (((_a = (await waBot.store.loadMessage((0, ID_1.fixID)(key.remoteJid), key.id))) === null || _a === void 0 ? void 0 : _a.message) || undefined);
|
|
118
|
+
},
|
|
119
|
+
cachedGroupMetadata: async (jid) => this.groupMetadataCache.get(jid),
|
|
120
|
+
...config,
|
|
121
|
+
};
|
|
122
|
+
delete this.config.auth;
|
|
123
|
+
// Listeners de eventos Baileys
|
|
124
|
+
setTimeout(() => {
|
|
125
|
+
if (this.sock && this.sock.ev) {
|
|
126
|
+
this.sock.ev.on('messages.upsert', async ({ type, messages }) => {
|
|
127
|
+
// Exemplo: processa todas as mensagens recebidas
|
|
128
|
+
for (const msg of messages) {
|
|
129
|
+
// Aqui você pode converter proto.IMessage para Message do Rompot
|
|
130
|
+
// e emitir eventos ou chamar handlers do seu fluxo
|
|
131
|
+
// Exemplo:
|
|
132
|
+
// const rompotMsg = await ConvertWAMessage.fromBaileys(this, msg, type);
|
|
133
|
+
// this.emit('message', rompotMsg);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
this.sock.ev.on('messages.update', (updates) => {
|
|
137
|
+
// Handler para mensagens editadas, deletadas, etc.
|
|
138
|
+
});
|
|
139
|
+
this.sock.ev.on('messages.delete', (deletes) => {
|
|
140
|
+
// Handler para deleção de mensagens
|
|
141
|
+
});
|
|
142
|
+
this.sock.ev.on('messages.reaction', (reaction) => {
|
|
143
|
+
// Handler para reações em mensagens
|
|
144
|
+
});
|
|
145
|
+
// Listener para histórico de mensagens (history sync)
|
|
146
|
+
this.sock.ev.on('messaging-history.set', async ({ chats, contacts, messages, syncType }) => {
|
|
147
|
+
// Armazena chats
|
|
148
|
+
if (chats && Array.isArray(chats)) {
|
|
149
|
+
for (const chat of chats) {
|
|
150
|
+
await this.auth.set(`chats-${chat.id}`, chat);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// Armazena contatos
|
|
154
|
+
if (contacts && Array.isArray(contacts)) {
|
|
155
|
+
for (const contact of contacts) {
|
|
156
|
+
await this.auth.set(`users-${contact.id}`, contact);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// Armazena mensagens
|
|
160
|
+
if (messages && Array.isArray(messages)) {
|
|
161
|
+
for (const msg of messages) {
|
|
162
|
+
if (msg.key && msg.key.id && msg.key.remoteJid) {
|
|
163
|
+
await this.store.saveMessage(msg.key.remoteJid, msg, false);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// Você pode emitir eventos ou processar syncType conforme necessário
|
|
168
|
+
});
|
|
169
|
+
// Exibe QR code no terminal ao receber
|
|
170
|
+
this.sock.ev.on('connection.update', async (update) => {
|
|
171
|
+
const { qr } = update;
|
|
172
|
+
if (qr) {
|
|
173
|
+
try {
|
|
174
|
+
const QRCode = (await Promise.resolve().then(() => __importStar(require('qrcode')))).default;
|
|
175
|
+
// Exibe o QR code no terminal
|
|
176
|
+
console.log(await QRCode.toString(qr, { type: 'terminal' }));
|
|
177
|
+
}
|
|
178
|
+
catch (err) {
|
|
179
|
+
console.log('QRCode:', qr);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}, 0);
|
|
185
|
+
}
|
|
186
|
+
async connect(auth) {
|
|
187
|
+
var _a, _b, _c;
|
|
188
|
+
if (!auth || typeof auth == 'string') {
|
|
189
|
+
this.auth = new Auth_1.MultiFileAuthState(`${auth || './session'}`);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
this.auth = auth;
|
|
193
|
+
}
|
|
194
|
+
if (!this.auth.botPhoneNumber) {
|
|
195
|
+
await this.internalConnect({ browser: baileys_1.Browsers.windows('Rompot') });
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
await this.internalConnect({
|
|
199
|
+
browser: ['Chrome (linux)', 'Rompot', '22.5.0'],
|
|
200
|
+
});
|
|
201
|
+
if (!((_c = (_b = (_a = this.sock) === null || _a === void 0 ? void 0 : _a.authState) === null || _b === void 0 ? void 0 : _b.creds) === null || _c === void 0 ? void 0 : _c.registered)) {
|
|
202
|
+
await this.sock.waitForConnectionUpdate(async (update) => Promise.resolve(!!update.qr));
|
|
203
|
+
const code = await this.sock.requestPairingCode(this.auth.botPhoneNumber);
|
|
204
|
+
this.emit('code', code);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
await this.awaitConnectionState('open');
|
|
208
|
+
}
|
|
209
|
+
async internalConnect(additionalOptions = {}) {
|
|
210
|
+
return new Promise(async (resolve, reject) => {
|
|
211
|
+
try {
|
|
212
|
+
const { state, saveCreds } = await (0, Auth_1.getBaileysAuth)(this.auth);
|
|
213
|
+
this.saveCreds = saveCreds;
|
|
214
|
+
this.sock = (0, baileys_1.default)({
|
|
215
|
+
auth: {
|
|
216
|
+
creds: state.creds,
|
|
217
|
+
keys: (0, baileys_1.makeCacheableSignalKeyStore)(state.keys, this.config.logger || this.logger),
|
|
218
|
+
},
|
|
219
|
+
...additionalOptions,
|
|
220
|
+
...this.config,
|
|
221
|
+
});
|
|
222
|
+
this.store.bind(this.sock.ev);
|
|
223
|
+
this.configEvents.configureAll();
|
|
224
|
+
resolve();
|
|
225
|
+
await this.awaitConnectionState('open');
|
|
226
|
+
this.sock.ev.on('creds.update', saveCreds);
|
|
227
|
+
}
|
|
228
|
+
catch (err) {
|
|
229
|
+
this.ev.emit('error', err);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* * Reconecta ao servidor do WhatsApp
|
|
235
|
+
* @returns
|
|
236
|
+
*/
|
|
237
|
+
async reconnect(stopEvents = false, showOpen) {
|
|
238
|
+
if (stopEvents) {
|
|
239
|
+
this.eventsIsStoped = true;
|
|
240
|
+
let state = this.status == BotStatus_1.BotStatus.Online ? 'close' : 'connecting';
|
|
241
|
+
let status = baileys_1.DisconnectReason.connectionClosed;
|
|
242
|
+
let retryCount = 0;
|
|
243
|
+
this.connectionListeners.push((update) => {
|
|
244
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
245
|
+
if (!update.connection)
|
|
246
|
+
return false;
|
|
247
|
+
if (retryCount >= 3) {
|
|
248
|
+
this.eventsIsStoped = false;
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
if (update.connection != state) {
|
|
252
|
+
if (update.connection == 'close') {
|
|
253
|
+
state = 'connecting';
|
|
254
|
+
status =
|
|
255
|
+
((_c = (_b = (_a = update.lastDisconnect) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.output) === null || _c === void 0 ? void 0 : _c.statusCode) ||
|
|
256
|
+
((_d = update.lastDisconnect) === null || _d === void 0 ? void 0 : _d.error) ||
|
|
257
|
+
baileys_1.DisconnectReason.connectionClosed;
|
|
258
|
+
retryCount++;
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
this.eventsIsStoped = false;
|
|
262
|
+
if (state == 'connecting') {
|
|
263
|
+
this.emit('close', { reason: status });
|
|
264
|
+
}
|
|
265
|
+
else if (state == 'open') {
|
|
266
|
+
this.emit('close', { reason: status });
|
|
267
|
+
this.emit('connecting', {});
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
if (state == 'close') {
|
|
273
|
+
state = 'connecting';
|
|
274
|
+
status =
|
|
275
|
+
((_g = (_f = (_e = update.lastDisconnect) === null || _e === void 0 ? void 0 : _e.error) === null || _f === void 0 ? void 0 : _f.output) === null || _g === void 0 ? void 0 : _g.statusCode) ||
|
|
276
|
+
((_h = update.lastDisconnect) === null || _h === void 0 ? void 0 : _h.error) ||
|
|
277
|
+
baileys_1.DisconnectReason.connectionClosed;
|
|
278
|
+
}
|
|
279
|
+
else if (state == 'connecting') {
|
|
280
|
+
state = 'open';
|
|
281
|
+
}
|
|
282
|
+
else if (state == 'open' && showOpen) {
|
|
283
|
+
this.eventsIsStoped = !showOpen;
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
return false;
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
await this.stop();
|
|
290
|
+
this.emit('reconnecting', {});
|
|
291
|
+
await this.internalConnect();
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* * Desliga a conexão com o servidor do WhatsApp
|
|
295
|
+
* @param reason
|
|
296
|
+
* @returns
|
|
297
|
+
*/
|
|
298
|
+
async stop(reason = 402) {
|
|
299
|
+
var _a;
|
|
300
|
+
try {
|
|
301
|
+
this.status = BotStatus_1.BotStatus.Offline;
|
|
302
|
+
(_a = this.sock) === null || _a === void 0 ? void 0 : _a.end(reason);
|
|
303
|
+
}
|
|
304
|
+
catch (err) {
|
|
305
|
+
this.emit('error', err);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
async logout() {
|
|
309
|
+
var _a;
|
|
310
|
+
await ((_a = this.sock) === null || _a === void 0 ? void 0 : _a.logout());
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* * Aguarda um status de conexão
|
|
314
|
+
*/
|
|
315
|
+
async awaitConnectionState(connection) {
|
|
316
|
+
return new Promise((res) => {
|
|
317
|
+
this.connectionListeners.push((update) => {
|
|
318
|
+
if (update.connection != connection)
|
|
319
|
+
return false;
|
|
320
|
+
res(update);
|
|
321
|
+
return true;
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* * Lê o chat
|
|
327
|
+
* @param chat Sala de bate-papo
|
|
328
|
+
*/
|
|
329
|
+
async readChat(chat, metadata, updateMetadata = true) {
|
|
330
|
+
try {
|
|
331
|
+
if (!chat.id || !(chat.id.includes('@s') || chat.id.includes('@g')))
|
|
332
|
+
return;
|
|
333
|
+
chat.type = (0, baileys_1.isJidGroup)(chat.id) ? ChatType_1.default.Group : ChatType_1.default.PV;
|
|
334
|
+
if (chat.type == ChatType_1.default.Group) {
|
|
335
|
+
if (updateMetadata) {
|
|
336
|
+
chat.profileUrl =
|
|
337
|
+
(await this.getChatProfileUrl(new Chat_1.default(chat.id))) || undefined;
|
|
338
|
+
if (!metadata) {
|
|
339
|
+
try {
|
|
340
|
+
metadata = await this.sock.groupMetadata(chat.id);
|
|
341
|
+
}
|
|
342
|
+
catch (_a) { }
|
|
343
|
+
}
|
|
344
|
+
else if (!metadata.participants) {
|
|
345
|
+
try {
|
|
346
|
+
metadata = {
|
|
347
|
+
...metadata,
|
|
348
|
+
...(await this.sock.groupMetadata(chat.id)),
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
catch (_b) { }
|
|
352
|
+
if (metadata.participant) {
|
|
353
|
+
metadata.participants = [
|
|
354
|
+
...(metadata.participants || []),
|
|
355
|
+
...metadata.participant.map((p) => {
|
|
356
|
+
return {
|
|
357
|
+
id: p.userJid,
|
|
358
|
+
isSuperAdmin: p.rank == baileys_1.proto.GroupParticipant.Rank.SUPERADMIN,
|
|
359
|
+
isAdmin: p.rank == baileys_1.proto.GroupParticipant.Rank.ADMIN,
|
|
360
|
+
};
|
|
361
|
+
}),
|
|
362
|
+
];
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
if (metadata === null || metadata === void 0 ? void 0 : metadata.participants) {
|
|
367
|
+
chat.users = [];
|
|
368
|
+
chat.admins = [];
|
|
369
|
+
for (const p of metadata.participants) {
|
|
370
|
+
chat.users.push(p.id);
|
|
371
|
+
if (p.admin == 'admin' || p.isAdmin) {
|
|
372
|
+
chat.admins.push(`${p.id}`);
|
|
373
|
+
}
|
|
374
|
+
else if (p.isSuperAdmin) {
|
|
375
|
+
chat.leader = p.id;
|
|
376
|
+
chat.admins.push(`${p.id}`);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (metadata === null || metadata === void 0 ? void 0 : metadata.subjectOwner) {
|
|
381
|
+
chat.leader = metadata.subjectOwner;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if ((metadata === null || metadata === void 0 ? void 0 : metadata.subject) || (metadata === null || metadata === void 0 ? void 0 : metadata.name)) {
|
|
385
|
+
chat.name = metadata.subject || metadata.name || undefined;
|
|
386
|
+
}
|
|
387
|
+
if ((metadata === null || metadata === void 0 ? void 0 : metadata.desc) || (metadata === null || metadata === void 0 ? void 0 : metadata.description)) {
|
|
388
|
+
chat.description = metadata.desc || metadata.description || undefined;
|
|
389
|
+
}
|
|
390
|
+
if (metadata === null || metadata === void 0 ? void 0 : metadata.unreadCount) {
|
|
391
|
+
chat.unreadCount = metadata.unreadCount || undefined;
|
|
392
|
+
}
|
|
393
|
+
if (metadata === null || metadata === void 0 ? void 0 : metadata.conversationTimestamp) {
|
|
394
|
+
if (long_1.default.isLong(metadata.conversationTimestamp)) {
|
|
395
|
+
chat.timestamp = metadata.conversationTimestamp.toNumber() * 1000;
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
chat.timestamp = Number(metadata.conversationTimestamp) * 1000;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
await this.updateChat({ id: chat.id, ...chat });
|
|
402
|
+
}
|
|
403
|
+
catch (_c) { }
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* * Lê o usuário
|
|
407
|
+
* @param user Usuário
|
|
408
|
+
*/
|
|
409
|
+
async readUser(user, metadata) {
|
|
410
|
+
try {
|
|
411
|
+
if (!user.id || !user.id.includes('@s'))
|
|
412
|
+
return;
|
|
413
|
+
if (metadata === null || metadata === void 0 ? void 0 : metadata.imgUrl) {
|
|
414
|
+
user.profileUrl = await this.getUserProfileUrl(new User_1.default(user.id));
|
|
415
|
+
}
|
|
416
|
+
else {
|
|
417
|
+
const userData = await this.getUser(new User_1.default(user.id || ''));
|
|
418
|
+
if (userData == null || !userData.profileUrl) {
|
|
419
|
+
user.profileUrl = await this.getUserProfileUrl(new User_1.default(user.id));
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
if ((metadata === null || metadata === void 0 ? void 0 : metadata.notify) || (metadata === null || metadata === void 0 ? void 0 : metadata.verifiedName)) {
|
|
423
|
+
user.name = (metadata === null || metadata === void 0 ? void 0 : metadata.notify) || (metadata === null || metadata === void 0 ? void 0 : metadata.verifiedName);
|
|
424
|
+
}
|
|
425
|
+
if (metadata === null || metadata === void 0 ? void 0 : metadata.name) {
|
|
426
|
+
user.savedName = metadata.name;
|
|
427
|
+
}
|
|
428
|
+
user.name = user.name || user.savedName;
|
|
429
|
+
await this.updateUser({ id: user.id || '', ...user });
|
|
430
|
+
}
|
|
431
|
+
catch (err) {
|
|
432
|
+
this.emit('error', err);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Obtem uma mensagem de enquete.
|
|
437
|
+
* @param pollMessageId - ID da mensagem de enquete que será obtida.
|
|
438
|
+
* @returns A mensagem de enquete salva.
|
|
439
|
+
*/
|
|
440
|
+
async getPollMessage(pollMessageId) {
|
|
441
|
+
const pollMessage = await this.auth.get(`polls-${pollMessageId}`);
|
|
442
|
+
if (!pollMessage || !messages_1.PollMessage.isValid(pollMessage))
|
|
443
|
+
return messages_1.PollMessage.fromJSON({ id: pollMessageId });
|
|
444
|
+
if (pollMessage.type == Message_1.MessageType.PollUpdate) {
|
|
445
|
+
return messages_1.PollUpdateMessage.fromJSON(pollMessage);
|
|
446
|
+
}
|
|
447
|
+
return messages_1.PollMessage.fromJSON(pollMessage);
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Salva a mensagem de enquete.
|
|
451
|
+
* @param pollMessage - Mensagem de enquete que será salva.
|
|
452
|
+
*/
|
|
453
|
+
async savePollMessage(pollMessage) {
|
|
454
|
+
await this.auth.set(`polls-${pollMessage.id}`, pollMessage.toJSON());
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* * Trata atualizações de participantes
|
|
458
|
+
* @param action Ação realizada
|
|
459
|
+
* @param chatId Sala de bate-papo que a ação foi realizada
|
|
460
|
+
* @param userId Usuário que foi destinado a ação
|
|
461
|
+
* @param fromId Usuário que realizou a ação
|
|
462
|
+
*/
|
|
463
|
+
async groupParticipantsUpdate(action, chatId, userId, fromId) {
|
|
464
|
+
if (!chatId.includes('@g'))
|
|
465
|
+
return;
|
|
466
|
+
const event = action == 'join' ? 'add' : action == 'leave' ? 'remove' : action;
|
|
467
|
+
let chat = await this.getChat(new Chat_1.default(chatId));
|
|
468
|
+
if (!chat) {
|
|
469
|
+
if (!this.config.autoLoadGroupInfo)
|
|
470
|
+
return;
|
|
471
|
+
chat = Chat_1.default.fromJSON({
|
|
472
|
+
id: chatId,
|
|
473
|
+
phoneNumber: (0, ID_1.getPhoneNumber)(chatId),
|
|
474
|
+
type: ChatType_1.default.Group,
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
const fromUser = (await this.getUser(new User_1.default(fromId))) ||
|
|
478
|
+
User_1.default.fromJSON({ id: fromId, phoneNumber: (0, ID_1.getPhoneNumber)(fromId) });
|
|
479
|
+
const user = (await this.getUser(new User_1.default(userId))) ||
|
|
480
|
+
User_1.default.fromJSON({ id: userId, phoneNumber: (0, ID_1.getPhoneNumber)(userId) });
|
|
481
|
+
let users = chat.users || [];
|
|
482
|
+
const admins = chat.admins || [];
|
|
483
|
+
if (event == 'add')
|
|
484
|
+
users.push(user.id);
|
|
485
|
+
if (event == 'remove')
|
|
486
|
+
users = users.filter((u) => u != user.id);
|
|
487
|
+
if (event == 'demote')
|
|
488
|
+
chat.admins = admins.filter((admin) => admin != user.id);
|
|
489
|
+
if (event == 'promote')
|
|
490
|
+
admins.push(user.id);
|
|
491
|
+
chat.users = users;
|
|
492
|
+
chat.admins = admins;
|
|
493
|
+
if (user.id == this.id) {
|
|
494
|
+
if (event == 'remove')
|
|
495
|
+
await this.removeChat(chat);
|
|
496
|
+
if (event == 'add')
|
|
497
|
+
await this.updateChat(chat);
|
|
498
|
+
}
|
|
499
|
+
else {
|
|
500
|
+
await this.updateChat(chat);
|
|
501
|
+
}
|
|
502
|
+
this.ev.emit('user', { action, event, user, fromUser, chat });
|
|
503
|
+
}
|
|
504
|
+
//! ********************************* CHAT *********************************
|
|
505
|
+
async getChatName(chat) {
|
|
506
|
+
var _a;
|
|
507
|
+
return ((_a = (await this.getChat(chat))) === null || _a === void 0 ? void 0 : _a.name) || '';
|
|
508
|
+
}
|
|
509
|
+
async setChatName(chat, name) {
|
|
510
|
+
if (!(0, baileys_1.isJidGroup)(chat.id))
|
|
511
|
+
return;
|
|
512
|
+
const admins = await this.getChatAdmins(chat);
|
|
513
|
+
if (admins.length && !admins.includes(this.id))
|
|
514
|
+
return;
|
|
515
|
+
await this.sock.groupUpdateSubject(chat.id, name);
|
|
516
|
+
}
|
|
517
|
+
async getChatDescription(chat) {
|
|
518
|
+
var _a;
|
|
519
|
+
return ((_a = (await this.getChat(chat))) === null || _a === void 0 ? void 0 : _a.description) || '';
|
|
520
|
+
}
|
|
521
|
+
async setChatDescription(chat, description) {
|
|
522
|
+
if (!(0, baileys_1.isJidGroup)(chat.id))
|
|
523
|
+
return;
|
|
524
|
+
const admins = await this.getChatAdmins(chat);
|
|
525
|
+
if (admins.length && !admins.includes(this.id))
|
|
526
|
+
return;
|
|
527
|
+
await this.sock.groupUpdateDescription(chat.id, description);
|
|
528
|
+
}
|
|
529
|
+
async getChatProfile(chat, lowQuality) {
|
|
530
|
+
const uri = await this.getChatProfileUrl(chat, lowQuality);
|
|
531
|
+
return await (0, Generic_1.getImageURL)(uri);
|
|
532
|
+
}
|
|
533
|
+
async getChatProfileUrl(chat, lowQuality) {
|
|
534
|
+
try {
|
|
535
|
+
return ((await this.sock.profilePictureUrl(chat.id, lowQuality ? 'preview' : 'image')) || '');
|
|
536
|
+
}
|
|
537
|
+
catch (_a) {
|
|
538
|
+
return '';
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
async setChatProfile(chat, image) {
|
|
542
|
+
if (!(0, baileys_1.isJidGroup)(chat.id))
|
|
543
|
+
return;
|
|
544
|
+
const admins = await this.getChatAdmins(chat);
|
|
545
|
+
if (admins.length && !admins.includes(this.id))
|
|
546
|
+
return;
|
|
547
|
+
await this.sock.updateProfilePicture(chat.id, image);
|
|
548
|
+
}
|
|
549
|
+
async updateChat(chat) {
|
|
550
|
+
const chatData = await this.getChat(new Chat_1.default(chat.id));
|
|
551
|
+
if (chatData != null) {
|
|
552
|
+
chat = Object.keys(chat).reduce((data, key) => {
|
|
553
|
+
if (chat[key] == undefined || chat[key] == null)
|
|
554
|
+
return data;
|
|
555
|
+
if ((0, Generic_1.verifyIsEquals)(chat[key], chatData[key]))
|
|
556
|
+
return data;
|
|
557
|
+
return { ...data, [key]: chat[key] };
|
|
558
|
+
}, { id: chat.id });
|
|
559
|
+
if (Object.keys(chat).length < 2)
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
const newChat = Chat_1.default.fromJSON({ ...(chatData || {}), ...chat });
|
|
563
|
+
newChat.type = (0, baileys_1.isJidGroup)(chat.id) ? ChatType_1.default.Group : ChatType_1.default.PV;
|
|
564
|
+
newChat.phoneNumber = newChat.phoneNumber || (0, ID_1.getPhoneNumber)(chat.id);
|
|
565
|
+
await this.auth.set(`chats-${chat.id}`, newChat.toJSON());
|
|
566
|
+
this.ev.emit('chat', { action: chatData != null ? 'update' : 'add', chat });
|
|
567
|
+
}
|
|
568
|
+
async removeChat(chat) {
|
|
569
|
+
await this.auth.remove(`chats-${chat.id}`);
|
|
570
|
+
this.ev.emit('chat', { action: 'remove', chat });
|
|
571
|
+
}
|
|
572
|
+
async getChat(chat) {
|
|
573
|
+
const chatData = await this.auth.get(`chats-${chat.id}`);
|
|
574
|
+
if (!chatData)
|
|
575
|
+
return null;
|
|
576
|
+
if (!chat.name || !chat.profileUrl) {
|
|
577
|
+
const user = await this.getUser(new User_1.default(chat.id));
|
|
578
|
+
if (user != null) {
|
|
579
|
+
return Chat_1.default.fromJSON({ ...chat, ...user });
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
return Chat_1.default.fromJSON(chatData);
|
|
583
|
+
}
|
|
584
|
+
async getChats() {
|
|
585
|
+
return (await this.auth.listAll('chats-')).map((id) => id.replace('chats-', ''));
|
|
586
|
+
}
|
|
587
|
+
async setChats(chats) {
|
|
588
|
+
await Promise.all(chats.map(async (chat) => await this.updateChat(chat)));
|
|
589
|
+
}
|
|
590
|
+
async getChatUsers(chat) {
|
|
591
|
+
var _a;
|
|
592
|
+
return ((_a = (await this.getChat(chat))) === null || _a === void 0 ? void 0 : _a.users) || [];
|
|
593
|
+
}
|
|
594
|
+
async getChatAdmins(chat) {
|
|
595
|
+
var _a, _b;
|
|
596
|
+
const chatReaded = await this.getChat(chat);
|
|
597
|
+
if (!chatReaded)
|
|
598
|
+
return [];
|
|
599
|
+
if ((_a = chatReaded.admins) === null || _a === void 0 ? void 0 : _a.length) {
|
|
600
|
+
return chatReaded.admins || [];
|
|
601
|
+
}
|
|
602
|
+
if (chatReaded.type !== ChatType_1.default.Group)
|
|
603
|
+
return [];
|
|
604
|
+
await this.readChat(chat);
|
|
605
|
+
return ((_b = (await this.getChat(chat))) === null || _b === void 0 ? void 0 : _b.admins) || [];
|
|
606
|
+
}
|
|
607
|
+
async getChatLeader(chat) {
|
|
608
|
+
var _a;
|
|
609
|
+
return ((_a = (await this.getChat(chat))) === null || _a === void 0 ? void 0 : _a.leader) || '';
|
|
610
|
+
}
|
|
611
|
+
async addUserInChat(chat, user) {
|
|
612
|
+
if (!(0, baileys_1.isJidGroup)(chat.id))
|
|
613
|
+
return;
|
|
614
|
+
const admins = await this.getChatAdmins(chat);
|
|
615
|
+
if (admins.length && !admins.includes(this.id))
|
|
616
|
+
return;
|
|
617
|
+
await this.sock.groupParticipantsUpdate(chat.id, [user.id], 'add');
|
|
618
|
+
}
|
|
619
|
+
async removeUserInChat(chat, user) {
|
|
620
|
+
if (!(0, baileys_1.isJidGroup)(chat.id))
|
|
621
|
+
return;
|
|
622
|
+
const admins = await this.getChatAdmins(chat);
|
|
623
|
+
if (admins.length && !admins.includes(this.id))
|
|
624
|
+
return;
|
|
625
|
+
await this.sock.groupParticipantsUpdate(chat.id, [user.id], 'remove');
|
|
626
|
+
}
|
|
627
|
+
async promoteUserInChat(chat, user) {
|
|
628
|
+
if (!(0, baileys_1.isJidGroup)(chat.id))
|
|
629
|
+
return;
|
|
630
|
+
const admins = await this.getChatAdmins(chat);
|
|
631
|
+
if (admins.length && !admins.includes(this.id))
|
|
632
|
+
return;
|
|
633
|
+
await this.sock.groupParticipantsUpdate(chat.id, [user.id], 'promote');
|
|
634
|
+
}
|
|
635
|
+
async demoteUserInChat(chat, user) {
|
|
636
|
+
if (!(0, baileys_1.isJidGroup)(chat.id))
|
|
637
|
+
return;
|
|
638
|
+
const admins = await this.getChatAdmins(chat);
|
|
639
|
+
if (admins.length && !admins.includes(this.id))
|
|
640
|
+
return;
|
|
641
|
+
await this.sock.groupParticipantsUpdate(chat.id, [user.id], 'demote');
|
|
642
|
+
}
|
|
643
|
+
async changeChatStatus(chat, status) {
|
|
644
|
+
await this.sock.sendPresenceUpdate(WAStatus_1.WAStatus[status] || 'available', chat.id);
|
|
645
|
+
}
|
|
646
|
+
async createChat(chat) {
|
|
647
|
+
await this.sock.groupCreate(chat.name || '', [this.id]);
|
|
648
|
+
}
|
|
649
|
+
async leaveChat(chat) {
|
|
650
|
+
if (!(0, baileys_1.isJidGroup)(chat.id))
|
|
651
|
+
return;
|
|
652
|
+
if ((await this.getChat(chat)) == null)
|
|
653
|
+
return;
|
|
654
|
+
await this.sock.groupLeave(chat.id);
|
|
655
|
+
await this.removeChat(chat);
|
|
656
|
+
}
|
|
657
|
+
async joinChat(code) {
|
|
658
|
+
await this.sock.groupAcceptInvite(code.replace('https://chat.whatsapp.com/', ''));
|
|
659
|
+
}
|
|
660
|
+
async getChatInvite(chat) {
|
|
661
|
+
if (!(0, baileys_1.isJidGroup)(chat.id))
|
|
662
|
+
return '';
|
|
663
|
+
// TODO: Return undefined if user is not admin
|
|
664
|
+
const admins = await this.getChatAdmins(chat);
|
|
665
|
+
if (admins.length && !admins.includes(this.id))
|
|
666
|
+
return '';
|
|
667
|
+
return (await this.sock.groupInviteCode(chat.id)) || '';
|
|
668
|
+
}
|
|
669
|
+
async revokeChatInvite(chat) {
|
|
670
|
+
if (!(0, baileys_1.isJidGroup)(chat.id))
|
|
671
|
+
return '';
|
|
672
|
+
const admins = await this.getChatAdmins(chat);
|
|
673
|
+
if (admins.length && !admins.includes(this.id))
|
|
674
|
+
return '';
|
|
675
|
+
return (await this.sock.groupRevokeInvite(chat.id)) || '';
|
|
676
|
+
}
|
|
677
|
+
async rejectCall(call) {
|
|
678
|
+
await this.sock.rejectCall(call.id, call.chat.id);
|
|
679
|
+
}
|
|
680
|
+
async getUserName(user) {
|
|
681
|
+
var _a;
|
|
682
|
+
return ((_a = (await this.getUser(user))) === null || _a === void 0 ? void 0 : _a.name) || '';
|
|
683
|
+
}
|
|
684
|
+
async setUserName(user, name) {
|
|
685
|
+
if (user.id != this.id)
|
|
686
|
+
return;
|
|
687
|
+
await this.setBotName(name);
|
|
688
|
+
}
|
|
689
|
+
async getUserDescription(user) {
|
|
690
|
+
// O método fetchStatus não existe na API pública do Baileys
|
|
691
|
+
// return (await this.sock.fetchStatus(String(user.id)))[0]?.status || '';
|
|
692
|
+
throw new Error('getUserDescription não implementado: fetchStatus não disponível na API do Baileys');
|
|
693
|
+
}
|
|
694
|
+
async setUserDescription(user, description) {
|
|
695
|
+
if (user.id != this.id)
|
|
696
|
+
return;
|
|
697
|
+
await this.setBotDescription(description);
|
|
698
|
+
}
|
|
699
|
+
async getUserProfile(user, lowQuality) {
|
|
700
|
+
const uri = await this.getUserProfileUrl(user, lowQuality);
|
|
701
|
+
return await (0, Generic_1.getImageURL)(uri);
|
|
702
|
+
}
|
|
703
|
+
async getUserProfileUrl(user, lowQuality) {
|
|
704
|
+
try {
|
|
705
|
+
return ((await this.sock.profilePictureUrl(user.id, lowQuality ? 'preview' : 'image')) || '');
|
|
706
|
+
}
|
|
707
|
+
catch (_a) {
|
|
708
|
+
return '';
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
async setUserProfile(user, image) {
|
|
712
|
+
if (user.id != this.id)
|
|
713
|
+
return;
|
|
714
|
+
await this.setBotProfile(image);
|
|
715
|
+
}
|
|
716
|
+
async getUser(user) {
|
|
717
|
+
const userData = await this.auth.get(`users-${user.id}`);
|
|
718
|
+
if (!userData)
|
|
719
|
+
return null;
|
|
720
|
+
return User_1.default.fromJSON(userData);
|
|
721
|
+
}
|
|
722
|
+
async getUsers() {
|
|
723
|
+
return (await this.auth.listAll('users-')).map((id) => id.replace('users-', ''));
|
|
724
|
+
}
|
|
725
|
+
async updateUser(user) {
|
|
726
|
+
const userData = await this.getUser(new User_1.default(user.id));
|
|
727
|
+
if (userData != null) {
|
|
728
|
+
user = Object.keys(user).reduce((data, key) => {
|
|
729
|
+
if (user[key] == undefined || user[key] == null)
|
|
730
|
+
return data;
|
|
731
|
+
if ((0, Generic_1.verifyIsEquals)(user[key], userData[key]))
|
|
732
|
+
return data;
|
|
733
|
+
return { ...data, [key]: user[key] };
|
|
734
|
+
}, { id: user.id });
|
|
735
|
+
if (Object.keys(user).length < 2)
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
const newUser = User_1.default.fromJSON({ ...(userData || {}), ...user });
|
|
739
|
+
newUser.phoneNumber = newUser.phoneNumber || (0, ID_1.getPhoneNumber)(user.id);
|
|
740
|
+
await this.auth.set(`users-${user.id}`, newUser.toJSON());
|
|
741
|
+
}
|
|
742
|
+
async setUsers(users) {
|
|
743
|
+
await Promise.all(users.map(async (user) => await this.updateUser(user)));
|
|
744
|
+
}
|
|
745
|
+
async removeUser(user) {
|
|
746
|
+
await this.auth.remove(`users-${user.id}`);
|
|
747
|
+
}
|
|
748
|
+
async blockUser(user) {
|
|
749
|
+
if (user.id == this.id)
|
|
750
|
+
return;
|
|
751
|
+
await this.sock.updateBlockStatus(user.id, 'block');
|
|
752
|
+
}
|
|
753
|
+
async unblockUser(user) {
|
|
754
|
+
if (user.id == this.id)
|
|
755
|
+
return;
|
|
756
|
+
await this.sock.updateBlockStatus(user.id, 'unblock');
|
|
757
|
+
}
|
|
758
|
+
//! ******************************** BOT ********************************
|
|
759
|
+
async getBotName() {
|
|
760
|
+
return await this.getUserName(new User_1.default(this.id));
|
|
761
|
+
}
|
|
762
|
+
async setBotName(name) {
|
|
763
|
+
await this.sock.updateProfileName(name);
|
|
764
|
+
}
|
|
765
|
+
async getBotDescription() {
|
|
766
|
+
return await this.getUserDescription(new User_1.default(this.id));
|
|
767
|
+
}
|
|
768
|
+
async setBotDescription(description) {
|
|
769
|
+
await this.sock.updateProfileStatus(description);
|
|
770
|
+
}
|
|
771
|
+
async getBotProfile(lowQuality) {
|
|
772
|
+
return await this.getUserProfile(new User_1.default(this.id), lowQuality);
|
|
773
|
+
}
|
|
774
|
+
async getBotProfileUrl(lowQuality) {
|
|
775
|
+
return (await this.getUserProfileUrl(new User_1.default(this.id), lowQuality)) || '';
|
|
776
|
+
}
|
|
777
|
+
async setBotProfile(image) {
|
|
778
|
+
await this.sock.updateProfilePicture(this.id, image);
|
|
779
|
+
}
|
|
780
|
+
//! ******************************* MESSAGE *******************************
|
|
781
|
+
async readMessage(message) {
|
|
782
|
+
const key = {
|
|
783
|
+
remoteJid: message.chat.id,
|
|
784
|
+
id: message.id || '',
|
|
785
|
+
fromMe: message.fromMe || message.user.id == this.id,
|
|
786
|
+
participant: (0, baileys_1.isJidGroup)(message.chat.id)
|
|
787
|
+
? message.user.id || this.id || undefined
|
|
788
|
+
: undefined,
|
|
789
|
+
toJSON: () => key,
|
|
790
|
+
};
|
|
791
|
+
const chat = await this.getChat(message.chat);
|
|
792
|
+
if ((chat === null || chat === void 0 ? void 0 : chat.type) == ChatType_1.default.Group) {
|
|
793
|
+
await this.sock.readMessages([key]);
|
|
794
|
+
}
|
|
795
|
+
else {
|
|
796
|
+
await this.sock.readMessages([key]);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
// Adiciona um método utilitário para cache de mensagens
|
|
800
|
+
addMessageCache(id) {
|
|
801
|
+
if (!this.messagesCached.includes(id)) {
|
|
802
|
+
this.messagesCached.push(id);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
// ================= APP STATE UPDATES =================
|
|
806
|
+
/** Arquiva ou desarquiva um chat */
|
|
807
|
+
async archiveChat(chat, archive = true, lastMessages) {
|
|
808
|
+
const chatId = typeof chat === 'string' ? chat : chat.id;
|
|
809
|
+
await this.sock.chatModify({ archive, lastMessages }, chatId);
|
|
810
|
+
}
|
|
811
|
+
/** Silencia ou dessilencia um chat */
|
|
812
|
+
async muteChat(chat, mute, lastMessages) {
|
|
813
|
+
const chatId = typeof chat === 'string' ? chat : chat.id;
|
|
814
|
+
await this.sock.chatModify({ mute, lastMessages }, chatId);
|
|
815
|
+
}
|
|
816
|
+
/** Marca um chat como lido */
|
|
817
|
+
async markChatRead(chat, read = true, lastMessages) {
|
|
818
|
+
const chatId = typeof chat === 'string' ? chat : chat.id;
|
|
819
|
+
await this.sock.chatModify({ markRead: read, lastMessages }, chatId);
|
|
820
|
+
}
|
|
821
|
+
/** Define o modo de mensagens temporárias em um chat */
|
|
822
|
+
async setDisappearingMessages(chat, duration) {
|
|
823
|
+
const chatId = typeof chat === 'string' ? chat : chat.id;
|
|
824
|
+
await this.sock.sendMessage(chatId, { disappearingMessagesInChat: duration });
|
|
825
|
+
}
|
|
826
|
+
// ================= BUSINESS FEATURES =================
|
|
827
|
+
/** Busca o perfil de negócio de um contato */
|
|
828
|
+
async fetchBusinessProfile(jid) {
|
|
829
|
+
return await this.sock.getBusinessProfile(jid);
|
|
830
|
+
}
|
|
831
|
+
// O método fetchBusinessProducts foi removido pois não existe na API pública do Baileys.
|
|
832
|
+
// Se precisar de recursos de catálogo, utilize a API oficial do WhatsApp Business.
|
|
833
|
+
// ================= PRIVACIDADE =================
|
|
834
|
+
async fetchBlocklist() {
|
|
835
|
+
return await this.sock.fetchBlocklist();
|
|
836
|
+
}
|
|
837
|
+
async fetchPrivacySettings(force = false) {
|
|
838
|
+
return await this.sock.fetchPrivacySettings(force);
|
|
839
|
+
}
|
|
840
|
+
async updateOnlinePrivacy(option) {
|
|
841
|
+
await this.sock.updateOnlinePrivacy(option);
|
|
842
|
+
}
|
|
843
|
+
async updateLastSeenPrivacy(option) {
|
|
844
|
+
await this.sock.updateLastSeenPrivacy(option);
|
|
845
|
+
}
|
|
846
|
+
async updateProfilePicturePrivacy(option) {
|
|
847
|
+
await this.sock.updateProfilePicturePrivacy(option);
|
|
848
|
+
}
|
|
849
|
+
async updateStatusPrivacy(option) {
|
|
850
|
+
await this.sock.updateStatusPrivacy(option);
|
|
851
|
+
}
|
|
852
|
+
async updateGroupsAddPrivacy(option) {
|
|
853
|
+
await this.sock.updateGroupsAddPrivacy(option);
|
|
854
|
+
}
|
|
855
|
+
async updateReadReceiptsPrivacy(option) {
|
|
856
|
+
await this.sock.updateReadReceiptsPrivacy(option);
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* Adiciona uma reação a uma mensagem
|
|
860
|
+
*/
|
|
861
|
+
async addReaction(message) {
|
|
862
|
+
var _a;
|
|
863
|
+
if (!message.id || !((_a = message.chat) === null || _a === void 0 ? void 0 : _a.id) || !message.reaction)
|
|
864
|
+
return;
|
|
865
|
+
await this.sock.sendMessage(message.chat.id, {
|
|
866
|
+
react: {
|
|
867
|
+
text: message.reaction,
|
|
868
|
+
key: {
|
|
869
|
+
id: message.id,
|
|
870
|
+
remoteJid: message.chat.id,
|
|
871
|
+
fromMe: message.fromMe || message.user.id === this.id,
|
|
872
|
+
participant: (0, baileys_1.isJidGroup)(message.chat.id)
|
|
873
|
+
? message.user.id || this.id || undefined
|
|
874
|
+
: undefined,
|
|
875
|
+
},
|
|
876
|
+
},
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
/** Remove uma reação de uma mensagem */
|
|
880
|
+
async removeReaction(message) {
|
|
881
|
+
var _a;
|
|
882
|
+
if (!message.id || !((_a = message.chat) === null || _a === void 0 ? void 0 : _a.id))
|
|
883
|
+
return;
|
|
884
|
+
await this.sock.sendMessage(message.chat.id, {
|
|
885
|
+
react: {
|
|
886
|
+
text: '',
|
|
887
|
+
key: {
|
|
888
|
+
id: message.id,
|
|
889
|
+
remoteJid: message.chat.id,
|
|
890
|
+
fromMe: message.fromMe || message.user.id === this.id,
|
|
891
|
+
participant: (0, baileys_1.isJidGroup)(message.chat.id)
|
|
892
|
+
? message.user.id || this.id || undefined
|
|
893
|
+
: undefined,
|
|
894
|
+
},
|
|
895
|
+
},
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
/** Edita o texto de uma mensagem enviada */
|
|
899
|
+
async editMessage(message) {
|
|
900
|
+
var _a;
|
|
901
|
+
if (!message.id || !((_a = message.chat) === null || _a === void 0 ? void 0 : _a.id))
|
|
902
|
+
return;
|
|
903
|
+
await this.sock.sendMessage(message.chat.id, {
|
|
904
|
+
edit: {
|
|
905
|
+
remoteJid: message.chat.id,
|
|
906
|
+
id: message.id,
|
|
907
|
+
fromMe: message.fromMe || message.user.id === this.id,
|
|
908
|
+
participant: (0, baileys_1.isJidGroup)(message.chat.id)
|
|
909
|
+
? message.user.id || this.id || undefined
|
|
910
|
+
: undefined,
|
|
911
|
+
},
|
|
912
|
+
text: message.text,
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
/** Envia uma mensagem */
|
|
916
|
+
async send(message) {
|
|
917
|
+
var _a;
|
|
918
|
+
try {
|
|
919
|
+
const waMsg = (await new ConvertToWAMessage_1.default(this, message).refactory()).waMessage;
|
|
920
|
+
const sent = await this.sock.sendMessage(message.chat.id, waMsg);
|
|
921
|
+
if (sent && sent.key && sent.key.id)
|
|
922
|
+
message.id = sent.key.id;
|
|
923
|
+
return message;
|
|
924
|
+
}
|
|
925
|
+
catch (error) {
|
|
926
|
+
// Log detalhado para diagnóstico
|
|
927
|
+
console.error('[WhatsAppBot.send] Erro ao enviar mensagem', {
|
|
928
|
+
chatId: (_a = message === null || message === void 0 ? void 0 : message.chat) === null || _a === void 0 ? void 0 : _a.id,
|
|
929
|
+
messageObj: message,
|
|
930
|
+
error
|
|
931
|
+
});
|
|
932
|
+
throw error;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
/** Remove uma mensagem (marca como removida para todos) */
|
|
936
|
+
async removeMessage(message) {
|
|
937
|
+
var _a;
|
|
938
|
+
if (!message.id || !((_a = message.chat) === null || _a === void 0 ? void 0 : _a.id))
|
|
939
|
+
return;
|
|
940
|
+
await this.sock.sendMessage(message.chat.id, {
|
|
941
|
+
delete: {
|
|
942
|
+
remoteJid: message.chat.id,
|
|
943
|
+
id: message.id,
|
|
944
|
+
fromMe: message.fromMe || message.user.id === this.id,
|
|
945
|
+
participant: (0, baileys_1.isJidGroup)(message.chat.id)
|
|
946
|
+
? message.user.id || this.id || undefined
|
|
947
|
+
: undefined,
|
|
948
|
+
},
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
/** Deleta uma mensagem (remove do histórico) */
|
|
952
|
+
async deleteMessage(message) {
|
|
953
|
+
var _a;
|
|
954
|
+
if (!message.id || !((_a = message.chat) === null || _a === void 0 ? void 0 : _a.id))
|
|
955
|
+
return;
|
|
956
|
+
await this.sock.sendMessage(message.chat.id, {
|
|
957
|
+
delete: {
|
|
958
|
+
remoteJid: message.chat.id,
|
|
959
|
+
id: message.id,
|
|
960
|
+
fromMe: message.fromMe || message.user.id === this.id,
|
|
961
|
+
participant: (0, baileys_1.isJidGroup)(message.chat.id)
|
|
962
|
+
? message.user.id || this.id || undefined
|
|
963
|
+
: undefined,
|
|
964
|
+
},
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
/** Baixa a stream de mídia de uma mensagem */
|
|
968
|
+
async downloadStreamMessage(media) {
|
|
969
|
+
// media é um MediaMessage, que herda de Message
|
|
970
|
+
const msg = await this.store.loadMessage(media.chat.id, media.id);
|
|
971
|
+
if (!msg)
|
|
972
|
+
return Buffer.from("");
|
|
973
|
+
// downloadMediaMessage espera (msg, type, options?)
|
|
974
|
+
return Buffer.from(await (0, baileys_1.downloadMediaMessage)(msg, "buffer", {
|
|
975
|
+
// opções extras se necessário
|
|
976
|
+
}));
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
exports.default = WhatsAppBot;
|
|
980
|
+
//# sourceMappingURL=WhatsAppBot.js.map
|