Skip to content

Commit

Permalink
fix: Fixed error when send msg to some lids (close #2472, close #2480)
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Nov 14, 2024
1 parent c8015bd commit febaf0c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/chat/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import * as webpack from '../webpack';
import { ChatModel, functions } from '../whatsapp';
import { wrapModuleFunction } from '../whatsapp/exportModule';
import {
findOrCreateLatestChat,
isUnreadTypeMsg,
mediaTypeFromProtobuf,
typeAttributeFromProtobuf,
Expand Down Expand Up @@ -81,6 +82,23 @@ function applyPatch() {

return func(...args);
});

/**
* Fixed error on try send message to some lids
*/
wrapModuleFunction(findOrCreateLatestChat, async (func, ...args) => {
const [chat, type] = args;

if (chat.isLid() && type != 'username_contactless_search') {
try {
return await func(...args);
} catch (error) {
return await func(chat, 'username_contactless_search');
}
}

return await func(...args);
});
}

function applyPatchModel() {
Expand Down
34 changes: 34 additions & 0 deletions src/whatsapp/functions/findOrCreateLatestChat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*!
* Copyright 2021 WPPConnect Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { exportModule } from '../exportModule';
import { Wid } from '../misc';
import { ChatModel } from '../models';

/** @whatsapp WAWebFindChatAction
*/
export declare function findOrCreateLatestChat(
wid: Wid,
type?: 'username_contactless_search'
): Promise<ChatModel>;

exportModule(
exports,
{
findOrCreateLatestChat: 'findOrCreateLatestChat',
},
(m) => m.findOrCreateLatestChat
);
1 change: 1 addition & 0 deletions src/whatsapp/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export * from './fetchLinkPreview';
export * from './findChat';
export * from './findCommonGroups';
export * from './findFirstWebLink';
export * from './findOrCreateLatestChat';
export * from './forwardMessagesToChats';
export * from './frontendFireAndForget';
export * from './genBotMsgSecretFromMsgSecret';
Expand Down

0 comments on commit febaf0c

Please sign in to comment.