Skip to content

Commit febaf0c

Browse files
committed
fix: Fixed error when send msg to some lids (close #2472, close #2480)
1 parent c8015bd commit febaf0c

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

src/chat/patch.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import * as webpack from '../webpack';
1818
import { ChatModel, functions } from '../whatsapp';
1919
import { wrapModuleFunction } from '../whatsapp/exportModule';
2020
import {
21+
findOrCreateLatestChat,
2122
isUnreadTypeMsg,
2223
mediaTypeFromProtobuf,
2324
typeAttributeFromProtobuf,
@@ -81,6 +82,23 @@ function applyPatch() {
8182

8283
return func(...args);
8384
});
85+
86+
/**
87+
* Fixed error on try send message to some lids
88+
*/
89+
wrapModuleFunction(findOrCreateLatestChat, async (func, ...args) => {
90+
const [chat, type] = args;
91+
92+
if (chat.isLid() && type != 'username_contactless_search') {
93+
try {
94+
return await func(...args);
95+
} catch (error) {
96+
return await func(chat, 'username_contactless_search');
97+
}
98+
}
99+
100+
return await func(...args);
101+
});
84102
}
85103

86104
function applyPatchModel() {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*!
2+
* Copyright 2021 WPPConnect Team
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { exportModule } from '../exportModule';
18+
import { Wid } from '../misc';
19+
import { ChatModel } from '../models';
20+
21+
/** @whatsapp WAWebFindChatAction
22+
*/
23+
export declare function findOrCreateLatestChat(
24+
wid: Wid,
25+
type?: 'username_contactless_search'
26+
): Promise<ChatModel>;
27+
28+
exportModule(
29+
exports,
30+
{
31+
findOrCreateLatestChat: 'findOrCreateLatestChat',
32+
},
33+
(m) => m.findOrCreateLatestChat
34+
);

src/whatsapp/functions/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export * from './fetchLinkPreview';
4848
export * from './findChat';
4949
export * from './findCommonGroups';
5050
export * from './findFirstWebLink';
51+
export * from './findOrCreateLatestChat';
5152
export * from './forwardMessagesToChats';
5253
export * from './frontendFireAndForget';
5354
export * from './genBotMsgSecretFromMsgSecret';

0 commit comments

Comments
 (0)