This commit is contained in:
mike
2025-12-12 09:12:03 +01:00
parent 08908d80d5
commit 92f145e6b3
12 changed files with 1638 additions and 71 deletions

4
.aiignore Normal file
View File

@@ -0,0 +1,4 @@
node_modules
.idea
.git
package-lock.json

View File

@@ -26,6 +26,7 @@ RUN npm run postinstall || true
# Copy application files
COPY server.js ./
COPY swagger.yml ./
# ==================== RUNTIME STAGE ====================
FROM node:20-alpine
@@ -55,6 +56,7 @@ COPY --from=builder --chown=whatsapp:whatsapp /app/node_modules ./node_modules
# Copy application files
COPY --chown=whatsapp:whatsapp server.js ./
COPY --chown=whatsapp:whatsapp package*.json ./
COPY --chown=whatsapp:whatsapp swagger.yml ./
# Create volume directories
RUN mkdir -p /app/data /app/media /app/.wwebjs_cache /app/.wwebjs_auth && \

View File

@@ -2,7 +2,7 @@ services:
wapp:
#user: "1000:1000"
build:
#context: /opt/apps/wapp
#context: /opt/00apps/wapp
context: .
dockerfile: Dockerfile
ports:

View File

@@ -2,7 +2,7 @@ services:
wapp:
user: "1000:1000"
build:
context: /opt/apps/wapp
context: ${WAPP_APP_ROOT}
dockerfile: Dockerfile
ports:
- "3001:3001"
@@ -10,6 +10,7 @@ services:
restart: unless-stopped
networks:
- traefik_net
- default
environment:
# Server configuration
- PORT=3001
@@ -61,6 +62,8 @@ networks:
traefik_net:
external: true
name: traefik_net
default:
driver: bridge
volumes:
whatsapp-data:

86
fix_path.sh Executable file
View File

@@ -0,0 +1,86 @@
#!/usr/bin/env bash
set -e
echo "=== Cleaning node_modules ==="
rm -rf node_modules
echo "OK"
echo "=== Installing dependencies (ignoring scripts) ==="
npm install --ignore-scripts
echo "OK"
echo "=== Locating Injected Store.js ==="
TARGET=$(find node_modules/whatsapp-web.js/src/util/Injected -type f -name "Store.js" | head -n 1)
if [ -z "$TARGET" ]; then
echo "ERROR: Cannot find Store.js under Injected/"
exit 1
fi
echo "Found Injected file:"
echo " $TARGET"
echo "=== Backing up original ==="
cp "$TARGET" "$TARGET.bak"
echo "=== Applying getContactModel patch ==="
# Patch de getContactModel functie
sed -i '/getContactModel:/,/return {/c\
getContactModel: (contact) => {\n\
return {\n\
id: contact.id,\n\
name: contact.name,\n\
type: contact.type,\n\
\n\
isMe: contact.isMe || false,\n\
isUser: contact.isUser || false,\n\
isGroup: contact.isGroup || false,\n\
isBroadcast: contact.isBroadcast || false,\n\
isBusiness: contact.isBusiness || false,\n\
isEnterprise: contact.isEnterprise || false,\n\
\n\
isContactSyncEnabled: contact.isContactSyncEnabled || false,\n\
isContactLocked: contact.isContactLocked || false,\n\
\n\
verifiedLevel: contact.verifiedLevel,\n\
verifiedName: contact.verifiedName,\n\
pushname: contact.pushname,\n\
\n\
isWAContact: contact.isWAContact || false,\n\
\n\
isMyContact: (\n\
contact.isMyContact !== undefined\n\
? contact.isMyContact\n\
: contact.type === \"in\" || false\n\
),\n\
\n\
isBlocked: contact.isBlocked || false,\n\
\n\
labels: Array.isArray(contact.labels)\n\
? contact.labels.map(l => l.id)\n\
: [],\n\
\n\
displayName: contact.displayName || contact.pushname || contact.name,\n\
formattedName: contact.formattedName || contact.name,\n\
formattedShortName: contact.formattedShortName || contact.name,\n\
shortName: contact.shortName || contact.name,\n\
isSaved: contact.isSaved !== undefined ? contact.isSaved : false,\n\
\n\
isMuted: contact.muteExpiration !== undefined\n\
? contact.muteExpiration > 0\n\
: false,\n\
\n\
muteExpiration: contact.muteExpiration || 0,\n\
disappearingModeDuration: contact.disappearingModeDuration || 0,\n\
};\n\
},' "$TARGET"
echo "=== Generating patch-package diff ==="
npx patch-package whatsapp-web.js
echo "OK"
echo "=== Final npm install ==="
npm install
echo "SUCCESS — Patch applied, new diff created 🚀"

