diff --git a/src/chat/functions/editMessage.ts b/src/chat/functions/editMessage.ts index 77ea20d9c0..474faf5b78 100644 --- a/src/chat/functions/editMessage.ts +++ b/src/chat/functions/editMessage.ts @@ -16,7 +16,7 @@ import { WPPError } from '../../util'; import { MsgKey } from '../../whatsapp'; -import { canEditMsg } from '../../whatsapp/functions'; +import { canEditCaption, canEditMsg } from '../../whatsapp/functions'; import { defaultSendMessageOptions, LinkPreviewOptions, @@ -52,7 +52,8 @@ export async function editMessage( const msg = await getMessageById(msgId); const canEdit = canEditMsg(msg); - if (!canEdit) { + const canEditCaptionMessage = canEditCaption(msg); + if (!canEdit && !canEditCaptionMessage) { throw new WPPError(`edit_message_error`, `Cannot edit this message`); } @@ -61,6 +62,7 @@ export async function editMessage( subtype: 'message_edit', protocolMessageKey: msg.id, body: newText.trim(), + caption: newText.trim(), editMsgType: msg.type, }; diff --git a/src/whatsapp/functions/canEditCaption.ts b/src/whatsapp/functions/canEditCaption.ts new file mode 100644 index 0000000000..fda2a4fb1f --- /dev/null +++ b/src/whatsapp/functions/canEditCaption.ts @@ -0,0 +1,31 @@ +/*! + * Copyright 2024 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 { MsgModel } from '../models'; + +/** + * @whatsapp WAWebMsgActionCapability >= 2.3000.0 + */ +export declare function canEditCaption(msg: MsgModel): boolean; + +exportModule( + exports, + { + canEditCaption: 'canEditCaption', + }, + (m) => m.canEditCaption +); diff --git a/src/whatsapp/functions/index.ts b/src/whatsapp/functions/index.ts index e4f15568b0..781707bf76 100644 --- a/src/whatsapp/functions/index.ts +++ b/src/whatsapp/functions/index.ts @@ -19,6 +19,7 @@ export * from './addAndSendMsgToChat'; export * from './addToLabelCollection'; export * from './blockContact'; export * from './calculateFilehashFromBlob'; +export * from './canEditCaption'; export * from './canEditMsg'; export * from './canReplyMsg'; export * from './changeOptInStatusForExternalWebBeta';