diff --git a/src/chat/functions/prepareMessageButtons.ts b/src/chat/functions/prepareMessageButtons.ts index 766f33fbb8..e2a5800ebe 100644 --- a/src/chat/functions/prepareMessageButtons.ts +++ b/src/chat/functions/prepareMessageButtons.ts @@ -20,10 +20,12 @@ import { ReplyButtonModel, TemplateButtonCollection, TemplateButtonModel, + websocket, } from '../../whatsapp'; import { DROP_ATTR } from '../../whatsapp/contants'; import { wrapModuleFunction } from '../../whatsapp/exportModule'; import { + createFanoutMsgStanza, createMsgProtobuf, encodeMaybeMediaType, mediaTypeFromProtobuf, @@ -293,21 +295,21 @@ webpack.onInjected(() => { const proto = func(...args); if (proto.templateMessage) { - proto.viewOnceMessage = { - message: { - templateMessage: proto.templateMessage, - }, - }; - delete proto.templateMessage; - } - if (proto.buttonsMessage) { - proto.viewOnceMessage = { - message: { - buttonsMessage: proto.buttonsMessage, - }, - }; - delete proto.buttonsMessage; + // proto.viewOnceMessage = { + // message: { + // templateMessage: proto.templateMessage, + // }, + // }; + // delete proto.templateMessage; } + // if (proto.buttonsMessage) { + // proto.viewOnceMessage = { + // message: { + // buttonsMessage: proto.buttonsMessage, + // }, + // }; + // delete proto.buttonsMessage; + // } return proto; }); }, 100); @@ -356,4 +358,52 @@ webpack.onInjected(() => { return func(...args); }); + + wrapModuleFunction(createFanoutMsgStanza, async (func, ...args) => { + const [, proto] = args; + + let buttonNode: websocket.WapNode | null = null; + + if (proto.buttonsMessage) { + buttonNode = websocket.smax('buttons'); + } else if (proto.listMessage) { + const listType: number = proto.listMessage.listType || 0; + + const types = ['unknown', 'single_select', 'product_list']; + + buttonNode = websocket.smax('list', { + v: '2', + type: types[listType], + }); + } + + const node = await func(...args); + + if (!buttonNode) { + return node; + } + + const content = node.content as websocket.WapNode[]; + + let bizNode = content.find((c) => c.tag === 'biz'); + + if (!bizNode) { + bizNode = websocket.smax('biz', {}, null); + content.push(bizNode); + } + + let hasButtonNode = false; + + if (Array.isArray(bizNode.content)) { + hasButtonNode = !!bizNode.content.find((c) => c.tag === buttonNode?.tag); + } else { + bizNode.content = []; + } + + if (!hasButtonNode) { + bizNode.content.push(buttonNode); + } + + return node; + }); }); diff --git a/src/chat/functions/sendListMessage.ts b/src/chat/functions/sendListMessage.ts index e380f4299b..6af9adef02 100644 --- a/src/chat/functions/sendListMessage.ts +++ b/src/chat/functions/sendListMessage.ts @@ -127,14 +127,14 @@ webpack.onInjected(() => { wrapModuleFunction(createMsgProtobuf, (func, ...args) => { const proto = func(...args); - if (proto.listMessage) { - proto.viewOnceMessage = { - message: { - listMessage: proto.listMessage, - }, - }; - delete proto.listMessage; - } + // if (proto.listMessage) { + // proto.viewOnceMessage = { + // message: { + // listMessage: proto.listMessage, + // }, + // }; + // delete proto.listMessage; + // } return proto; }); }, 100); diff --git a/src/whatsapp/functions/createFanoutMsgStanza.ts b/src/whatsapp/functions/createFanoutMsgStanza.ts new file mode 100644 index 0000000000..492e649a0a --- /dev/null +++ b/src/whatsapp/functions/createFanoutMsgStanza.ts @@ -0,0 +1,36 @@ +/*! + * Copyright 2023 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 { MsgModel, websocket, Wid } from '..'; +import { exportModule } from '../exportModule'; + +/** + * + */ +export declare function createFanoutMsgStanza( + msg: MsgModel, + proto: { [key: string]: any }, + devices: Wid[], + options: { [key: string]: any } +): Promise; + +exportModule( + exports, + { + createFanoutMsgStanza: 'createFanoutMsgStanza', + }, + (m) => m.createFanoutMsgStanza +); diff --git a/src/whatsapp/functions/index.ts b/src/whatsapp/functions/index.ts index 58af8daf86..f72588eb79 100644 --- a/src/whatsapp/functions/index.ts +++ b/src/whatsapp/functions/index.ts @@ -1,5 +1,5 @@ /*! - * Copyright 2021 WPPConnect Team + * Copyright 2023 WPPConnect Team * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ export * from './calculateFilehashFromBlob'; export * from './canEditMsg'; export * from './canReplyMsg'; export * from './collections'; +export * from './createFanoutMsgStanza'; export * from './createGroup'; export * from './createMsgProtobuf'; export * from './createOrUpdateReactions'; diff --git a/src/whatsapp/websocket/WapNode.ts b/src/whatsapp/websocket/WapNode.ts index b5bc11eb5e..19e69d55f0 100644 --- a/src/whatsapp/websocket/WapNode.ts +++ b/src/whatsapp/websocket/WapNode.ts @@ -22,7 +22,7 @@ import { exportModule } from '../exportModule'; export declare class WapNode { public tag: any; public attrs: { [key: string]: any }; - public content: Uint8Array | (any | WapNode)[]; + public content: undefined | string | Uint8Array | WapNode[]; constructor(tag: any, attrs?: { [key: string]: any }, content?: any[]);