diff --git a/src/chat/functions/canReply.ts b/src/chat/functions/canReply.ts new file mode 100644 index 000000000..576f4a73e --- /dev/null +++ b/src/chat/functions/canReply.ts @@ -0,0 +1,48 @@ +/*! + * Copyright 2022 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 { Stringable } from '../../types'; +import { MsgKey, MsgModel } from '../../whatsapp'; +import { canReplyMsg } from '../../whatsapp/functions'; +import { getMessageById } from './getMessageById'; + +/** + * Get if message can reply + * + * @example + * ```javascript + * WPP.chat.canReply('[message_id]'); + * ``` + * @category Message + */ +export async function canReply( + messageId: string | MsgKey | MsgModel | Stringable +): Promise { + if ( + !(messageId instanceof MsgModel) && + typeof messageId !== 'string' && + typeof messageId.toString === 'function' + ) { + messageId = messageId.toString(); + } + + const msg = + messageId instanceof MsgModel + ? messageId + : await getMessageById(messageId.toString()); + + return canReplyMsg(msg); +} diff --git a/src/chat/functions/index.ts b/src/chat/functions/index.ts index 1b0e5afa8..e9519de84 100644 --- a/src/chat/functions/index.ts +++ b/src/chat/functions/index.ts @@ -17,6 +17,7 @@ export { archive, unarchive } from './archive'; export { canMarkPlayed } from './canMarkPlayed'; export { canMute } from './canMute'; +export { canReply } from './canReply'; export { clear } from './clear'; export { delete } from './delete'; export { deleteMessage, DeleteMessageReturn } from './deleteMessage';