diff --git a/src/chat/functions/prepareRawMessage.ts b/src/chat/functions/prepareRawMessage.ts index 787707feb3..905aec9083 100644 --- a/src/chat/functions/prepareRawMessage.ts +++ b/src/chat/functions/prepareRawMessage.ts @@ -19,7 +19,11 @@ import { getParticipants } from '../../group'; import { WPPError } from '../../util'; import { ChatModel, MsgKey, MsgModel, UserPrefs, Wid } from '../../whatsapp'; import { ACK } from '../../whatsapp/enums'; -import { canReplyMsg, unixTime } from '../../whatsapp/functions'; +import { + canReplyMsg, + getEphemeralFields, + unixTime, +} from '../../whatsapp/functions'; import { defaultSendMessageOptions, RawMessage, SendMessageOptions } from '..'; import { generateMessageID, getMessageById } from '.'; @@ -49,6 +53,15 @@ export async function prepareRawMessage( ...message, }; + if (message.type !== 'protocol') { + const ephemeral = getEphemeralFields(chat); + + message = { + ...ephemeral, + ...message, + }; + } + if (options.messageId) { if (typeof options.messageId === 'string') { options.messageId = MsgKey.fromString(options.messageId); diff --git a/src/whatsapp/functions/getEphemeralFields.ts b/src/whatsapp/functions/getEphemeralFields.ts new file mode 100644 index 0000000000..7e6c6c0e60 --- /dev/null +++ b/src/whatsapp/functions/getEphemeralFields.ts @@ -0,0 +1,35 @@ +/*! + * 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 { ChatModel } from '../models'; + +/** + * @whatsapp 700154 >= 2.2318.11 + */ +export declare function getEphemeralFields(chat: ChatModel): { + ephemeralDuration?: number; + ephemeralSettingTimestamp?: number; + disappearingModeInitiator?: number; +}; + +exportModule( + exports, + { + getEphemeralFields: 'getEphemeralFields', + }, + (m) => m.getEphemeralFields +); diff --git a/src/whatsapp/functions/index.ts b/src/whatsapp/functions/index.ts index 0887a345d7..cbf7005e2e 100644 --- a/src/whatsapp/functions/index.ts +++ b/src/whatsapp/functions/index.ts @@ -37,6 +37,7 @@ export * from './generateVideoThumbsAndDuration'; export * from './genMinimalLinkPreview'; export * from './getABPropConfigValue'; export * from './getCommunityParticipants'; +export * from './getEphemeralFields'; export * from './getFanOutList'; export * from './getGroupSenderKeyList'; export * from './getGroupSizeLimit'; diff --git a/src/whatsapp/models/MsgModel.ts b/src/whatsapp/models/MsgModel.ts index 353d23ab90..c2f75cbbf8 100644 --- a/src/whatsapp/models/MsgModel.ts +++ b/src/whatsapp/models/MsgModel.ts @@ -176,8 +176,8 @@ interface Props { paymentRequestMessageKey?: any; paymentExpiryTimestamp?: any; ephemeralStartTimestamp?: any; - ephemeralDuration?: any; - ephemeralSettingTimestamp?: any; + ephemeralDuration?: number; + ephemeralSettingTimestamp?: number; ephemeralOutOfSync?: any; ephemeralSharedSecret?: any; disappearingModeInitiator?: any;