Skip to content

Commit

Permalink
feat: Added WPP.chat.canReply function
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Oct 30, 2022
1 parent 0931800 commit b10c648
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
48 changes: 48 additions & 0 deletions 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<boolean> {
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);
}
1 change: 1 addition & 0 deletions src/chat/functions/index.ts
Expand Up @@ -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';
Expand Down

0 comments on commit b10c648

Please sign in to comment.