1173
output.md Normal file

File diff suppressed because it is too large Load Diff

62
package-lock.json generated
View File

@@ -1,11 +1,11 @@
{
"name": "whatsapp-web-server",
"name": "wapp",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "whatsapp-web-server",
"name": "wapp",
"version": "1.0.0",
"hasInstallScript": true,
"dependencies": {
@@ -16,7 +16,9 @@
"sequelize": "^6.32.1",
"socket.io": "^4.7.2",
"sqlite3": "^5.1.6",
"whatsapp-web.js": "github:pedroslopez/whatsapp-web.js"
"swagger-ui-express": "^5.0.0",
"whatsapp-web.js": "github:pedroslopez/whatsapp-web.js",
"yamljs": "^0.3.0"
},
"devDependencies": {
"nodemon": "^3.0.1",
@@ -76,6 +78,12 @@
"integrity": "sha512-wtnBAETBVYZ9GvcbgdswRVSLkFkYAGv1KzwBBTeRXvGT9sb9cPllOgFFWXCn9PyARQ0H+Ijz6mmoRrGateUDxQ==",
"license": "MIT"
},
"node_modules/@scarf/scarf": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/@scarf/scarf/-/scarf-1.4.0.tgz",
"integrity": "sha512-xxeapPiUXdZAE3che6f3xogoJPeZgig6omHEy1rIY5WVsB3H2BHNnZH+gHG6x91SCWyQCzWGsuL2Hh3ClO5/qQ==",
"hasInstallScript": true
},
"node_modules/@socket.io/component-emitter": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.2.tgz",
@@ -348,6 +356,14 @@
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
}
},
"node_modules/argparse": {
"version": "1.0.10",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
"integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",
"dependencies": {
"sprintf-js": "~1.0.2"
}
},
"node_modules/array-flatten": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
@@ -4023,6 +4039,11 @@
"node": ">= 10"
}
},
"node_modules/sprintf-js": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
"integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g=="
},
"node_modules/sqlite3": {
"version": "5.1.7",
"resolved": "https://registry.npmjs.org/sqlite3/-/sqlite3-5.1.7.tgz",
@@ -4126,6 +4147,28 @@
"node": ">=4"
}
},
"node_modules/swagger-ui-dist": {
"version": "5.31.0",
"resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-5.31.0.tgz",
"integrity": "sha512-zSUTIck02fSga6rc0RZP3b7J7wgHXwLea8ZjgLA3Vgnb8QeOl3Wou2/j5QkzSGeoz6HusP/coYuJl33aQxQZpg==",
"dependencies": {
"@scarf/scarf": "=1.4.0"
}
},
"node_modules/swagger-ui-express": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/swagger-ui-express/-/swagger-ui-express-5.0.1.tgz",
"integrity": "sha512-SrNU3RiBGTLLmFU8GIJdOdanJTl4TOmT27tt3bWWHppqYmAZ6IDuEuBvMU6nZq0zLEe6b/1rACXCgLZqO6ZfrA==",
"dependencies": {
"swagger-ui-dist": ">=5.0.0"
},
"engines": {
"node": ">= v0.10.32"
},
"peerDependencies": {
"express": ">=4.0.0 || >=5.0.0-beta"
}
},
"node_modules/tar": {
"version": "6.2.1",
"resolved": "https://registry.npmjs.org/tar/-/tar-6.2.1.tgz",
@@ -4606,6 +4649,19 @@
"url": "https://github.com/sponsors/eemeli"
}
},
"node_modules/yamljs": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/yamljs/-/yamljs-0.3.0.tgz",
"integrity": "sha512-C/FsVVhht4iPQYXOInoxUM/1ELSf9EsgKH34FofQOp6hwCPrW4vG4w5++TED3xRUo8gD7l0P1J1dLlDYzODsTQ==",
"dependencies": {
"argparse": "^1.0.7",
"glob": "^7.0.5"
},
"bin": {
"json2yaml": "bin/json2yaml",
"yaml2json": "bin/yaml2json"
}
},
"node_modules/yargs": {
"version": "15.4.1",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz",

View File

@@ -16,7 +16,9 @@
"sequelize": "^6.32.1",
"socket.io": "^4.7.2",
"sqlite3": "^5.1.6",
"whatsapp-web.js": "github:pedroslopez/whatsapp-web.js"
"whatsapp-web.js": "github:pedroslopez/whatsapp-web.js",
"swagger-ui-express": "^5.0.0",
"yamljs": "^0.3.0"
},
"devDependencies": {
"nodemon": "^3.0.1",

View File

@@ -1,65 +0,0 @@
diff --git a/node_modules/whatsapp-web.js/src/util/Injected.js b/node_modules/whatsapp-web.js/src/util/Injected.js
index xxxxxxx..yyyyyyy 100644
--- a/node_modules/whatsapp-web.js/src/util/Injected.js
+++ b/node_modules/whatsapp-web.js/src/util/Injected.js
@@ -628,16 +628,28 @@ exports.ExposeStore = () => {
return Object.defineProperty(window, 'WWebJS', {
get() {
return {
getContactModel: (contact) => {
+ // Safe method extraction with fallbacks
+ const getContactMethod = (method) => {
+ if (!window.Store.ContactMethods || !window.Store.ContactMethods[method]) {
+ return null;
+ }
+ return window.Store.ContactMethods[method];
+ };
+
return {
id: contact.id,
name: contact.name,
type: contact.type,
- isMe: contact.isMe,
- isUser: contact.isUser,
- isGroup: contact.isGroup,
- isBroadcast: contact.isBroadcast,
- isBusiness: contact.isBusiness,
- isEnterprise: contact.isEnterprise,
+ isMe: contact.isMe || false,
+ isUser: contact.isUser || false,
+ isGroup: contact.isGroup || false,
+ isBroadcast: contact.isBroadcast || false,
+ isBusiness: contact.isBusiness || false,
+ isEnterprise: contact.isEnterprise || false,
+ isContactSyncEnabled: contact.isContactSyncEnabled || false,
+ isContactLocked: contact.isContactLocked || false,
verifiedLevel: contact.verifiedLevel,
verifiedName: contact.verifiedName,
pushname: contact.pushname,
@@ -646,11 +658,23 @@ exports.ExposeStore = () => {
isMe: contact.isMe,
isUser: contact.isUser,
isWAContact: contact.isWAContact,
- isMyContact: contact.isMyContact,
+ // Fallback for changed API
+ isMyContact: contact.isMyContact !== undefined
+ ? contact.isMyContact
+ : contact.type === 'in' || false,
isBlocked: contact.isBlocked,
- labels: contact.labels ? contact.labels.map(l => l.id) : []
+ labels: contact.labels ? contact.labels.map(l => l.id) : [],
+ // Additional properties
+ displayName: contact.displayName || contact.pushname || contact.name,
+ formattedName: contact.formattedName || contact.name,
+ formattedShortName: contact.formattedShortName || contact.name,
+ shortName: contact.shortName || contact.name,
+ isSaved: contact.isSaved !== undefined ? contact.isSaved : false,
+ isMuted: contact.muteExpiration !== undefined ? contact.muteExpiration > 0 : false,
+ muteExpiration: contact.muteExpiration || 0,
+ disappearingModeDuration: contact.disappearingModeDuration || 0
};
},
});
}
});
}

View File

@@ -0,0 +1,263 @@
diff --git a/node_modules/whatsapp-web.js/src/util/Injected/Store.js.bak b/node_modules/whatsapp-web.js/src/util/Injected/Store.js.bak
new file mode 100644
index 0000000..08fe745
--- /dev/null
+++ b/node_modules/whatsapp-web.js/src/util/Injected/Store.js.bak
@@ -0,0 +1,257 @@
+'use strict';
+
+exports.ExposeStore = () => {
+ /**
+ * Helper function that compares between two WWeb versions. Its purpose is to help the developer to choose the correct code implementation depending on the comparison value and the WWeb version.
+ * @param {string} lOperand The left operand for the WWeb version string to compare with
+ * @param {string} operator The comparison operator
+ * @param {string} rOperand The right operand for the WWeb version string to compare with
+ * @returns {boolean} Boolean value that indicates the result of the comparison
+ */
+ window.compareWwebVersions = (lOperand, operator, rOperand) => {
+ if (!['>', '>=', '<', '<=', '='].includes(operator)) {
+ throw new class _ extends Error {
+ constructor(m) { super(m); this.name = 'CompareWwebVersionsError'; }
+ }('Invalid comparison operator is provided');
+
+ }
+ if (typeof lOperand !== 'string' || typeof rOperand !== 'string') {
+ throw new class _ extends Error {
+ constructor(m) { super(m); this.name = 'CompareWwebVersionsError'; }
+ }('A non-string WWeb version type is provided');
+ }
+
+ lOperand = lOperand.replace(/-beta$/, '');
+ rOperand = rOperand.replace(/-beta$/, '');
+
+ while (lOperand.length !== rOperand.length) {
+ lOperand.length > rOperand.length
+ ? rOperand = rOperand.concat('0')
+ : lOperand = lOperand.concat('0');
+ }
+
+ lOperand = Number(lOperand.replace(/\./g, ''));
+ rOperand = Number(rOperand.replace(/\./g, ''));
+
+ return (
+ operator === '>' ? lOperand > rOperand :
+ operator === '>=' ? lOperand >= rOperand :
+ operator === '<' ? lOperand < rOperand :
+ operator === '<=' ? lOperand <= rOperand :
+ operator === '=' ? lOperand === rOperand :
+ false
+ );
+ };
+
+ window.Store = Object.assign({}, window.require('WAWebCollections'));
+ window.Store.AppState = window.require('WAWebSocketModel').Socket;
+ window.Store.BlockContact = window.require('WAWebBlockContactAction');
+ window.Store.Conn = window.require('WAWebConnModel').Conn;
+ window.Store.Cmd = window.require('WAWebCmd').Cmd;
+ window.Store.DownloadManager = window.require('WAWebDownloadManager').downloadManager;
+ window.Store.GroupQueryAndUpdate = window.require('WAWebGroupQueryJob').queryAndUpdateGroupMetadataById;
+ window.Store.MediaPrep = window.require('WAWebPrepRawMedia');
+ window.Store.MediaObject = window.require('WAWebMediaStorage');
+ window.Store.MediaTypes = window.require('WAWebMmsMediaTypes');
+ window.Store.MediaUpload = window.require('WAWebMediaMmsV4Upload');
+ window.Store.MsgKey = window.require('WAWebMsgKey');
+ window.Store.OpaqueData = window.require('WAWebMediaOpaqueData');
+ window.Store.QueryProduct = window.require('WAWebBizProductCatalogBridge');
+ window.Store.QueryOrder = window.require('WAWebBizOrderBridge');
+ window.Store.SendClear = window.require('WAWebChatClearBridge');
+ window.Store.SendDelete = window.require('WAWebDeleteChatAction');
+ window.Store.SendMessage = window.require('WAWebSendMsgChatAction');
+ window.Store.EditMessage = window.require('WAWebSendMessageEditAction');
+ window.Store.MediaDataUtils = window.require('WAWebMediaDataUtils');
+ window.Store.BlobCache = window.require('WAWebMediaInMemoryBlobCache');
+ window.Store.SendSeen = window.require('WAWebUpdateUnreadChatAction');
+ window.Store.User = window.require('WAWebUserPrefsMeUser');
+ window.Store.ContactMethods = {
+ ...window.require('WAWebContactGetters'),
+ ...window.require('WAWebFrontendContactGetters')
+ };
+ window.Store.UserConstructor = window.require('WAWebWid');
+ window.Store.Validators = window.require('WALinkify');
+ window.Store.WidFactory = window.require('WAWebWidFactory');
+ window.Store.ProfilePic = window.require('WAWebContactProfilePicThumbBridge');
+ window.Store.PresenceUtils = window.require('WAWebPresenceChatAction');
+ window.Store.ChatState = window.require('WAWebChatStateBridge');
+ window.Store.findCommonGroups = window.require('WAWebFindCommonGroupsContactAction').findCommonGroups;
+ window.Store.StatusUtils = window.require('WAWebContactStatusBridge');
+ window.Store.ConversationMsgs = window.require('WAWebChatLoadMessages');
+ window.Store.sendReactionToMsg = window.require('WAWebSendReactionMsgAction').sendReactionToMsg;
+ window.Store.createOrUpdateReactionsModule = window.require('WAWebDBCreateOrUpdateReactions');
+ window.Store.EphemeralFields = window.require('WAWebGetEphemeralFieldsMsgActionsUtils');
+ window.Store.MsgActionChecks = window.require('WAWebMsgActionCapability');
+ window.Store.QuotedMsg = window.require('WAWebQuotedMsgModelUtils');
+ window.Store.LinkPreview = window.require('WAWebLinkPreviewChatAction');
+ window.Store.Socket = window.require('WADeprecatedSendIq');
+ window.Store.SocketWap = window.require('WAWap');
+ window.Store.SearchContext = window.require('WAWebChatMessageSearch');
+ window.Store.DrawerManager = window.require('WAWebDrawerManager').DrawerManager;
+ window.Store.LidUtils = window.require('WAWebApiContact');
+ window.Store.WidToJid = window.require('WAWebWidToJid');
+ window.Store.JidToWid = window.require('WAWebJidToWid');
+ window.Store.getMsgInfo = window.require('WAWebApiMessageInfoStore').queryMsgInfo;
+ window.Store.QueryExist = window.require('WAWebQueryExistsJob').queryWidExists;
+ window.Store.ReplyUtils = window.require('WAWebMsgReply');
+ window.Store.BotSecret = window.require('WAWebBotMessageSecret');
+ window.Store.BotProfiles = window.require('WAWebBotProfileCollection');
+ window.Store.ContactCollection = window.require('WAWebContactCollection').ContactCollection;
+ window.Store.DeviceList = window.require('WAWebApiDeviceList');
+ window.Store.HistorySync = window.require('WAWebSendNonMessageDataRequest');
+ window.Store.AddonReactionTable = window.require('WAWebAddonReactionTableMode').reactionTableMode;
+ window.Store.AddonPollVoteTable = window.require('WAWebAddonPollVoteTableMode').pollVoteTableMode;
+ window.Store.ChatGetters = window.require('WAWebChatGetters');
+ window.Store.UploadUtils = window.require('WAWebUploadManager');
+ window.Store.WAWebStreamModel = window.require('WAWebStreamModel');
+ window.Store.FindOrCreateChat = window.require('WAWebFindChatAction');
+ window.Store.CustomerNoteUtils = window.require('WAWebNoteAction');
+ window.Store.BusinessGatingUtils = window.require('WAWebBizGatingUtils');
+ window.Store.PollsVotesSchema = window.require('WAWebPollsVotesSchema');
+ window.Store.PollsSendVote = window.require('WAWebPollsSendVoteMsgAction');
+
+ window.Store.Settings = {
+ ...window.require('WAWebUserPrefsGeneral'),
+ ...window.require('WAWebUserPrefsNotifications'),
+ setPushname: window.require('WAWebSetPushnameConnAction').setPushname
+ };
+ window.Store.NumberInfo = {
+ ...window.require('WAPhoneUtils'),
+ ...window.require('WAPhoneFindCC')
+ };
+ window.Store.ForwardUtils = {
+ ...window.require('WAWebChatForwardMessage')
+ };
+ window.Store.PinnedMsgUtils = {
+ ...window.require('WAWebPinInChatSchema'),
+ ...window.require('WAWebSendPinMessageAction')
+ };
+ window.Store.ScheduledEventMsgUtils = {
+ ...window.require('WAWebGenerateEventCallLink'),
+ ...window.require('WAWebSendEventEditMsgAction'),
+ ...window.require('WAWebSendEventResponseMsgAction')
+ };
+ window.Store.VCard = {
+ ...window.require('WAWebFrontendVcardUtils'),
+ ...window.require('WAWebVcardParsingUtils'),
+ ...window.require('WAWebVcardGetNameFromParsed')
+ };
+ window.Store.StickerTools = {
+ ...window.require('WAWebImageUtils'),
+ ...window.require('WAWebAddWebpMetadata')
+ };
+ window.Store.GroupUtils = {
+ ...window.require('WAWebGroupCreateJob'),
+ ...window.require('WAWebGroupModifyInfoJob'),
+ ...window.require('WAWebExitGroupAction'),
+ ...window.require('WAWebContactProfilePicThumbBridge'),
+ ...window.require('WAWebSetPropertyGroupAction')
+ };
+ window.Store.GroupParticipants = {
+ ...window.require('WAWebModifyParticipantsGroupAction'),
+ ...window.require('WASmaxGroupsAddParticipantsRPC')
+ };
+ window.Store.GroupInvite = {
+ ...window.require('WAWebGroupInviteJob'),
+ ...window.require('WAWebGroupQueryJob'),
+ ...window.require('WAWebMexFetchGroupInviteCodeJob')
+ };
+ window.Store.GroupInviteV4 = {
+ ...window.require('WAWebGroupInviteV4Job'),
+ ...window.require('WAWebChatSendMessages')
+ };
+ window.Store.MembershipRequestUtils = {
+ ...window.require('WAWebApiMembershipApprovalRequestStore'),
+ ...window.require('WASmaxGroupsMembershipRequestsActionRPC')
+ };
+ window.Store.ChannelUtils = {
+ ...window.require('WAWebLoadNewsletterPreviewChatAction'),
+ ...window.require('WAWebNewsletterMetadataQueryJob'),
+ ...window.require('WAWebNewsletterCreateQueryJob'),
+ ...window.require('WAWebEditNewsletterMetadataAction'),
+ ...window.require('WAWebNewsletterDeleteAction'),
+ ...window.require('WAWebNewsletterSubscribeAction'),
+ ...window.require('WAWebNewsletterUnsubscribeAction'),
+ ...window.require('WAWebNewsletterDirectorySearchAction'),
+ ...window.require('WAWebNewsletterToggleMuteStateJob'),
+ ...window.require('WAWebNewsletterGatingUtils'),
+ ...window.require('WAWebNewsletterModelUtils'),
+ ...window.require('WAWebMexAcceptNewsletterAdminInviteJob'),
+ ...window.require('WAWebMexRevokeNewsletterAdminInviteJob'),
+ ...window.require('WAWebChangeNewsletterOwnerAction'),
+ ...window.require('WAWebDemoteNewsletterAdminAction'),
+ ...window.require('WAWebNewsletterDemoteAdminJob'),
+ countryCodesIso: window.require('WAWebCountriesNativeCountryNames'),
+ currentRegion: window.require('WAWebL10N').getRegion(),
+ };
+ window.Store.SendChannelMessage = {
+ ...window.require('WAWebNewsletterUpdateMsgsRecordsJob'),
+ ...window.require('WAWebMsgDataFromModel'),
+ ...window.require('WAWebNewsletterSendMessageJob'),
+ ...window.require('WAWebNewsletterSendMsgAction'),
+ ...window.require('WAMediaCalculateFilehash')
+ };
+ window.Store.ChannelSubscribers = {
+ ...window.require('WAWebMexFetchNewsletterSubscribersJob'),
+ ...window.require('WAWebNewsletterSubscriberListAction')
+ };
+ window.Store.AddressbookContactUtils = {
+ ...window.require('WAWebSaveContactAction'),
+ ...window.require('WAWebDeleteContactAction')
+ };
+
+ if (!window.Store.Chat._find || !window.Store.Chat.findImpl) {
+ window.Store.Chat._find = e => {
+ const target = window.Store.Chat.get(e);
+ return target ? Promise.resolve(target) : Promise.resolve({
+ id: e
+ });
+ };
+ window.Store.Chat.findImpl = window.Store.Chat._find;
+ }
+
+ /**
+ * Target options object description
+ * @typedef {Object} TargetOptions
+ * @property {string|number} module The target module
+ * @property {string} function The function name to get from a module
+ */
+ /**
+ * Function to modify functions
+ * @param {TargetOptions} target Options specifying the target function to search for modifying
+ * @param {Function} callback Modified function
+ */
+ window.injectToFunction = (target, callback) => {
+ try {
+ let module = window.require(target.module);
+ if (!module) return;
+
+ const path = target.function.split('.');
+ const funcName = path.pop();
+
+ for (const key of path) {
+ if (!module[key]) return;
+ module = module[key];
+ }
+
+ const originalFunction = module[funcName];
+ if (typeof originalFunction !== 'function') return;
+
+ module[funcName] = (...args) => {
+ try {
+ return callback(originalFunction, ...args);
+ } catch {
+ return originalFunction(...args);
+ }
+ };
+
+ } catch {
+ return;
+ }
+ };
+
+ window.injectToFunction({ module: 'WAWebBackendJobsCommon', function: 'mediaTypeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage ? null : func(...args); });
+
+ window.injectToFunction({ module: 'WAWebE2EProtoUtils', function: 'typeAttributeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage || proto.groupInviteMessage ? 'text' : func(...args); });
+};

View File

@@ -1,4 +1,11 @@
require('dotenv').config()
const swaggerUi = require('swagger-ui-express');
const YAML = require('yamljs');
const path = require('path');
const swaggerPath = path.join(__dirname, 'swagger.yml');
const swaggerDoc = YAML.load(swaggerPath);
const express = require('express')
const http = require('http')
const socketIo = require('socket.io')
@@ -105,6 +112,7 @@ const io = socketIo(server, {
})
app.use(express.json({ limit: '50mb' }))
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDoc));
// Middleware
function validateApiKey(req, res, next) {

35
swagger.yml Normal file
View File

@@ -0,0 +1,35 @@
openapi: 3.0.0
info:
title: WAPP API
version: 1.0.0
components:
securitySchemes:
ApiKeyAuth:
type: apiKey
in: header
name: x-api-key
security:
- ApiKeyAuth: []
paths:
/api/send:
post:
summary: Send a WhatsApp message
security:
- ApiKeyAuth: []
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
phoneNumber:
type: string
message:
type: string
responses:
'200':
description: OK